Make New Workspace an app-wide screen (#1746)
* 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
This commit is contained in:
@@ -2,27 +2,29 @@ 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 { buildHostNewWorkspaceRoute } from "@/utils/host-routes";
|
||||
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 (!serverId) {
|
||||
if (hosts.length === 0) {
|
||||
return false;
|
||||
}
|
||||
router.navigate(buildHostNewWorkspaceRoute(serverId) as never);
|
||||
router.navigate(buildNewWorkspaceRoute(serverId ? { serverId } : undefined) as never);
|
||||
return true;
|
||||
}, [serverId]);
|
||||
}, [hosts.length, serverId]);
|
||||
|
||||
useKeyboardActionHandler({
|
||||
handlerId: "workspace-new-global",
|
||||
actions: WORKSPACE_NEW_ACTIONS,
|
||||
enabled: serverId !== null,
|
||||
enabled: hosts.length > 0,
|
||||
priority: 0,
|
||||
handle,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user