* fix(app): keep New Workspace on the active project New Workspace preselection was falling back to stale remembered host state when multiple hosts existed. Pass durable active-project context from workspace entry points and centralize initial host selection so stale offline hosts cannot steal the form while startup restore remains last-workspace only. * fix(app): address New Workspace review feedback * fix(app): stabilize New Workspace host selection * fix(app): preserve New Workspace host fallback * test(app): loosen stale-host project assertion * fix(app): prefer reachable new workspace hosts * fix(app): avoid stale offline workspace preselect * fix(app): prefer online project hosts
40 lines
1.4 KiB
TypeScript
40 lines
1.4 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 { useActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
|
import { useWorkspace } from "@/stores/session-store-hooks";
|
|
import { buildNewWorkspaceRoute } from "@/utils/host-routes";
|
|
|
|
const WORKTREE_NEW_ACTIONS: readonly KeyboardActionId[] = ["worktree.new"];
|
|
|
|
export function useActiveWorktreeNewAction() {
|
|
const selection = useActiveWorkspaceSelection();
|
|
const serverId = selection?.serverId ?? null;
|
|
const workspaceId = selection?.workspaceId ?? null;
|
|
const activeWorkspace = useWorkspace(serverId, workspaceId);
|
|
const activeGitWorkspace = activeWorkspace?.projectKind === "git" ? activeWorkspace : null;
|
|
|
|
const handle = useCallback(() => {
|
|
if (!serverId || !activeGitWorkspace) {
|
|
return false;
|
|
}
|
|
router.navigate(
|
|
buildNewWorkspaceRoute({
|
|
serverId,
|
|
sourceDirectory: activeGitWorkspace.projectRootPath,
|
|
projectId: activeGitWorkspace.projectId,
|
|
}) as never,
|
|
);
|
|
return true;
|
|
}, [activeGitWorkspace, serverId]);
|
|
|
|
useKeyboardActionHandler({
|
|
handlerId: "worktree-new-active",
|
|
actions: WORKTREE_NEW_ACTIONS,
|
|
enabled: serverId !== null && activeGitWorkspace !== null,
|
|
priority: 0,
|
|
handle,
|
|
});
|
|
}
|