From 67d033ef5241389806e576849287e5e5d4b59559 Mon Sep 17 00:00:00 2001 From: Prateek Chaplot Date: Mon, 23 Nov 2026 18:24:23 +0530 Subject: [PATCH] feat(ui): add keyboard accessibility and error-copy pass Move every user-visible string into strings.ts (section 11) and give each API error code a plain-language corrective action in ErrorBanner. Add a skip link and main landmark, focus management for errors, a named progress bar, aria-busy on the generate section, and an inline delete confirmation in History. Task T4.2 from docs/ARCHITECTURE.md section 14. --- docs/ARCHITECTURE.md | 1 + docs/TASKS.md | 9 +- frontend/src/App.test.tsx | 13 ++ frontend/src/App.tsx | 26 +-- frontend/src/components/DownloadBar.tsx | 13 +- frontend/src/components/ErrorBanner.test.tsx | 39 ++++ frontend/src/components/ErrorBanner.tsx | 70 ++++++-- frontend/src/components/GenerateBar.test.tsx | 6 + frontend/src/components/GenerateBar.tsx | 44 +++-- frontend/src/components/HistoryPanel.test.tsx | 37 +++- frontend/src/components/HistoryPanel.tsx | 136 ++++++++++---- frontend/src/components/InputPanel.tsx | 20 ++- frontend/src/components/PlaybackPanel.tsx | 39 ++-- frontend/src/components/SubtitleView.tsx | 19 +- frontend/src/components/VoicePanel.tsx | 22 ++- frontend/src/components/validation.ts | 13 +- frontend/src/strings.test.ts | 82 +++++++++ frontend/src/strings.ts | 170 ++++++++++++++++++ frontend/src/styles.css | 25 +++ 19 files changed, 638 insertions(+), 146 deletions(-) create mode 100644 frontend/src/components/ErrorBanner.test.tsx create mode 100644 frontend/src/strings.test.ts create mode 100644 frontend/src/strings.ts diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index ca766c7..c20afb4 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -213,6 +213,7 @@ tts/ │ └── src/ │ ├── main.tsx # mount │ ├── App.tsx # single page layout +│ ├── strings.ts # every user-visible string (section 11, NFR-04) │ ├── api/ │ │ ├── client.ts # typed fetch wrapper, error envelope decoding │ │ ├── mock.ts # MockApi implementing ApiInterface (VITE_API_MODE=mock) diff --git a/docs/TASKS.md b/docs/TASKS.md index f3b821e..1264d08 100644 --- a/docs/TASKS.md +++ b/docs/TASKS.md @@ -35,7 +35,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining | ID | Task | Branch | Verification | Status | |---|---|---|---|---| -| _(empty)_ | | | | | +| T4.2 | Accessibility + error-copy pass | `arch/tts/t4.2` | 111 Vitest (18 new); ESLint; `tsc --noEmit`; Prettier (CRLF); live Vite build; 23/23 keyboard-only AC15 checks against the built bundle with the real voice; 196 pytest unit; `git diff --check` | Awaiting PR review | ## Remaining @@ -61,7 +61,6 @@ _T4.1 done — see Done._ | ID | Task | Files | Deps | Acceptance criteria (summary) | |---|---|---|---|---| -| T4.2 | Accessibility + error-copy pass | `frontend/src/components/`, `frontend/src/strings.ts` | T3.1–T3.3 | Keyboard-only workflow manually verified and recorded | | T4.3 | Observability polish | `src/tts/config.py`, `src/tts/jobs/manager.py` | P2 | Failure reason logged without full input text | ### P5 — Verification + docs @@ -145,3 +144,9 @@ _T4.1 done — see Done._ - T4.1 mock parity decision (closes T1.4's follow-up): the mock stays as shipped. `mock.ts:buildCues` has no sentence grouping, no 1 200 ms floor, and no audio-duration cap, and its in-memory history is unbounded. Both are accepted **mock-only simplifications** and are recorded here instead of mirrored, because the mock is a P3 scaffold that only runs under `VITE_API_MODE=mock` and `mock.ts` is not one of T4.1's owned files; live behavior (`tts.subtitles.cues`, DAL eviction) is the binding contract. - T4.1 observation for T5.2 (`KNOWN_LIMITATIONS.md`): words whose phonemes do not reconcile become zero-width `aligned=false` entries, so the highlight is empty while they are spoken — the fixture sentence "Hello world. This is a live check. Numbers like 42 stay honest." produced 2 unaligned words (`This`, `a`) and a highlight gap between `world.` and `is`. This is the FR-05 honest-degradation path (and the words render `.unaligned`), but it is visible to users and should be documented rather than debugged. - T4.1 environment: this checkout was bare at task start (no `gh`, `.venv`, `frontend/node_modules`, Playwright browsers, or Piper voice); setup was re-run and the voice copied into an isolated `TTS_DATA_DIR=.venv\tts-data` so neither the live run nor the eviction check touched `%LOCALAPPDATA%\tts`. On Windows the Vite dev server binds `localhost` (IPv6) rather than `127.0.0.1`, and `npm run dev -- --port 5173` misparses the port as Vite's root, so the proxy check used `npx vite --port 5173` and `http://localhost:5173`. Prettier's CRLF check also needs the equals form on npm 11: `npx prettier --check . --end-of-line=crlf` (the T2.3 form `npm run format:check -- --end-of-line crlf` now fails with "No files matching the pattern were found: crlf"). +- T4.2 decisions: §11's "all strings live in one `strings.ts`" is now enforced — `frontend/src/strings.ts` holds every user-visible literal plus interpolating helpers (`characterCount`, `countLabel`, `statusGenerating`, `jumpLabel`, history labels) and the delete-confirm copy. Copy was moved verbatim (no wording changes) so the frozen aria-label contracts from T2.2/T3.3/T5.1 AC13 (`Open generation: …`, `Delete generation: …`, `N saved generation(s)`) are unchanged. `App.tsx` gained an additive import for the header/tagline/badge/footer copy and `styles.css` gained `.skip-link`, `.banner .error-guidance`, and `.history-confirm` rules; neither file is owned by T4.2, so this is recorded here. §6's frontend tree gained the `strings.ts` line in the same PR. +- T4.2 error copy: `errorGuidance(code)` maps all 15 §9.1 codes to a plain-language corrective action with a fallback for unknown codes; `ErrorBannerContent` (exported, prop-driven) renders heading + server message + "What you can do: …" and is static-markup testable. `ErrorBanner` keeps `role="alert"`, focuses the heading (`tabIndex={-1}`) when an error appears, and Dismiss restores focus to the previously focused element when it is still connected. Errors cleared by other reducer actions (`SET_INPUT`, `GENERATION_CREATED`, …) do not move focus — only the explicit Dismiss does. +- T4.2 accessibility: skip link is the first tab stop and targets `
` (footer stays outside the landmark); the generate section exposes `aria-busy`; `` is named and carries `aria-valuetext`; the active-word `scrollIntoView` is explicitly `behavior: "auto"` (the highlight transition is already disabled under `prefers-reduced-motion`, which T0.5 shipped). Word spans remain mouse-only seek targets: T3.2's decision is now final, and the sentence cue buttons (one per cue, each in tab order) are the keyboard word-seek path, which AC15 exercises. +- T4.2 history delete: T3.3's deferred confirmation is an inline two-step — Delete swaps to `Confirm delete` + `Keep` and shows "Delete this entry? This cannot be undone.", the confirm button autofocuses, and Keep returns focus to the row's Delete button. No `window.confirm`, no new dependency. Focus effects are not unit-tested (no jsdom, §5 lists vitest only); they were verified in the live keyboard run, while the confirmation markup and labels are covered by static-markup tests. +- T4.2 AC15 record: 23/23 keyboard-only checks passed in **live** mode against the built bundle served by `tts` (port 8322, isolated `TTS_DATA_DIR=.venv\tts-data`, real `en_US-lessac-medium`). Driven by keyboard events only (Tab/Shift+Tab/Enter/Space): first Tab → skip link → Enter → main landmark; Tab → textarea → typed "Hello world. This is a keyboard check."; Tab → voice select (populated) → Tab → Generate audio → Enter → "Audio ready." (aligned ratio 0.714); Tab → Play → Enter starts playback, Space pauses; Tab → sentence cue (focusable `Jump to 00:00: …`); Tab → WAV, SRT, VTT downloads all named `hello-world-this-is-a-keyboard_20261123-125257.{wav,srt,vtt}`; Tab → Delete → Enter (focus moves to Confirm delete) → Tab → Keep → Enter (focus returns to Delete); empty-input pass: error banner takes focus, shows "Enter some text before generating…" plus "What you can do: …", Tab reaches Dismiss, Enter returns focus to Generate audio. The temporary headless-Chromium script was removed after the run and is not committed. +- T4.2 environment: port 8321 was already bound by a stale `tts` process, so the live run used 8322; the temporary script lives in `frontend/` so it resolves `@playwright/test` from `frontend/node_modules`. Vitest count moved 93 → 111 (9 in `strings.test.ts`, 4 in new `ErrorBanner.test.tsx`, 2 history-confirm markup, 2 skip-link/main, 1 `aria-busy`). diff --git a/frontend/src/App.test.tsx b/frontend/src/App.test.tsx index 4f938b9..da68f1f 100644 --- a/frontend/src/App.test.tsx +++ b/frontend/src/App.test.tsx @@ -43,6 +43,19 @@ describe("App shell", () => { expect(html).toContain("Nothing generated yet"); }); + it("offers a skip link to the main landmark as the first control", () => { + const html = renderApp(); + expect(html.indexOf('class="skip-link"')).toBeGreaterThan(0); + expect(html.indexOf('class="skip-link"')).toBeLessThan(html.indexOf("Skip to main content<\/a>/); + expect(html).toContain('
'); + }); + + it("keeps the footer outside the main landmark", () => { + const html = renderApp(); + expect(html.indexOf("
")).toBeLessThan(html.indexOf(" { expect(renderApp()).not.toContain('role="alert"'); }); diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 4d85c86..4e3f5c9 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -16,6 +16,7 @@ import { PlaybackPanel } from "./components/PlaybackPanel"; import { VoicePanel } from "./components/VoicePanel"; import { clampRate, clampVolume } from "./components/validation"; import { useApp } from "./state/appContext"; +import { strings } from "./strings"; export function App() { const { dispatch } = useApp(); @@ -63,23 +64,28 @@ export function App() { return (
+ + {strings.app.skipLink} +
-

tts

-

Local text to speech with synchronized subtitles.

- {apiMode === "mock" ?

Mock mode: sample data

: null} +

{strings.app.title}

+

{strings.app.tagline}

+ {apiMode === "mock" ?

{strings.app.mockBadge}

: null}
- - - - +
+ + + + - + - + +
-

Everything runs on this machine; nothing is uploaded.

+

{strings.app.footer}

); diff --git a/frontend/src/components/DownloadBar.tsx b/frontend/src/components/DownloadBar.tsx index bba1866..a9da5af 100644 --- a/frontend/src/components/DownloadBar.tsx +++ b/frontend/src/components/DownloadBar.tsx @@ -10,6 +10,7 @@ import { useState } from "react"; import { api } from "../api"; import { toApiError } from "../api/client"; +import { strings } from "../strings"; import { useApp } from "../state/appContext"; import type { GenerationDetail, SubtitleFormat } from "../types/contracts"; @@ -112,10 +113,8 @@ export function DownloadBar({ detail }: DownloadBarProps) { return (
-

Downloads

-

- Files are named after the first words of the input and when the generation was created. -

+

{strings.downloads.heading}

+

{strings.downloads.hint}

diff --git a/frontend/src/components/ErrorBanner.test.tsx b/frontend/src/components/ErrorBanner.test.tsx new file mode 100644 index 0000000..cbcd62c --- /dev/null +++ b/frontend/src/components/ErrorBanner.test.tsx @@ -0,0 +1,39 @@ +import { renderToStaticMarkup } from "react-dom/server"; +import { describe, expect, it } from "vitest"; +import type { ErrorInfo } from "../types/contracts"; +import { ErrorBannerContent } from "./ErrorBanner"; + +function renderBanner(code = "ENGINE_ERROR", message = "The speech engine failed."): string { + return renderToStaticMarkup( + undefined} + />, + ); +} + +describe("ErrorBannerContent", () => { + it("announces the problem, the server message, and the corrective action", () => { + const html = renderBanner(); + expect(html).toContain('role="alert"'); + expect(html).toContain("Something went wrong"); + expect(html).toContain("The speech engine failed."); + expect(html).toContain("What you can do"); + expect(html).toContain("Try a shorter text or a different voice."); + }); + + it("makes the heading focusable so focus can move there", () => { + expect(renderBanner()).toMatch(/]*tabindex="-1"/); + }); + + it("labels the dismiss control for screen readers", () => { + const html = renderBanner(); + expect(html).toContain('aria-label="Dismiss error message"'); + expect(html).toContain(">Dismiss"); + }); + + it("still gives advice for a code outside the fixed set", () => { + const html = renderBanner("SOMETHING_ELSE", "Unexpected problem."); + expect(html).toContain("Try again. If the problem continues"); + }); +}); diff --git a/frontend/src/components/ErrorBanner.tsx b/frontend/src/components/ErrorBanner.tsx index 01c1c93..b7eefd4 100644 --- a/frontend/src/components/ErrorBanner.tsx +++ b/frontend/src/components/ErrorBanner.tsx @@ -1,32 +1,78 @@ /** * Single error surface for the whole page (ARCHITECTURE.md section 16: every * frontend error goes through here with its message and corrective action). + * + * Accessibility (NFR-04): `role="alert"` announces the error, the message and + * its corrective action are both read, and focus moves to the heading so a + * keyboard user is not stranded at the trigger. Dismiss returns focus to the + * control that was focused when the error appeared. */ +import { useEffect, useRef, type Ref } from "react"; import { useApp } from "../state/appContext"; +import { errorGuidance, strings } from "../strings"; +import type { ErrorInfo } from "../types/contracts"; -export function ErrorBanner() { - const { state, dispatch } = useApp(); - - if (state.error === null) { - return null; - } +export interface ErrorBannerContentProps { + error: ErrorInfo; + onDismiss: () => void; + headingRef?: Ref; +} +/** Presentational banner; exported so the copy can be tested without effects. */ +export function ErrorBannerContent({ error, onDismiss, headingRef }: ErrorBannerContentProps) { return (
-

Something went wrong

+

+ {strings.error.heading} +

-

{state.error.message}

+

{error.message}

+

+ {strings.error.guidanceLabel}: {errorGuidance(error.code)} +

); } + +export function ErrorBanner() { + const { state, dispatch } = useApp(); + const headingRef = useRef(null); + const restoreRef = useRef(null); + const error = state.error; + + useEffect(() => { + if (error === null) { + return; + } + const active = document.activeElement; + if (active instanceof HTMLElement && active !== document.body) { + restoreRef.current = active; + } + headingRef.current?.focus(); + }, [error]); + + if (error === null) { + return null; + } + + function dismiss(): void { + const target = restoreRef.current; + restoreRef.current = null; + dispatch({ type: "CLEAR_ERROR" }); + if (target !== null && target.isConnected) { + target.focus(); + } + } + + return ; +} diff --git a/frontend/src/components/GenerateBar.test.tsx b/frontend/src/components/GenerateBar.test.tsx index 41d28f7..77d19bf 100644 --- a/frontend/src/components/GenerateBar.test.tsx +++ b/frontend/src/components/GenerateBar.test.tsx @@ -25,4 +25,10 @@ describe("GenerateBar", () => { expect(html).toContain("Nothing generated yet"); expect(html).not.toContain(" { + const html = renderBar(); + expect(html).toContain('aria-busy="false"'); + expect(html).toContain('aria-live="polite"'); + }); }); diff --git a/frontend/src/components/GenerateBar.tsx b/frontend/src/components/GenerateBar.tsx index 1aa7a2e..807dbd3 100644 --- a/frontend/src/components/GenerateBar.tsx +++ b/frontend/src/components/GenerateBar.tsx @@ -9,31 +9,32 @@ import { useEffect, useRef } from "react"; import { api } from "../api"; import { toApiError } from "../api/client"; +import { strings } from "../strings"; import { useApp, type CurrentGeneration } from "../state/appContext"; import type { GenerationDetail, GenerationStreamEvent } from "../types/contracts"; import { validateGeneration } from "./validation"; function statusLabel(current: CurrentGeneration | null): string { if (current === null) { - return "Nothing generated yet"; + return strings.generate.statusEmpty; } switch (current.status) { case "queued": - return "Queued. Waiting for the worker."; + return strings.generate.statusQueued; case "running": return current.sentenceCount > 0 - ? `Generating: ${current.sentenceIndex} of ${current.sentenceCount} sentences done.` - : "Generating…"; + ? strings.generate.statusGenerating(current.sentenceIndex, current.sentenceCount) + : strings.generate.statusGeneratingUnknown; case "cancelling": - return "Cancelling…"; + return strings.generate.statusCancelling; case "succeeded": return current.detail === undefined - ? "Finished, but the details could not be loaded. Check the message above." - : "Audio ready."; + ? strings.generate.statusMissingDetail + : strings.generate.statusReady; case "failed": - return "Generation failed. See the message above."; + return strings.generate.statusFailed; case "cancelled": - return "Generation cancelled. No audio was saved."; + return strings.generate.statusCancelled; } } @@ -217,17 +218,15 @@ export function GenerateBar() { const hasVoices = state.voices.length > 0; return ( -
-

Generate

+
+

{strings.generate.heading}

{hasVoices ? ( -

- Start a generation, watch progress, and cancel if you change your mind. -

+

{strings.generate.hint}

) : (

- No voices installed, so generation is disabled. Run{" "} - tts add-voice <name> in a terminal, then reload this page. + {strings.generate.noVoicesPrefix} tts add-voice <name>{" "} + {strings.generate.noVoicesSuffix}

)} @@ -235,7 +234,12 @@ export function GenerateBar() { {statusLabel(current)}

{active && current !== null && current.sentenceCount > 0 ? ( - + ) : null}
@@ -246,7 +250,7 @@ export function GenerateBar() { void handleGenerate(); }} > - Generate audio + {strings.generate.generate} {active ? ( ) : null}
diff --git a/frontend/src/components/HistoryPanel.test.tsx b/frontend/src/components/HistoryPanel.test.tsx index 7540302..1fce95c 100644 --- a/frontend/src/components/HistoryPanel.test.tsx +++ b/frontend/src/components/HistoryPanel.test.tsx @@ -11,6 +11,7 @@ import { historyStatusText, HistoryList, HistoryPanel, + type HistoryBusy, } from "./HistoryPanel"; const SUCCEEDED: GenerationSummary = { @@ -51,14 +52,22 @@ const FILE_SOURCE: GenerationSummary = { inputFilename: "notes.txt", }; -function renderList(items: GenerationSummary[], total = items.length): string { +function renderList( + items: GenerationSummary[], + total = items.length, + options: { confirmingId?: string | null; busy?: HistoryBusy } = {}, +): string { return renderToStaticMarkup( undefined} - onDelete={() => undefined} + onRequestDelete={() => undefined} + onConfirmDelete={() => undefined} + onKeep={() => undefined} />, ); } @@ -146,6 +155,28 @@ describe("HistoryList", () => { /]*disabled[^>]*aria-label="Delete generation: Still generating\.[^>]*>Delete<\/button>/, ); }); + + it("asks for confirmation before deleting a row", () => { + const html = renderList([SUCCEEDED], 1, { confirmingId: SUCCEEDED.generationId }); + expect(html).toContain("Delete this entry? This cannot be undone."); + expect(html).toContain('aria-label="Confirm delete generation: Hello world."'); + expect(html).toContain(">Confirm delete"); + expect(html).toContain('aria-label="Keep generation: Hello world."'); + expect(html).toContain(">Keep"); + expect(html).not.toContain('aria-label="Delete generation: Hello world."'); + expect(html).toMatch( + /]*disabled[^>]*aria-label="Open generation: Hello world\.[^>]*>Open<\/button>/, + ); + }); + + it("keeps other rows out of the confirmation state", () => { + const second = { ...FAILED, inputPreview: "Second entry." }; + const html = renderList([SUCCEEDED, second], 2, { confirmingId: second.generationId }); + expect(html.match(/Confirm delete<\/button>/g)).toHaveLength(1); + expect(html.match(/Delete this entry\? This cannot be undone\./g)).toHaveLength(1); + expect(html).toContain('aria-label="Delete generation: Hello world."'); + expect(html).toContain('aria-label="Confirm delete generation: Second entry."'); + }); }); describe("HistoryPanel", () => { diff --git a/frontend/src/components/HistoryPanel.tsx b/frontend/src/components/HistoryPanel.tsx index d90af9b..ce61803 100644 --- a/frontend/src/components/HistoryPanel.tsx +++ b/frontend/src/components/HistoryPanel.tsx @@ -10,6 +10,7 @@ import { useCallback, useEffect, useRef, useState, type Dispatch } from "react"; import { api } from "../api"; import { toApiError } from "../api/client"; +import { strings } from "../strings"; import { useApp, type AppAction } from "../state/appContext"; import type { GenerationDetail, GenerationSummary } from "../types/contracts"; @@ -33,18 +34,20 @@ export function historyStatusText(item: GenerationSummary): string { switch (item.status) { case "succeeded": return item.durationSeconds === null - ? "Ready" - : `Ready · ${Math.round(item.durationSeconds)} s`; + ? strings.history.statusReady + : strings.history.statusReadyWithDuration(item.durationSeconds); case "failed": - return item.error === null ? "Failed" : `Failed: ${item.error.message}`; + return item.error === null + ? strings.history.statusFailed + : strings.history.statusFailedWithReason(item.error.message); case "cancelled": - return "Cancelled"; + return strings.history.statusCancelled; case "queued": - return "Queued"; + return strings.history.statusQueued; case "running": - return "Generating…"; + return strings.history.statusRunning; case "cancelling": - return "Cancelling…"; + return strings.history.statusCancelling; } } @@ -62,7 +65,7 @@ export function historyPreview(item: GenerationSummary): string { if (item.inputPreview.trim().length > 0) { return item.inputPreview; } - return item.inputFilename ?? "(no preview)"; + return item.inputFilename ?? strings.history.noPreview; } /** Wide viewports open the panel; narrow ones start collapsed (section 12). */ @@ -89,19 +92,44 @@ export interface HistoryListProps { items: GenerationSummary[]; total: number; busy: HistoryBusy; + /** Row awaiting delete confirmation, or null. */ + confirmingId: string | null; + /** Row whose Delete button should take focus after a cancelled confirmation. */ + focusDeleteId: string | null; onRestore: (item: GenerationSummary) => void; - onDelete: (item: GenerationSummary) => void; + onRequestDelete: (item: GenerationSummary) => void; + onConfirmDelete: (item: GenerationSummary) => void; + onKeep: () => void; } /** Presentational list; kept separate so it can be tested without effects. */ -export function HistoryList({ items, total, busy, onRestore, onDelete }: HistoryListProps) { - const countLabel = `${total} saved generation${total === 1 ? "" : "s"}`; +export function HistoryList({ + items, + total, + busy, + confirmingId, + focusDeleteId, + onRestore, + onRequestDelete, + onConfirmDelete, + onKeep, +}: HistoryListProps) { + const countLabel = strings.history.countLabel(total); + const restoreFocusRef = useRef(null); + + // Focus returns to Delete after "Keep" (and only then), so a keyboard user + // does not land on the document body when the confirm buttons unmount. + useEffect(() => { + if (focusDeleteId !== null) { + restoreFocusRef.current?.focus(); + } + }, [focusDeleteId]); if (items.length === 0) { return ( <>

{countLabel}

-

Nothing here yet. Generate audio and it will appear in this list.

+

{strings.history.empty}

); } @@ -109,13 +137,11 @@ export function HistoryList({ items, total, busy, onRestore, onDelete }: History return ( <>

{countLabel}

-

- Open a finished generation to load its audio and subtitles. Deleting an entry removes only - that entry. -

+

{strings.history.hint}

    {items.map((item) => { const preview = historyPreview(item); + const confirming = confirmingId === item.generationId; const restorable = canRestore(item) && busy === null; const deletable = canDelete(item) && busy === null; const restoring = @@ -135,26 +161,57 @@ export function HistoryList({ items, total, busy, onRestore, onDelete }: History
    - + {confirming ? ( + <> + + + + ) : ( + + )}
    + {confirming ? ( +

    + {strings.history.confirmPrompt} +

    + ) : null} ); })} @@ -166,6 +223,8 @@ export function HistoryList({ items, total, busy, onRestore, onDelete }: History export function HistoryPanel() { const { state, dispatch } = useApp(); const [busy, setBusy] = useState(null); + const [confirmingId, setConfirmingId] = useState(null); + const [focusDeleteId, setFocusDeleteId] = useState(null); const [isOpen, setIsOpen] = useState(() => historyStartsOpen(readNarrowViewport())); const restoredUrlRef = useRef(null); const refreshedRef = useRef(null); @@ -227,6 +286,7 @@ export function HistoryPanel() { }, []); async function handleRestore(item: GenerationSummary): Promise { + setConfirmingId(null); setBusy({ id: item.generationId, kind: "restore" }); let detail: GenerationDetail; try { @@ -257,6 +317,8 @@ export function HistoryPanel() { } async function handleDelete(item: GenerationSummary): Promise { + setConfirmingId(null); + setFocusDeleteId(null); setBusy({ id: item.generationId, kind: "delete" }); try { await api.deleteGeneration(item.generationId); @@ -278,18 +340,28 @@ export function HistoryPanel() { }} > -

    History

    +

    {strings.history.heading}

    { void handleRestore(item); }} - onDelete={(item) => { + onRequestDelete={(item) => { + setFocusDeleteId(null); + setConfirmingId(item.generationId); + }} + onConfirmDelete={(item) => { void handleDelete(item); }} + onKeep={() => { + setFocusDeleteId(confirmingId); + setConfirmingId(null); + }} />
diff --git a/frontend/src/components/InputPanel.tsx b/frontend/src/components/InputPanel.tsx index 7c1955f..c52e50c 100644 --- a/frontend/src/components/InputPanel.tsx +++ b/frontend/src/components/InputPanel.tsx @@ -8,6 +8,7 @@ import type { ChangeEvent } from "react"; import { api } from "../api"; import { toApiError } from "../api/client"; +import { strings } from "../strings"; import { useApp } from "../state/appContext"; import { MAX_INPUT_CHARS, inputTooLongMessage } from "./validation"; @@ -37,15 +38,15 @@ export function InputPanel() { return (
-

Text

+

{strings.input.heading}

- +