Add keyboard shortcut to create a new workspace

Cmd+N (Ctrl+N off mac) navigates to the new-workspace route through a
global handler keyed on the active host. The sidebar header row surfaces
the shortcut hint on hover, replacing the redundant "+" button that
duplicated the action in the Workspaces section header.
This commit is contained in:
Mohamed Boudra
2026-06-16 16:13:03 +07:00
parent e77c8e2bf3
commit 88b48c9d09
17 changed files with 106 additions and 39 deletions
@@ -0,0 +1,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 { useActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
import { buildHostNewWorkspaceRoute } from "@/utils/host-routes";
const WORKSPACE_NEW_ACTIONS: readonly KeyboardActionId[] = ["workspace.new"];
export function useGlobalNewWorkspaceAction() {
const selection = useActiveWorkspaceSelection();
const serverId = selection?.serverId ?? null;
const handle = useCallback(() => {
if (!serverId) {
return false;
}
router.navigate(buildHostNewWorkspaceRoute(serverId) as never);
return true;
}, [serverId]);
useKeyboardActionHandler({
handlerId: "workspace-new-global",
actions: WORKSPACE_NEW_ACTIONS,
enabled: serverId !== null,
priority: 0,
handle,
});
}