diff --git a/src/app/features/estate/EstateNavigator.tsx b/src/app/features/estate/EstateNavigator.tsx index f65ba827..63d0c0c2 100644 --- a/src/app/features/estate/EstateNavigator.tsx +++ b/src/app/features/estate/EstateNavigator.tsx @@ -48,6 +48,10 @@ import { useEstate, useEstateRootId } from './useEstate'; /** How long a tap waits for the client store to hold the room it just joined. */ const JOIN_ARRIVAL_TIMEOUT_MS = 20000; +/** How long after a timed-out tap the store may still deliver the room and have its DM filed. */ +const LATE_ARRIVAL_WINDOW_MS = 10 * 60 * 1000; +/** Minimum tap target on phones. */ +const TOUCH_TARGET = 44; const estateRoomPath = (mx: ReturnType, room: EstateRoom): string => { const alias = getCanonicalAliasOrRoomId(mx, room.roomId); @@ -62,6 +66,7 @@ const estateRoomPath = (mx: ReturnType, room: EstateRoom function JoinRow({ room }: { room: EstateRoom }) { const mx = useMatrixClient(); const navigate = useNavigate(); + const mobile = useScreenSizeContext() === ScreenSize.Mobile; const [state, join] = useAsyncCallback( useCallback(async () => { const userId = mx.getSafeUserId(); @@ -74,7 +79,14 @@ function JoinRow({ room }: { room: EstateRoom }) { if (result.kind === 'refused') throw new Error(result.message); // joinRoom resolves before the store holds the room; opening it now shows the invite card. if (!(await awaitMyJoin(mx, room.roomId, JOIN_ARRIVAL_TIMEOUT_MS))) { - throw new Error('Joined, but the room has not arrived yet. Tap Join again in a moment.'); + // The join is accepted; when the room arrives the row becomes a joined row by itself, + // so a DM is filed then (a failed write leaves it under Elsewhere, where it can be found). + if (dmUserId) { + awaitMyJoin(mx, room.roomId, LATE_ARRIVAL_WINDOW_MS) + .then((arrived) => arrived && addRoomIdToMDirect(mx, room.roomId, dmUserId)) + .catch(() => undefined); + } + throw new Error('Joined. The room is still on its way and will open from this list.'); } if (dmUserId) await addRoomIdToMDirect(mx, room.roomId, dmUserId); navigate(estateRoomPath(mx, room)); @@ -84,14 +96,23 @@ function JoinRow({ room }: { room: EstateRoom }) { return ( - + {room.name} {state.status === AsyncStatus.Error && ( - + {(state.error as Error).message} )} @@ -102,6 +123,7 @@ function JoinRow({ room }: { room: EstateRoom }) { before={busy ? : } onClick={join} disabled={busy} + style={mobile ? { minHeight: TOUCH_TARGET, minWidth: TOUCH_TARGET } : undefined} aria-label={`Join ${room.name}`} > Join @@ -248,27 +270,33 @@ function EntryPoints() { function EstateTiers({ rootId }: { rootId: string }) { const { fetching, error, tiers } = useEstate(rootId); - const scrollRef = useRef(null); return ( - - - - {tiers.map((tier) => ( - - ))} - {fetching && ( - - - - )} - {error && ( - - {error.message} - - )} - - + <> + {tiers.map((tier) => ( + + ))} + {fetching && ( + + + + )} + {error && ( + + )} + + ); +} + +/** A short message that wraps inside the navigator; never a raw request error. */ +function EstateError({ message }: { message: string }) { + return ( + + {message} + ); } @@ -276,6 +304,7 @@ function EstateTiers({ rootId }: { rootId: string }) { export function EstateNavigator() { const openRoomFinder = useSetAtom(searchModalAtom); const { rootId, error } = useEstateRootId(); + const scrollRef = useRef(null); const mx = useMatrixClient(); const title = (rootId && mx.getRoom(rootId)?.name) || 'GameCult'; @@ -297,13 +326,20 @@ export function EstateNavigator() { - {rootId ? ( - - ) : ( - - {error ? {error.message} : } + + + + {rootId && } + {!rootId && error && ( + + )} + {!rootId && !error && ( + + + + )} - )} +