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:
@@ -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;
|
||||
|
||||
|
||||
@@ -83,6 +83,16 @@ export function MobileSpacesScreen() {
|
||||
}
|
||||
}, [selectedSpaceId, setCurrentSpace, loadSpaceDetail]);
|
||||
|
||||
// Sync local selection from store when external code changes the current
|
||||
// space (e.g. SpaceInviteCard's join handler seeding currentSpaceId before
|
||||
// routing to the Spaces tab). Without this, useState(currentSpaceId) is only
|
||||
// captured on mount and the strip stays on the previously-selected space.
|
||||
useEffect(() => {
|
||||
if (currentSpaceId && currentSpaceId !== selectedSpaceId) {
|
||||
setSelectedSpaceId(currentSpaceId);
|
||||
}
|
||||
}, [currentSpaceId, selectedSpaceId]);
|
||||
|
||||
// Auto-select first space if none selected
|
||||
useEffect(() => {
|
||||
if (!selectedSpaceId && spaces.length > 0 && spaces[0]) {
|
||||
|
||||
Reference in New Issue
Block a user