From 3c3e2456e26c4157d8f41547eae8eed0f06dec74 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 2 Jan 2025 11:16:26 +0200 Subject: [PATCH] web/roomlist: switch space in unread click handler On desktop it worked without this via event propagation, but that doesn't work on mobile (possibly because the room view opens immediately and hides the space bar?) --- web/src/ui/roomlist/FakeSpace.tsx | 6 ++++-- web/src/ui/roomlist/RoomList.tsx | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/web/src/ui/roomlist/FakeSpace.tsx b/web/src/ui/roomlist/FakeSpace.tsx index 59120e8..bb46319 100644 --- a/web/src/ui/roomlist/FakeSpace.tsx +++ b/web/src/ui/roomlist/FakeSpace.tsx @@ -27,7 +27,7 @@ export interface FakeSpaceProps { space: Space | null setSpace: (space: RoomListFilter | null) => void isActive: boolean - onClickUnread?: (evt: React.MouseEvent | null, space: Space | null) => void + onClickUnread?: (evt: React.MouseEvent, space: Space | null) => void } const getFakeSpaceMeta = (space: RoomListFilter | null): [string | undefined, JSX.Element | null] => { @@ -47,7 +47,9 @@ const getFakeSpaceMeta = (space: RoomListFilter | null): [string | undefined, JS const FakeSpace = ({ space, setSpace, isActive, onClickUnread }: FakeSpaceProps) => { const unreads = useEventAsState(space?.counts) - const onClickUnreadWrapped = onClickUnread ? () => onClickUnread(null, space) : undefined + const onClickUnreadWrapped = onClickUnread + ? (evt: React.MouseEvent) => onClickUnread(evt, space) + : undefined const [title, icon] = getFakeSpaceMeta(space) return
setSpace(space)} title={title}> diff --git a/web/src/ui/roomlist/RoomList.tsx b/web/src/ui/roomlist/RoomList.tsx index b4c0b78..39d4cb5 100644 --- a/web/src/ui/roomlist/RoomList.tsx +++ b/web/src/ui/roomlist/RoomList.tsx @@ -51,17 +51,17 @@ const RoomList = ({ activeRoomID, space }: RoomListProps) => { mainScreen.setSpace(store) }, [mainScreen, client]) const onClickSpaceUnread = useCallback(( - evt: React.MouseEvent | null, space?: SpaceStore | null, + evt: React.MouseEvent, space?: SpaceStore | null, ) => { - if (evt) { + if (!space) { const targetSpace = evt.currentTarget.closest("div.space-entry")?.getAttribute("data-target-space") if (!targetSpace) { return } space = client.store.getSpaceStore(targetSpace) - } - if (!space) { - return + if (!space) { + return + } } const counts = space.counts.current let wantedField: keyof SpaceUnreadCounts @@ -78,6 +78,8 @@ const RoomList = ({ activeRoomID, space }: RoomListProps) => { const entry = client.store.roomList.current[i] if (entry[wantedField] > 0 && space.include(entry)) { mainScreen.setActiveRoom(entry.room_id) + mainScreen.setSpace(space) + evt.stopPropagation() break } }