fix(mobile): Spaces tab remembers last-selected space across DM/Friends/Settings detours
Adds sticky `lastSelectedSpaceId` to useSpaceStore. Updated on every
setCurrentSpace(non-null) and on loadSpaceDetail success; NOT cleared by
setCurrentSpace(null), so the @me URL effect in AppLayout no longer wipes
the memory. Cleared only when the remembered space is actually removed
(deleteSpace / leaveSpace / removeSpace / removeInstanceSpaces / reset).
Ephemeral — URL drives initial state on reload.
MobileBottomNav.handleTab('spaces') and MobileSpacesScreen's initial
useState now resolve via `currentSpaceId ?? lastSelectedSpaceId`. The
prior Object.keys(lastChannelPerSpace)[0] fallback was wrong twice over:
first-inserted ordering locked the tab to whichever space the user
opened first in their session, and any approach reading currentSpaceId
alone breaks after a /channels/@me detour.
Also fixes a pre-existing render loop in MobileSpacesScreen's
currentSpaceId sync effect — `selectedSpaceId` removed from deps,
functional setState makes the update idempotent.
Spec: docs/systems/mobile-ui.md updates Tab Tap Behavior, MobileScreenHeader,
and LocalStorage Persistence sections.
This commit is contained in:
@@ -10,7 +10,6 @@ export function MobileBottomNav() {
|
||||
const mobileScreen = useUIStore((s) => s.mobileScreen);
|
||||
const mobileStack = useUIStore((s) => s.mobileStack);
|
||||
const setMobileTab = useUIStore((s) => s.setMobileTab);
|
||||
const lastChannelPerSpace = useUIStore((s) => s.lastChannelPerSpace);
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Badge data
|
||||
@@ -41,8 +40,17 @@ export function MobileBottomNav() {
|
||||
setMobileTab(tab);
|
||||
if (tab === 'dms') navigate('/channels/@me');
|
||||
if (tab === 'spaces') {
|
||||
const lastSpace = Object.keys(lastChannelPerSpace)[0];
|
||||
if (lastSpace) navigate(`/channels/${lastSpace}`);
|
||||
// Prefer `currentSpaceId` (the canonical "currently selected space" —
|
||||
// updated by URL routing, the space strip, SpaceInviteCard joins, etc.).
|
||||
// Fall back to `lastSelectedSpaceId`, the sticky memory that survives
|
||||
// navigating to `/channels/@me`. AppLayout's URL effect clears
|
||||
// `currentSpaceId` to null whenever the URL is `@me`; without the
|
||||
// sticky memory, returning to Spaces from a DM/Friends/Settings detour
|
||||
// would have nothing to anchor to and `MobileSpacesScreen`'s auto-select
|
||||
// would fall back to `spaces[0]`.
|
||||
const { currentSpaceId, lastSelectedSpaceId } = useSpaceStore.getState();
|
||||
const target = currentSpaceId ?? lastSelectedSpaceId;
|
||||
if (target) navigate(`/channels/${target}`);
|
||||
else navigate('/');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user