diff --git a/src/app/features/room-nav/ThreadNavItems.tsx b/src/app/features/room-nav/ThreadNavItems.tsx index da7a08830..c67751b0d 100644 --- a/src/app/features/room-nav/ThreadNavItems.tsx +++ b/src/app/features/room-nav/ThreadNavItems.tsx @@ -12,6 +12,7 @@ import { MessageEventWithoutRoomId, UnreadNotificationCounts } from 'neurone/lib import { Box, Chip, Icon, Icons, Text } from 'folds'; import { HTMLReactParserOptions } from 'html-react-parser'; import { Opts as LinkifyOpts } from 'linkifyjs'; +import { useNavigate } from 'react-router-dom'; import { Timeline } from '../../../client/room'; import { useObservableValue } from '../../hooks/useObservableValue'; import { NavButton, NavItem } from '../../components/nav'; @@ -39,7 +40,6 @@ import { useRoomHeroes } from '../../hooks/storage/useRoomHeros'; type ThreadNavItemProps = { thread: ThreadTimeline; notification?: UnreadNotificationCounts; - selected: boolean; redactedEvents?: Set; editEvents?: MessageEventWithoutRoomId[]; htmlReactParserOptions: HTMLReactParserOptions; @@ -49,7 +49,6 @@ type ThreadNavItemProps = { function ThreadNavItem({ thread, notification, - selected, redactedEvents, editEvents, htmlReactParserOptions, @@ -121,17 +120,20 @@ function ThreadNavItem({ } type ThreadNavItemsProps = { + linkPath: string; timeline: Timeline; roomSelected: boolean; threadNotifications: Map; }; export function ThreadNavItems({ + linkPath, timeline, roomSelected, threadNotifications, }: ThreadNavItemsProps) { const ct = useClient(); const useAuthentication = useMediaAuthentication(); + const navigate = useNavigate(); const [viewMore, setViewMore] = useState(false); const threads = useObservableValue(timeline.threads); @@ -175,6 +177,15 @@ export function ThreadNavItems({ const threadIds = Array.from(threadNotifications.keys()); const slicedThreadIds = viewMore ? threadIds : threadIds.slice(0, 5); + const handleOpenThread = (threadId: string) => { + if (!activeThread) { + timeline.openThread(threadId); + } + if (!roomSelected) { + navigate(linkPath); + } + }; + return ( <> @@ -187,13 +198,12 @@ export function ThreadNavItems({ timeline.openThread(threadId)} + onClick={() => handleOpenThread(threadId)} /> ); })} diff --git a/src/app/features/room-nav/index.ts b/src/app/features/room-nav/index.ts index c23b43be4..7412ba57c 100644 --- a/src/app/features/room-nav/index.ts +++ b/src/app/features/room-nav/index.ts @@ -9,3 +9,4 @@ Please see LICENSE file in root of repository for full details. export * from './RoomNavItem'; export * from './RoomNavCategoryButton'; +export * from './ThreadNavItems'; diff --git a/src/app/pages/client/direct/Direct.tsx b/src/app/pages/client/direct/Direct.tsx index 30d6397b0..38b59641d 100644 --- a/src/app/pages/client/direct/Direct.tsx +++ b/src/app/pages/client/direct/Direct.tsx @@ -40,7 +40,7 @@ import { import { getDirectCreatePath, getDirectRoomPath } from '../../pathUtils'; import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom'; import { VirtualTile } from '../../../components/virtualizer'; -import { RoomNavCategoryButton, RoomNavItem } from '../../../features/room-nav'; +import { RoomNavCategoryButton, RoomNavItem, ThreadNavItems } from '../../../features/room-nav'; import { makeNavCategoryId } from '../../../state/closedNavCategories'; import { useCategoryHandler } from '../../../hooks/useCategoryHandler'; import { useNavToActivePathMapper } from '../../../hooks/useNavToActivePathMapper'; @@ -199,6 +199,7 @@ export function Direct() { const roomToNotifications = useRoomsNotifications(directs, roomToNotificationsAtom); const unreadRooms = useRoomsUnread(directs, unreadRoomsAtom); const roomToLatestEvent = useRoomsLatestEvent(directs); + const roomToTimeline = useObservableValue(ct.roomToTimeline); const notificationPreferences = useRoomsNotificationPreferencesContext(); const navigate = useNavigate(); @@ -291,7 +292,9 @@ export function Direct() { const roomId = sortedDirects[vItem.index]; const selected = selectedRoomId === roomId; const n = roomToNotifications.get(roomId); - const notifications = n && getRoomTotalNotifications(n); + const notifications = n && getRoomTotalNotifications(n, true); + const threadNotifications = n?.threads; + const timeline = roomToTimeline.get(roomId); return ( + + {timeline && threadNotifications && threadNotifications.size > 0 && ( + + )} ); })} diff --git a/src/app/pages/client/home/Home.tsx b/src/app/pages/client/home/Home.tsx index ce2cdd070..e8be08fce 100644 --- a/src/app/pages/client/home/Home.tsx +++ b/src/app/pages/client/home/Home.tsx @@ -53,7 +53,7 @@ import { } from '../../../hooks/router/useHomeSelected'; import { useHomeRooms } from './useHomeRooms'; import { VirtualTile } from '../../../components/virtualizer'; -import { RoomNavCategoryButton, RoomNavItem } from '../../../features/room-nav'; +import { RoomNavCategoryButton, RoomNavItem, ThreadNavItems } from '../../../features/room-nav'; import { makeNavCategoryId } from '../../../state/closedNavCategories'; import { useCategoryHandler } from '../../../hooks/useCategoryHandler'; import { useNavToActivePathMapper } from '../../../hooks/useNavToActivePathMapper'; @@ -227,6 +227,7 @@ export function Home() { const roomToNotifications = useRoomsNotifications(rooms, roomToNotificationsAtom); const unreadRooms = useRoomsUnread(rooms, unreadRoomsAtom); const roomToLatestEvent = useRoomsLatestEvent(rooms); + const roomToTimeline = useObservableValue(ct.roomToTimeline); const notificationPreferences = useRoomsNotificationPreferencesContext(); const navigate = useNavigate(); @@ -377,7 +378,9 @@ export function Home() { const roomId = sortedRooms[vItem.index]; const selected = selectedRoomId === roomId; const n = roomToNotifications.get(roomId); - const notifications = n && getRoomTotalNotifications(n); + const notifications = n && getRoomTotalNotifications(n, true); + const threadNotifications = n?.threads; + const timeline = roomToTimeline.get(roomId); return ( + {timeline && threadNotifications && threadNotifications.size > 0 && ( + + )} ); })} diff --git a/src/app/pages/client/space/Space.tsx b/src/app/pages/client/space/Space.tsx index f062739f5..dd94be4f3 100644 --- a/src/app/pages/client/space/Space.tsx +++ b/src/app/pages/client/space/Space.tsx @@ -55,7 +55,7 @@ import { } from '../../../hooks/router/useSelectedSpace'; import { useSpace } from '../../../hooks/useSpace'; import { VirtualTile } from '../../../components/virtualizer'; -import { RoomNavCategoryButton, RoomNavItem } from '../../../features/room-nav'; +import { RoomNavCategoryButton, RoomNavItem, ThreadNavItems } from '../../../features/room-nav'; import { makeNavCategoryId } from '../../../state/closedNavCategories'; import { useCategoryHandler } from '../../../hooks/useCategoryHandler'; import { useNavToActivePathMapper } from '../../../hooks/useNavToActivePathMapper'; @@ -102,7 +102,6 @@ import { useAllJoinedRoomsSet } from '../../../hooks/useAllJoinedRoomsSet'; import { unreadRoomsAtom } from '../../../state/room/roomToUnread'; import { useRoomsUnread } from '../../../state/hooks/unread'; import { RoomAccessIndicator } from '../../../components/RoomAccessIndicator'; -import { ThreadNavItems } from '../../../features/room-nav/ThreadNavItems'; type SpaceMenuProps = { requestClose: () => void; @@ -528,7 +527,7 @@ export function Space() { } const n = roomToNotifications.get(roomId); - const notifications = n && getRoomTotalNotifications(n); + const notifications = n && getRoomTotalNotifications(n, true); const threadNotifications = n?.threads; const timeline = roomToTimeline.get(roomId); @@ -548,6 +547,7 @@ export function Space() { /> {timeline && threadNotifications && threadNotifications.size > 0 && ( useMemo(() => getRoomsTotalNotifications(roomsToNotifications), [roomsToNotifications]); -export const getRoomTotalNotifications = (notifications?: Notifications): TotalNotifications => { +export const getRoomTotalNotifications = ( + notifications?: Notifications, + excludeThreads?: boolean +): TotalNotifications => { const total: TotalNotifications = { count: 0, highlight: false, }; setTotal(total, notifications ?? {}); + + if (excludeThreads) return total; + notifications?.threads.forEach((tn) => setTotal(total, tn)); return total;