From caf67b98892dc923ebb57580056253a21bd9a8db Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:41:04 +0530 Subject: [PATCH] fix unread room menu ref --- .../client/sidebar/NotificationBadge.tsx | 164 +++++++++--------- 1 file changed, 83 insertions(+), 81 deletions(-) diff --git a/src/app/pages/client/sidebar/NotificationBadge.tsx b/src/app/pages/client/sidebar/NotificationBadge.tsx index b250087d..4ae867df 100644 --- a/src/app/pages/client/sidebar/NotificationBadge.tsx +++ b/src/app/pages/client/sidebar/NotificationBadge.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { forwardRef, useState } from 'react'; import { useAtomValue } from 'jotai'; import { PopOut, Menu, Box, toRem, config, Text, Header, Scroll, Avatar } from 'folds'; import FocusTrap from 'focus-trap-react'; @@ -17,92 +17,94 @@ import { getHomeRoomPath } from '../../pathUtils'; import { getCanonicalAliasOrRoomId } from '../../../utils/matrix'; import { useSelectedRoom } from '../../../hooks/useSelectedRoom'; -function UnreadMenu({ rooms, requestClose }: { rooms: string[]; requestClose: () => void }) { - const mx = useMatrixClient(); - const mDirects = useAtomValue(mDirectAtom); - const roomToUnread = useAtomValue(roomToUnreadAtom); - const selectedRoomId = useSelectedRoom(); +const UnreadMenu = forwardRef void }>( + ({ rooms, requestClose }, ref) => { + const mx = useMatrixClient(); + const mDirects = useAtomValue(mDirectAtom); + const roomToUnread = useAtomValue(roomToUnreadAtom); + const selectedRoomId = useSelectedRoom(); - return ( - - -
- Unread Rooms -
- - - {rooms - .sort(factoryRoomIdByActivity(mx)) - .sort(factoryRoomIdByUnreadCount((rId) => roomToUnread.get(rId)?.total ?? 0)) - .map((roomId) => { - const room = mx.getRoom(roomId); - if (!room) return null; - const avatarSrc = getRoomAvatarUrl(mx, room, 32); + return ( + + +
+ Unread Rooms +
+ + + {rooms + .sort(factoryRoomIdByActivity(mx)) + .sort(factoryRoomIdByUnreadCount((rId) => roomToUnread.get(rId)?.total ?? 0)) + .map((roomId) => { + const room = mx.getRoom(roomId); + if (!room) return null; + const avatarSrc = getRoomAvatarUrl(mx, room, 32); - const roomUnread = roomToUnread.get(roomId); - if (!roomUnread) return null; + const roomUnread = roomToUnread.get(roomId); + if (!roomUnread) return null; - return ( - - - - - - {mDirects.has(roomId) ? ( - ( - - {nameInitials(room.name)} - - )} - /> - ) : ( - + + + + + {mDirects.has(roomId) ? ( + ( + + {nameInitials(room.name)} + + )} + /> + ) : ( + + )} + + + + {room.name} + + + {roomUnread && ( + + 0} + count={roomUnread.total} + /> + )} - - - - {room.name} - - {roomUnread && ( - - 0} - count={roomUnread.total} - /> - - )} - - - - - ); - })} - - -
-
- ); -} + + + + ); + })} +
+
+
+
+ ); + } +); export function NotificationBadge({ unread }: { unread: Unread }) { const unreadRooms = [...(unread.from ?? [])];