feat(app): retain workspace screens on sidebar switch

This commit is contained in:
Mohamed Boudra
2026-04-20 12:55:58 +07:00
parent f8411d121e
commit 403fb03c97
11 changed files with 265 additions and 48 deletions
@@ -1,17 +1,27 @@
import { useCallback } from "react";
import { router } from "expo-router";
import {
activateNavigationWorkspaceSelection,
getNavigationActiveWorkspaceSelection,
} from "@/stores/navigation-active-workspace-store";
import { buildHostWorkspaceRoute } from "@/utils/host-routes";
/**
* Navigate to a workspace screen. Uses router.navigate() which,
* combined with getId on the workspace Stack.Screen, ensures:
* - Only one instance of each workspace exists in the stack
* - History is preserved (back button works)
* - No duplicate workspace screens
* Open a workspace. Once the workspace shell is mounted, switching workspaces
* is app-level state so native-stack does not rebuild every retained screen.
*/
export function navigateToWorkspace(serverId: string, workspaceId: string) {
const activeWorkspace = getNavigationActiveWorkspaceSelection();
if (activeWorkspace) {
activateNavigationWorkspaceSelection(
{ serverId, workspaceId },
{ updateBrowserHistory: true, historyMode: "push" },
);
return;
}
const href = buildHostWorkspaceRoute(serverId, workspaceId);
router.navigate(href);
router.navigate(href as any);
}
export function useWorkspaceNavigation() {