8000 feat(longform): non-destructive stage transitions with diff-aware propagation + confirm dialogs by johannboehme · Pull Request #46 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Settings } from "./pages/Settings";
import { BrowserTooOld } from "./pages/BrowserTooOld";
import Triage from "./pages/Triage";
import Upload from "./pages/Upload";
import ConfirmDialogHost from "./components/ConfirmDialogHost";

export default function App() {
const location = useLocation();
Expand Down Expand Up @@ -88,6 +89,7 @@ export default function App() {
</Routes>
<Footer overlay={isFullBleed} />
<HelpOverlay />
<ConfirmDialogHost />
</div>
);
}
Expand Down
178 changes: 178 additions & 0 deletions frontend/src/components/ConfirmDialogHost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/**
* Host component for `confirmDestructive` / `chooseSplitReplacement` /
* `confirmMergeReplaceAll`. Mount once at the app root — it renders one
* modal at a time from the queued request stack.
*
* Styling follows the rest of the UI: paper-hi card with a hot/danger
* destructive button. Esc cancels, Enter confirms (destructive flavour
* only — split/merge intentionally require an explicit click to avoid
* accidental data-shape choices).
*/
import { useEffect } from "react";
import {
useConfirmStore,
type ConfirmRequest,
type DestructiveRequest,
type SplitRequest,
type MergeRequest,
} from "../lib/confirm";

export default function ConfirmDialogHost() {
const r 8000 equests = useConfirmStore((s) => s.requests);
const resolve = useConfirmStore((s) => s.resolve);
const top: ConfirmRequest | undefined = requests[0];

useEffect(() => {
if (!top) return;
function onKey(e: KeyboardEvent) {
if (!top) return;
if (e.key === "Escape") {
e.preventDefault();
if (top.kind === "split") resolve(top.id, null);
else resolve(top.id, false);
} else if (e.key === "Enter" && top.kind === "destructive") {
e.preventDefault();
resolve(top.id, true);
}
}
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [top, resolve]);

if (!top) return null;

return (
<div
role="dialog"
aria-modal="true"
aria-labelledby="confirm-dialog-title"
className="fixed inset-0 z-[100] flex items-center justify-center bg-ink/40 backdrop-blur-sm px-4"
=> {
// Backdrop click cancels.
if (e.target === e.currentTarget) {
if (top.kind === "split") resolve(top.id, null);
else resolve(top.id, false);
}
}}
>
<div className="max-w-md w-full bg-paper-hi border border-rule rounded-lg shadow-panel p-6 flex flex-col gap-4">
<h2
id="confirm-dialog-title"
className="font-display text-lg text-ink"
>
{top.title}
</h2>
<div className="text-sm text-ink-2 leading-relaxed">{top.body}</div>
{top.kind === "destructive" && (
<DestructiveButtons req={top} resolve={resolve} />
)}
{top.kind === "split" && (
<SplitButtons req={top} resolve={resolve} />
)}
{top.kind === "merge" && (
<MergeButtons req={top} resolve={resolve} />
)}
</div>
</div>
);
}

function DestructiveButtons({
req,
resolve,
}: {
req: DestructiveRequest;
resolve: (id: number, value: boolean) => void;
}) {
return (
<div className="flex gap-2 justify-end">
<button
type="button"
=> resolve(req.id, false)}
className="h-9 px-3 rounded-md border border-rule bg-paper-deep text-ink-2 font-display tracking-label uppercase text-xs hover:bg-paper hover:text-ink"
autoFocus
>
{req.cancelLabel}
</button>
<button
type="button"
=> resolve(req.id, true)}
className="h-9 px-3 rounded-md bg-danger text-paper-hi font-display tracking-label uppercase text-xs hover:opacity-90"
>
{req.destructiveLabel}
</button>
</div>
);
}

function SplitButtons({
req,
resolve,
}: {
req: SplitRequest;
resolve: (id: number, value: "a" | "b" | "both" | null) => void;
}) {
return (
<div className="flex flex-col gap-2">
<button
type="button"
=> resolve(req.id, "both")}
className="h-10 px-3 rounded-md bg-hot text-paper font-display tracking-label uppercase text-xs hover:opacity-90"
autoFocus
>
Replace with both (A then B)
</button>
<div className="flex gap-2">
<button
type="button"
=> resolve(req.id, "a")}
className="flex-1 h-9 px-3 rounded-md border border-rule bg-paper-deep text-ink font-display tracking-label uppercase text-xs hover:bg-paper"
>
Replace with A only
</button>
<button
type="button"
=> resolve(req.id, "b")}
className="flex-1 h-9 px-3 rounded-md border border-rule bg-paper-deep text-ink font-display tracking-label uppercase text-xs hover:bg-paper"
>
Replace with B only
</button>
</div>
<button
type="button"
=> resolve(req.id, null)}
className="h-9 px-3 rounded-md text-ink-2 font-display tracking-label uppercase text-xs hover:text-ink"
>
Cancel split
</button>
</div>
);
}

function MergeButtons({
req,
resolve,
}: {
req: MergeRequest;
resolve: (id: number, value: boolean) => void;
}) {
return (
<div className="flex gap-2 justify-end">
<button
type="button"
=> resolve(req.id, false)}
className="h-9 px-3 rounded-md border border-rule bg-paper-deep text-ink-2 font-display tracking-label uppercase text-xs hover:bg-paper hover:text-ink"
autoFocus
>
Cancel merge
</button>
<button
type="button"
=> resolve(req.id, true)}
className="h-9 px-3 rounded-md bg-hot text-paper font-display tracking-label uppercase text-xs hover:opacity-90"
>
Replace all with merged
</button>
</div>
);
}
16 changes: 9 additions & 7 deletions frontend/src/components/arrange/ArrangeTransport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ import {
effectiveBarsForChunk,
useArrangeStore,
} from "../../local/arrange/arrange-store";
import {
duplicateItemWithEdits,
removeItemGuarded,
} from "../../local/arrange/arrange-guarded-actions";

export function ArrangeTransport() {
const isPlaying = useArrangeStore((s) => s.playback.isPlaying);
const setPlaying = useArrangeStore((s) => s.setPlaying);
const arrangement = useArrangeStore((s) => s.arrangement);
const focusedItemId = useArrangeStore((s) => s.focusedItemId);
const focusRelative = useArrangeStore((s) => s.focusRelative);
const removeItem = useArrangeStore((s) => s.removeItem);
const shiftItem = useArrangeStore((s) => s.shiftItem);
const duplicateItem = useArrangeStore((s) => s.duplicateItem);
const chunkPool = useArrangeStore((s) => s.chunks);
const jobBpm = useArrangeStore((s) => s.jobBpm);
const jobBeatsPerBar = useArrangeStore((s) => s.jobBeatsPerBar);
Expand Down Expand Up @@ -146,7 +148,7 @@ export function ArrangeTransport() {
const id = useArrangeStore.getState().focusedItemId;
if (id) {
e.preventDefault();
removeItem(id);
void removeItemGuarded(id);
}
} else if (
!e.metaKey &&
Expand All @@ -161,13 +163,13 @@ export function ArrangeTransport() {
const id = useArrangeStore.getState().focusedItemId;
if (id) {
e.preventDefault();
duplicateItem(id);
void duplicateItemWithEdits(id);
}
}
}
window.addEventListener("keydown", handler);
return () => window.removeEventListener("keydown", handler);
}, [setPlaying, focusRelative, shiftItem, removeItem, duplicateItem]);
}, [setPlaying, focusRelative, shiftItem]);

const seekToItem = useArrangeStore((s) => s.seekToItem);
const => {
Expand Down Expand Up @@ -267,15 +269,15 @@ export function ArrangeTransport() {
<ChunkyButton
variant="secondary"
size="sm"
=> duplicateItem(focusedItem.id)}
=> void duplicateItemWithEdits(focusedItem.id)}
title="Duplicate frame · D"
aria-label="Duplicate frame"
iconLeft={<CopyIcon className="w-4 h-4" />}
/>
<ChunkyButton
variant="secondary"
size="sm"
=> removeItem(focusedItem.id)}
=> void removeItemGuarded(focusedItem.id)}
title="Drop frame · Backspace"
aria-label="Drop frame"
iconLeft={<TrashIcon className="w-4 h-4" />}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/arrange/FilmStrip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
import { useEffect, useLayoutEffect, useRef } from "react";
import { useArrangeStore } from "../../local/arrange/arrange-store";
import { removeItemGuarded } from "../../local/arrange/arrange-guarded-actions";
import {
effectiveBarsForChunk,
frameWidthForBars,
Expand All @@ -43,7 +44,6 @@ export function FilmStrip() {
const focusItem = useArrangeStore((s) => s.focusItem);
const seekToItem = useArrangeStore((s) => s.seekToItem);
const reorderItem = useArrangeStore((s) => s.reorderItem);
const removeItem = useArrangeStore((s) => s.removeItem);
const setStripScrollPx = useArrangeStore((s) => s.setStripScrollPx);
const setStripMetrics = useArrangeStore((s) => s.setStripMetrics);
const jobBpm = useArrangeStore((s) => s.jobBpm);
Expand Down Expand Up @@ -280,7 +280,7 @@ export function FilmStrip() {
e.preventDefault();
// Right-click = drop the item (matches the inspector
// affordance)
removeItem(item.id);
void removeItemGuarded(item.id);
}}
/>
<InsertionCursor
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/components/triage/ChunkInspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import {
effectiveChunkBpm,
useTriageStore,
} from "../../local/triage/triage-store";
import {
joinFocusedGuarded,
splitFocusedGuarded,
} from "../../local/triage/triage-guarded-actions";
import type { Chunk } from "../../storage/jobs-db";

const CONFORM_STATUS_LABEL: Record<string, string> = {
Expand All @@ -58,8 +62,6 @@ export function ChunkInspector() {
const resetBpm = useTriageStore((s) => s.resetBpmToDetected);
const setBeatsPerBar = useTriageStore((s) => s.setBeatsPerBar);
const extendChunkBars = useTriageStore((s) => s.extendChunkBars);
const splitChunkAt = useTriageStore((s) => s.splitChunkAt);
const joinChunks = useTriageStore((s) => s.joinChunks);
const resetChunk = useTriageStore((s) => s.resetChunk);
const conformChunk = useTriageStore((s) => s.conformChunk);
const revertConform = useTriageStore((s) => s.revertConform);
Expand Down Expand Up @@ -120,9 +122,9 @@ export function ChunkInspector() {
jobBpmValue={jobBpm?.value ?? null}
beatsPerBar={beatsPerBar}
fwd) => extendChunkBars(focused.id, back, fwd)}
=> splitChunkAt(focused.id, Math.round(currentTime * 1000))}
=> joinChunks(focused.id, "prev")}
=> joinChunks(focused.id, "next")}
=> void splitFocusedGuarded(Math.round(currentTime * 1000))}
=> void joinFocusedGuarded("prev")}
=> void joinFocusedGuarded("next")}
=> resetChunk(focused.id)}
=> conformChunk(focused.id)}
=> revertConform(focused.id)}
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/triage/DetectionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ export function DetectionPanel() {
state.envelope,
config,
).then((result) => {
// Preserve the user's per-chunk accept/reject decisions across
// re-detection. The min-bars filter is a view concern and
// doesn't touch chunk.accepted here.
// Preserve the user's per-chunk accept/reject decisions AND
// the chunk id across re-detection. The id match keeps any
// arrangement / pill references pointing at the right chunk
// so a slider tweak that re-detects the same chunk geometry
// doesn't quietly empty the user's arrangement.
const merged = result.chunks.map((c) => {
const prev = state.chunks.find(
(p) => p.startMs === c.startMs && p.endMs === c.endMs,
);
if (prev) {
return {
...c,
id: prev.id,
accepted: prev.accepted,
bpmOctaveShift: prev.bpmOctaveShift,
detectedBpm: c.detectedBpm ?? prev.detectedBpm,
Expand Down
Loading
Loading
0