Fix workspace navigation regression on web (#772)
Centralize workspace navigation behind a small route-derived API so the workspace shell reads active selection from the current Expo Router route instead of a separately synchronized store.
Remove the stale layout-driven active-workspace write that regressed web after 02e5b564.
This commit is contained in:
@@ -1,61 +1,16 @@
|
||||
import { useCallback } from "react";
|
||||
import { router } from "expo-router";
|
||||
import {
|
||||
activateNavigationWorkspaceSelection,
|
||||
getNavigationActiveWorkspaceSelection,
|
||||
} from "@/stores/navigation-active-workspace-store";
|
||||
import { buildHostWorkspaceRoute, parseHostWorkspaceRouteFromPathname } from "@/utils/host-routes";
|
||||
import { navigateToWorkspace } from "@/stores/navigation-active-workspace-store";
|
||||
|
||||
interface NavigateToWorkspaceOptions {
|
||||
currentPathname?: string | null;
|
||||
}
|
||||
|
||||
function shouldUseRetainedWorkspaceSwitch(input: {
|
||||
hasActiveWorkspace: boolean;
|
||||
currentPathname?: string | null;
|
||||
}): boolean {
|
||||
if (!input.hasActiveWorkspace) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input.currentPathname == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return parseHostWorkspaceRouteFromPathname(input.currentPathname) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
options: NavigateToWorkspaceOptions = {},
|
||||
) {
|
||||
const activeWorkspace = getNavigationActiveWorkspaceSelection();
|
||||
if (
|
||||
shouldUseRetainedWorkspaceSwitch({
|
||||
hasActiveWorkspace: activeWorkspace !== null,
|
||||
currentPathname: options.currentPathname,
|
||||
})
|
||||
) {
|
||||
activateNavigationWorkspaceSelection(
|
||||
{ serverId, workspaceId },
|
||||
{ updateBrowserHistory: true, historyMode: "push" },
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const href = buildHostWorkspaceRoute(serverId, workspaceId);
|
||||
router.dismissTo(href);
|
||||
}
|
||||
export { navigateToWorkspace };
|
||||
|
||||
export function useWorkspaceNavigation() {
|
||||
return {
|
||||
navigateToWorkspace: useCallback(
|
||||
(serverId: string, workspaceId: string, options?: NavigateToWorkspaceOptions) => {
|
||||
(
|
||||
serverId: string,
|
||||
workspaceId: string,
|
||||
options?: Parameters<typeof navigateToWorkspace>[2],
|
||||
) => {
|
||||
navigateToWorkspace(serverId, workspaceId, options);
|
||||
},
|
||||
[],
|
||||
|
||||
Reference in New Issue
Block a user