Deletes the vanilla shell and mounts App.tsx on #root. main.ts and the 23 views it drove are gone; App.tsx composes the ported components — sidebar, multi-view, command bar, spawn modal, help and restart overlays, daemon link, drawer — around the catalog and layout stores. The pure parts of four deleted modules moved next to the components that still use them: the spawn-form model and spawnSimilar into components/spawn, the transcript's markdown/format helpers and the diff into components/structured, the help overlay's grouping into components/dialogs. Document-level event names now live in uiEvents.ts. Deduplicated two pairs the migration left side by side: the sidebar uses dialogs/KillDialog and common/ContextMenu. It also listens for the command bar's kill/rename events, which nothing had picked up since catalog.ts went away. styles.css stays as the token and base layer, with `#app` renamed to `#root` and the pane-body rules re-keyed off the classes the React panes actually carry. Closes #253
58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
// React port of main.ts's `requestFastForward` (#67): one keystroke, every
|
|
// spawn default resolved — most recent project (or the one the operator is
|
|
// on), its last command, a fresh generated branch handle, worktree on with a
|
|
// new branch. A failed POST, or any missing default, falls back to the same
|
|
// pre-filled form `onFallback` opens, rather than a dead keystroke.
|
|
|
|
import { useCallback } from "react";
|
|
|
|
import { createSession, fetchNames, getDaemonInfo, projects as fetchProjects } from "../../api.js";
|
|
import { buildFastForwardRequest, fastForwardSeed, resolveFastForward } from "../../fastForward.js";
|
|
import { FALLBACK_PRESETS, type SpawnFormSeed } from "./model.js";
|
|
import type { Project, Session, SpawnPreset } from "../../types.js";
|
|
|
|
export interface UseFastForwardOptions {
|
|
/** The project of the session the operator is currently on, if any — its
|
|
* base repo for a worktree session, else its cwd. Same rule the plain
|
|
* spawn modal's seed uses, so `N` lands where the operator currently is. */
|
|
focusedCwd?: string;
|
|
onSpawned(session: Session): void;
|
|
onFallback(seed: SpawnFormSeed): void;
|
|
}
|
|
|
|
async function resolvePresets(): Promise<SpawnPreset[]> {
|
|
try {
|
|
const info = await getDaemonInfo();
|
|
if (info.presets?.length) return info.presets;
|
|
} catch {
|
|
// keep fallbacks
|
|
}
|
|
return FALLBACK_PRESETS;
|
|
}
|
|
|
|
/** Returns a function to call on the fast-forward keystroke. */
|
|
export function useFastForward(opts: UseFastForwardOptions): () => Promise<void> {
|
|
const { focusedCwd, onSpawned, onFallback } = opts;
|
|
|
|
return useCallback(async () => {
|
|
const [discovered, handle] = await Promise.all([
|
|
fetchProjects().catch(() => [] as Project[]),
|
|
fetchNames(1)
|
|
.then((batch) => batch.names[0])
|
|
.catch(() => undefined),
|
|
]);
|
|
const presets = await resolvePresets();
|
|
const resolved = resolveFastForward(discovered, presets, handle, focusedCwd);
|
|
const req = buildFastForwardRequest(resolved);
|
|
if (req) {
|
|
try {
|
|
onSpawned(await createSession(req));
|
|
return;
|
|
} catch {
|
|
// degrades to the pre-filled form below, never a silent dead key
|
|
}
|
|
}
|
|
onFallback(fastForwardSeed(resolved));
|
|
}, [focusedCwd, onSpawned, onFallback]);
|
|
}
|