feat(app): retain workspace screens on sidebar switch
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user