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:
@@ -19,7 +19,6 @@ function makeCtx(overrides: Partial<ShortcutRoutingContext> = {}): ShortcutRouti
|
||||
isMobile: false,
|
||||
sidebarShortcutTargets: SIDEBAR_TARGETS,
|
||||
navigationActiveWorkspace: null,
|
||||
lastNavigationWorkspaceRoute: null,
|
||||
commandCenterOpen: false,
|
||||
shortcutsDialogOpen: false,
|
||||
...overrides,
|
||||
@@ -253,39 +252,25 @@ describe("routeKeyboardShortcut — settings.toggle", () => {
|
||||
).toEqual<ShortcutAction>({ kind: "router-push", route: "/settings" });
|
||||
});
|
||||
|
||||
it("replaces to the retained workspace route when leaving settings on desktop", () => {
|
||||
it("navigates to the last workspace when leaving settings on desktop", () => {
|
||||
expect(
|
||||
routeKeyboardShortcut(
|
||||
{ action: "settings.toggle", payload: null },
|
||||
makeCtx({
|
||||
pathname: "/settings/general",
|
||||
isMobile: false,
|
||||
lastNavigationWorkspaceRoute: { serverId: "srv", workspaceId: "ws-2" },
|
||||
}),
|
||||
),
|
||||
).toEqual<ShortcutAction>({
|
||||
kind: "router-replace",
|
||||
route: "/h/srv/workspace/ws-2",
|
||||
});
|
||||
).toEqual<ShortcutAction>({ kind: "navigate-last-workspace" });
|
||||
});
|
||||
|
||||
it("falls back to router.back() when no retained workspace exists", () => {
|
||||
expect(
|
||||
routeKeyboardShortcut(
|
||||
{ action: "settings.toggle", payload: null },
|
||||
makeCtx({ pathname: "/settings/general", lastNavigationWorkspaceRoute: null }),
|
||||
),
|
||||
).toEqual<ShortcutAction>({ kind: "router-back" });
|
||||
});
|
||||
|
||||
it("falls back to router.back() on mobile even if a retained workspace exists", () => {
|
||||
it("falls back to router.back() on mobile", () => {
|
||||
expect(
|
||||
routeKeyboardShortcut(
|
||||
{ action: "settings.toggle", payload: null },
|
||||
makeCtx({
|
||||
pathname: "/settings/general",
|
||||
isMobile: true,
|
||||
lastNavigationWorkspaceRoute: { serverId: "srv", workspaceId: "ws-2" },
|
||||
}),
|
||||
),
|
||||
).toEqual<ShortcutAction>({ kind: "router-back" });
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import type { KeyboardShortcutPayload, MessageInputKeyboardActionKind } from "@/keyboard/actions";
|
||||
import type { KeyboardActionDefinition } from "@/keyboard/keyboard-action-dispatcher";
|
||||
import {
|
||||
buildHostWorkspaceRoute,
|
||||
buildSettingsRoute,
|
||||
parseHostWorkspaceRouteFromPathname,
|
||||
} from "@/utils/host-routes";
|
||||
import { buildSettingsRoute, parseHostWorkspaceRouteFromPathname } from "@/utils/host-routes";
|
||||
import {
|
||||
getRelativeSidebarShortcutTarget,
|
||||
type SidebarShortcutWorkspaceTarget,
|
||||
@@ -15,7 +11,6 @@ export interface ShortcutRoutingContext {
|
||||
isMobile: boolean;
|
||||
sidebarShortcutTargets: ReadonlyArray<SidebarShortcutWorkspaceTarget>;
|
||||
navigationActiveWorkspace: SidebarShortcutWorkspaceTarget | null;
|
||||
lastNavigationWorkspaceRoute: SidebarShortcutWorkspaceTarget | null;
|
||||
commandCenterOpen: boolean;
|
||||
shortcutsDialogOpen: boolean;
|
||||
}
|
||||
@@ -35,6 +30,7 @@ export type ShortcutAction =
|
||||
| { kind: "none" }
|
||||
| { kind: "dispatch"; action: KeyboardActionDefinition }
|
||||
| { kind: "navigate-workspace"; serverId: string; workspaceId: string }
|
||||
| { kind: "navigate-last-workspace" }
|
||||
| { kind: "router-replace"; route: string }
|
||||
| { kind: "router-back" }
|
||||
| { kind: "router-push"; route: string }
|
||||
@@ -166,14 +162,8 @@ function routeSettingsToggle(ctx: ShortcutRoutingContext): ShortcutAction {
|
||||
if (!ctx.pathname.startsWith("/settings")) {
|
||||
return { kind: "router-push", route: buildSettingsRoute() };
|
||||
}
|
||||
if (!ctx.isMobile && ctx.lastNavigationWorkspaceRoute) {
|
||||
return {
|
||||
kind: "router-replace",
|
||||
route: buildHostWorkspaceRoute(
|
||||
ctx.lastNavigationWorkspaceRoute.serverId,
|
||||
ctx.lastNavigationWorkspaceRoute.workspaceId,
|
||||
),
|
||||
};
|
||||
if (!ctx.isMobile) {
|
||||
return { kind: "navigate-last-workspace" };
|
||||
}
|
||||
return { kind: "router-back" };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user