* fix(app): make new workspace global New Workspace now opens as an app-wide screen. Host and project context can still preselect the form through query params, but the route itself no longer lives under a host. * fix(app): simplify new workspace selection
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { useCallback } from "react";
|
|
import { router } from "expo-router";
|
|
import { useKeyboardActionHandler } from "@/hooks/use-keyboard-action-handler";
|
|
import type { KeyboardActionId } from "@/keyboard/keyboard-action-dispatcher";
|
|
import { useHosts } from "@/runtime/host-runtime";
|
|
import { useActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
|
import { buildNewWorkspaceRoute } from "@/utils/host-routes";
|
|
|
|
const WORKSPACE_NEW_ACTIONS: readonly KeyboardActionId[] = ["workspace.new"];
|
|
|
|
export function useGlobalNewWorkspaceAction() {
|
|
const selection = useActiveWorkspaceSelection();
|
|
const serverId = selection?.serverId ?? null;
|
|
const hosts = useHosts();
|
|
|
|
const handle = useCallback(() => {
|
|
if (hosts.length === 0) {
|
|
return false;
|
|
}
|
|
router.navigate(buildNewWorkspaceRoute(serverId ? { serverId } : undefined) as never);
|
|
return true;
|
|
}, [hosts.length, serverId]);
|
|
|
|
useKeyboardActionHandler({
|
|
handlerId: "workspace-new-global",
|
|
actions: WORKSPACE_NEW_ACTIONS,
|
|
enabled: hosts.length > 0,
|
|
priority: 0,
|
|
handle,
|
|
});
|
|
}
|