diff --git a/docs/TASKS.md b/docs/TASKS.md index 6cda540..ee7768d 100644 --- a/docs/TASKS.md +++ b/docs/TASKS.md @@ -33,7 +33,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining | ID | Task | Branch | Verification | Status | |---|---|---|---|---| -| _(empty)_ | | | | | +| T3.3 | History | `arch/tts/t3.3` | 93 Vitest (10 new); ESLint; `tsc --noEmit`; Prettier (CRLF); live + mock Vite builds; mock-mode Chromium 15/15 (narrow starts collapsed, summary toggle, empty state, 2 entries with preview/voice/time, restore loads subtitles + audio, delete one keeps the other, delete open entry clears playback, no console errors); 196 pytest; Ruff check/format; strict mypy; `git diff --check` | PR pending review | ## Remaining @@ -51,9 +51,7 @@ _All P2 tasks done._ ### P3 — UI against contracts -| ID | Task | Files | Deps | Acceptance criteria (summary) | -|---|---|---|---|---| -| T3.3 | History | `frontend/src/` history component | T0.5 | History preview, restore, and individual deletion | +_T3.3 in progress (see Doing)._ ### P4 — Integration @@ -132,3 +130,8 @@ _All P2 tasks done._ - T3.2 accessibility decision: word spans are mouse-only seek targets; sentence cue ` + + + + ); + })} + + + ); +} + +export function HistoryPanel() { + const { state, dispatch } = useApp(); + const [busy, setBusy] = useState(null); + const [isOpen, setIsOpen] = useState(() => historyStartsOpen(readNarrowViewport())); + const restoredUrlRef = useRef(null); + const refreshedRef = useRef(null); + const current = state.current; + const historyItems = state.history.items; + const currentAudioUrl = current?.audioUrl; + + const loadHistory = useCallback(async (): Promise => { + try { + const list = await api.listGenerations(); + dispatch({ type: "HISTORY_LOADED", items: list.items, total: list.total }); + } catch (error) { + dispatchFailure(dispatch, error); + } + }, [dispatch]); + + useEffect(() => { + void loadHistory(); + }, [loadHistory]); + + // Include a just-finished generation once, so the list follows the current + // playback item without polling. + useEffect(() => { + if (current === null) { + return; + } + if ( + current.status !== "succeeded" && + current.status !== "failed" && + current.status !== "cancelled" + ) { + return; + } + if (historyItems.some((item) => item.generationId === current.id)) { + return; + } + if (refreshedRef.current === current.id) { + return; + } + refreshedRef.current = current.id; + void loadHistory(); + }, [current, historyItems, loadHistory]); + + // Release the restored object URL when playback moves on or the panel goes. + useEffect(() => { + if (restoredUrlRef.current !== null && restoredUrlRef.current !== currentAudioUrl) { + URL.revokeObjectURL(restoredUrlRef.current); + restoredUrlRef.current = null; + } + }, [currentAudioUrl]); + + useEffect(() => { + return () => { + if (restoredUrlRef.current !== null) { + URL.revokeObjectURL(restoredUrlRef.current); + restoredUrlRef.current = null; + } + }; + }, []); + + async function handleRestore(item: GenerationSummary): Promise { + setBusy({ id: item.generationId, kind: "restore" }); + let detail: GenerationDetail; + try { + detail = await api.getGeneration(item.generationId); + } catch (error) { + dispatchFailure(dispatch, error); + setBusy(null); + return; + } + + let audioUrl: string | undefined; + try { + const blob = await api.getAudioBlob(item.generationId); + audioUrl = URL.createObjectURL(blob); + } catch (error) { + // The detail still restores the subtitle view; report the missing audio. + dispatchFailure(dispatch, error); + } + + if (audioUrl !== undefined) { + if (restoredUrlRef.current !== null) { + URL.revokeObjectURL(restoredUrlRef.current); + } + restoredUrlRef.current = audioUrl; + } + dispatch({ type: "SELECT_HISTORY_ITEM", detail, audioUrl }); + setBusy(null); + } + + async function handleDelete(item: GenerationSummary): Promise { + setBusy({ id: item.generationId, kind: "delete" }); + try { + await api.deleteGeneration(item.generationId); + dispatch({ type: "HISTORY_DELETED", id: item.generationId }); + } catch (error) { + dispatchFailure(dispatch, error); + } finally { + setBusy(null); + } + } + + return ( +
+
{ + setIsOpen(event.currentTarget.open); + }} + > + +

History

+
+ { + void handleRestore(item); + }} + onDelete={(item) => { + void handleDelete(item); + }} + /> +
+
+ ); +} diff --git a/frontend/src/styles.css b/frontend/src/styles.css index cd4c146..87897fb 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -318,6 +318,58 @@ audio { margin-top: 0.5rem; } +.history summary { + cursor: pointer; +} + +.history summary h2 { + display: inline; + margin: 0; +} + +.history-list { + margin: 0.85rem 0 0; + padding: 0; + list-style: none; + display: grid; + gap: 0.6rem; +} + +.history-item { + display: flex; + flex-wrap: wrap; + align-items: flex-start; + justify-content: space-between; + gap: 0.5rem 0.75rem; + border: 1px solid var(--border); + border-radius: 0.4rem; + padding: 0.6rem 0.75rem; +} + +.history-body { + min-width: 0; + flex: 1 1 14rem; +} + +.history-preview { + margin: 0; + overflow-wrap: anywhere; +} + +.history-meta { + margin-top: 0.15rem; + font-size: 0.9rem; +} + +.history-status { + margin-top: 0.15rem; +} + +.history-actions { + margin-top: 0; + align-self: center; +} + code { padding: 0 0.25rem; border-radius: 0.25rem;