fix(mobile): SpaceInviteCard Join lands on Spaces tab; skip auto-channel-redirect

AppLayout's auto-channel-redirect (turning /channels/<spaceId> into
/channels/<spaceId>/<firstChannelId>) is desktop-correct but on mobile
catapulted users past the channel sidebar straight into a chat — Join
from a SpaceInviteCard or Spaces-tab tap both inherited this. Guard
the effect with isMobile so /channels/<spaceId> settles at the channel
sidebar overview on mobile.

SpaceInviteCard's join handler now switches to the Spaces tab and seeds
spaceStore.currentSpaceId on mobile before navigating — clears the chat
stack the invite was tapped from and lands the user at the joined space's
channel sidebar instead of stuck behind the originating DM.

MobileSpacesScreen syncs its local selectedSpaceId from currentSpaceId
when external code (the Join handler) seeds the store — covers any future
programmatic space switch too.
This commit is contained in:
Jannis Braun
2026-05-05 23:23:46 +02:00
parent e2d938e6c0
commit fc9a07523f
3 changed files with 35 additions and 3 deletions
@@ -295,8 +295,13 @@ export function AppLayout() {
}
}, [channelId, spaceId, setCurrentChannel, loadMessages]);
// Auto-select last visited (or first) channel when opening a server without a channelId
// Auto-select last visited (or first) channel when opening a server without a channelId.
// Desktop-only: on mobile, `/channels/<spaceId>` should leave the user at the channel
// sidebar overview (MobileSpacesScreen), not auto-jump into a text channel — otherwise
// joining a space via SpaceInviteCard or tapping the Spaces bottom-nav tab catapults the
// user past the sidebar straight into a chat screen, with no clean back path.
useEffect(() => {
if (useUIStore.getState().isMobile) return;
if (!spaceId || spaceId === '@me' || channelId) return;
if (channels.length === 0) return;