mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 18:43:41 -05:00
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?)
This commit is contained in:
parent
021236592f
commit
3c3e2456e2
2 changed files with 11 additions and 7 deletions
|
@ -27,7 +27,7 @@ export interface FakeSpaceProps {
|
|||
space: Space | null
|
||||
setSpace: (space: RoomListFilter | null) => void
|
||||
isActive: boolean
|
||||
onClickUnread?: (evt: React.MouseEvent<HTMLDivElement> | null, space: Space | null) => void
|
||||
onClickUnread?: (evt: React.MouseEvent<HTMLDivElement>, 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<HTMLDivElement>) => onClickUnread(evt, space)
|
||||
: undefined
|
||||
const [title, icon] = getFakeSpaceMeta(space)
|
||||
return <div className={`space-entry ${isActive ? "active" : ""}`} onClick={() => setSpace(space)} title={title}>
|
||||
<UnreadCount counts={unreads} space={true} onClick={onClickUnreadWrapped} />
|
||||
|
|
|
@ -51,17 +51,17 @@ const RoomList = ({ activeRoomID, space }: RoomListProps) => {
|
|||
mainScreen.setSpace(store)
|
||||
}, [mainScreen, client])
|
||||
const onClickSpaceUnread = useCallback((
|
||||
evt: React.MouseEvent<HTMLDivElement> | null, space?: SpaceStore | null,
|
||||
evt: React.MouseEvent<HTMLDivElement>, 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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue