diff --git a/raven-app/src/components/feature/channels/ChannelList.tsx b/raven-app/src/components/feature/channels/ChannelList.tsx index 1d339c8fd..9ad79059e 100644 --- a/raven-app/src/components/feature/channels/ChannelList.tsx +++ b/raven-app/src/components/feature/channels/ChannelList.tsx @@ -4,7 +4,7 @@ import { CreateChannelButton } from "./CreateChannelModal" import { useContext, useMemo, useState } from "react" import { ChannelListContext, ChannelListContextType, ChannelListItem, UnreadCountData } from "../../../utils/channel/ChannelListProvider" import { ChannelIcon } from "@/utils/layout/channelIcon" -import { Flex, Text } from "@radix-ui/themes" +import { Box, Flex, Text } from "@radix-ui/themes" import { useLocation, useParams } from "react-router-dom" export const ChannelList = ({ unread_count }: { unread_count?: UnreadCountData }) => { @@ -22,11 +22,14 @@ export const ChannelList = ({ unread_count }: { unread_count?: UnreadCountData } - + Channels - {!showData && unread_count && unread_count.total_unread_count_in_channels > 0 && {unread_count.total_unread_count_in_channels}} + {!showData && unread_count && unread_count.total_unread_count_in_channels > 0 && + + {unread_count.total_unread_count_in_channels} + } @@ -45,6 +48,12 @@ const ChannelItem = ({ channel, unreadCount }: { channel: ChannelListItem, unrea const unreadCountForChannel = useMemo(() => unreadCount.find((unread) => unread.name == channel.name)?.unread_count, [channel.name, unreadCount]) + return + +} + +export const ChannelItemElement = ({ channel, unreadCount }: { channel: ChannelListItem, unreadCount?: number }) => { + const { channelID } = useParams() const { state } = useLocation() @@ -53,16 +62,15 @@ const ChannelItem = ({ channel, unreadCount }: { channel: ChannelListItem, unrea * Show the unread count if it exists and either the channel is not the current channel, * or if it is the current channel, the user is viewing a base message */ - const showUnread = unreadCountForChannel && (channelID !== channel.name || state?.baseMessage) + const showUnread = unreadCount && (channelID !== channel.name || state?.baseMessage) return ( {channel.channel_name} - {showUnread ? {unreadCountForChannel} : null} + {showUnread ? {unreadCount} : null} ) - } \ No newline at end of file diff --git a/raven-app/src/components/feature/channels/CreateChannelModal.tsx b/raven-app/src/components/feature/channels/CreateChannelModal.tsx index 29b0385b5..69e100b66 100644 --- a/raven-app/src/components/feature/channels/CreateChannelModal.tsx +++ b/raven-app/src/components/feature/channels/CreateChannelModal.tsx @@ -101,7 +101,7 @@ export const CreateChannelButton = ({ updateChannelList }: { updateChannelList: return - + diff --git a/raven-app/src/components/feature/direct-messages/DirectMessageList.tsx b/raven-app/src/components/feature/direct-messages/DirectMessageList.tsx index 236651079..ce1f96021 100644 --- a/raven-app/src/components/feature/direct-messages/DirectMessageList.tsx +++ b/raven-app/src/components/feature/direct-messages/DirectMessageList.tsx @@ -7,7 +7,7 @@ import { UserContext } from "../../../utils/auth/UserProvider" import { useGetUser } from "@/hooks/useGetUser" import { useIsUserActive } from "@/hooks/useIsUserActive" import { ChannelListContext, ChannelListContextType, DMChannelListItem, ExtraUsersData, UnreadCountData } from "../../../utils/channel/ChannelListProvider" -import { Flex, Text } from "@radix-ui/themes" +import { Box, Flex, Text } from "@radix-ui/themes" import { UserAvatar } from "@/components/common/UserAvatar" import { useToast } from "@/hooks/useToast" @@ -27,7 +27,11 @@ export const DirectMessageList = ({ unread_count }: { unread_count?: UnreadCount Direct Messages - {!showData && unread_count && unread_count?.total_unread_count_in_dms > 0 && {unread_count.total_unread_count_in_dms}} + {!showData && unread_count && unread_count?.total_unread_count_in_dms > 0 && + + {unread_count.total_unread_count_in_dms} + + } @@ -56,15 +60,22 @@ const DirectMessageItemList = ({ unread_count }: { unread_count?: UnreadCountDat const DirectMessageItem = ({ channel, unreadCount }: { channel: DMChannelListItem, unreadCount: UnreadCountData['channels'] }) => { - const { currentUser } = useContext(UserContext) + const unreadCountForChannel = useMemo(() => unreadCount.find((unread) => unread.name == channel.name)?.unread_count, [channel.name, unreadCount]) + return + +} + +export const DirectMessageItemElement = ({ channel, unreadCount }: { channel: DMChannelListItem, unreadCount?: number }) => { + + const { currentUser } = useContext(UserContext) const userData = useGetUser(channel.peer_user_id) const isActive = useIsUserActive(channel.peer_user_id) const { channelID } = useParams() - const showUnread = unreadCountForChannel && channelID !== channel.name + const showUnread = unreadCount && channelID !== channel.name return @@ -74,7 +85,7 @@ const DirectMessageItem = ({ channel, unreadCount }: { channel: DMChannelListIte {channel.peer_user_id !== currentUser ? userData?.full_name ?? channel.peer_user_id : `${userData?.full_name} (You)`} - {showUnread ? {unreadCountForChannel} : null} + {showUnread ? {unreadCount} : null} } diff --git a/raven-app/src/components/layout/Sidebar/SidebarBody.tsx b/raven-app/src/components/layout/Sidebar/SidebarBody.tsx index ad8296bd3..6830a5376 100644 --- a/raven-app/src/components/layout/Sidebar/SidebarBody.tsx +++ b/raven-app/src/components/layout/Sidebar/SidebarBody.tsx @@ -1,9 +1,10 @@ import { ChannelList } from '../../feature/channels/ChannelList' import { DirectMessageList } from '../../feature/direct-messages/DirectMessageList' import { SidebarItem } from './SidebarComp' -import { AccessibleIcon, Box, Flex, ScrollArea, Text } from '@radix-ui/themes' +import { AccessibleIcon, Box, Flex, ScrollArea, Separator, Text } from '@radix-ui/themes' import { BiBookmark } from 'react-icons/bi' import useUnreadMessageCount from '@/hooks/useUnreadMessageCount' +import UnreadChannels from './UnreadChannels' export const SidebarBody = () => { @@ -12,7 +13,7 @@ export const SidebarBody = () => { return ( - + @@ -22,6 +23,11 @@ export const SidebarBody = () => { + + + + + diff --git a/raven-app/src/components/layout/Sidebar/SidebarComp.tsx b/raven-app/src/components/layout/Sidebar/SidebarComp.tsx index 20b84523b..d5b37c1cf 100644 --- a/raven-app/src/components/layout/Sidebar/SidebarComp.tsx +++ b/raven-app/src/components/layout/Sidebar/SidebarComp.tsx @@ -80,7 +80,7 @@ export const SidebarItem = ({ to, children, end, active = false, activeStyles, c {children} diff --git a/raven-app/src/components/layout/Sidebar/UnreadChannels.tsx b/raven-app/src/components/layout/Sidebar/UnreadChannels.tsx new file mode 100644 index 000000000..6c70d2fab --- /dev/null +++ b/raven-app/src/components/layout/Sidebar/UnreadChannels.tsx @@ -0,0 +1,83 @@ +import { ChannelListContext, ChannelListContextType, UnreadCountData } from '@/utils/channel/ChannelListProvider' +import { useContext, useMemo } from 'react' +import { SidebarGroup, SidebarGroupItem, SidebarGroupLabel, SidebarGroupList } from './SidebarComp' +import { Flex } from '@radix-ui/themes' +import { MdOutlineMarkChatUnread } from 'react-icons/md' +import { ChannelItemElement } from '@/components/feature/channels/ChannelList' +import { DirectMessageItemElement } from '@/components/feature/direct-messages/DirectMessageList' + +type Props = {} + +const UnreadChannels = ({ unread_count }: { unread_count?: UnreadCountData }) => { + + const { channels, dm_channels } = useContext(ChannelListContext) as ChannelListContextType + + const { unread_channels, unread_dm_channels } = useMemo(() => { + // Only show channels with unread messages + const activeChannels = channels.filter(channel => channel.is_archived === 0) + + const channelsWithUnread = [] + const dmsWithUnread = [] + for (const channel of activeChannels) { + const count = unread_count?.channels.find((unread) => unread.name === channel.name)?.unread_count + if (count) { + channelsWithUnread.push({ + ...channel, + unread_count: count + }) + } + } + + for (const channel of dm_channels) { + const count = unread_count?.channels.find((unread) => unread.name === channel.name)?.unread_count + if (count) { + dmsWithUnread.push({ + ...channel, + unread_count: count + }) + } + } + + return { + unread_channels: channelsWithUnread, + unread_dm_channels: dmsWithUnread + } + + }, [channels, dm_channels, unread_count]) + + if (unread_channels.length === 0 && unread_dm_channels.length === 0) { + return null + } + + + return ( + + + + + Unread + + + + + {unread_channels.map((channel) => )} + + {unread_dm_channels.map((channel) => )} + + {/* {filteredChannels.map((channel) => )} */} + + + + ) +} + +export default UnreadChannels \ No newline at end of file