From ce06731dc80a79ce0a85c329cb532e9992d1ae8f Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Fri, 25 Sep 2026 17:19:44 +0200 Subject: [PATCH] Moved native confirmation dialogs to custom component --- CLAUDE.md | 7 +++ frontend/src/components/ConfirmDialog.tsx | 13 +++-- frontend/src/components/ExportsSection.tsx | 11 ++++- frontend/src/components/GridControls.tsx | 15 +++--- frontend/src/components/Sidebar.tsx | 9 +++- frontend/src/lib/confirm.tsx | 56 ++++++++++++++++++++++ frontend/src/main.tsx | 3 ++ 7 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 frontend/src/lib/confirm.tsx diff --git a/CLAUDE.md b/CLAUDE.md index 437cf28..56fa072 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -681,6 +681,13 @@ frontend at `http://localhost:5173`. can show a mark twice). That file is a lookup of display ASSETS by platform id, not platform branching; an unknown id falls back to a generic mark, so a new adapter needs no change there to appear. Keep `api.ts` types aligned with `schemas.py`. +- **Never `window.confirm` / `alert` / `prompt`.** They cannot be themed, they + block the event loop (a playing deck stutters), and under Tauri they read as a + web page. Use `await askConfirm({ title, body, confirmLabel, tone? })` from + `lib/confirm.tsx` — same one-line shape as `confirm()`, rendered as the themed + `ConfirmDialog` by the `ConfirmHost` mounted once in `main.tsx`. `tone` is + `danger` (default, pink) or `primary`. Components that already hold dialog + state may still render `ConfirmDialog` directly. ## Theme — "dark liquid glass" diff --git a/frontend/src/components/ConfirmDialog.tsx b/frontend/src/components/ConfirmDialog.tsx index d55412d..62dcb22 100644 --- a/frontend/src/components/ConfirmDialog.tsx +++ b/frontend/src/components/ConfirmDialog.tsx @@ -7,6 +7,9 @@ export interface ConfirmRequest { body: ReactNode /** The confirm button's label, e.g. "Remove 3 tracks". */ confirmLabel: string + /** `danger` (default) for destructive actions — a pink button; `primary` + * for a caution that is not destruction, e.g. switching library. */ + tone?: 'danger' | 'primary' onConfirm: () => Promise | void } @@ -16,7 +19,7 @@ interface Props extends ConfirmRequest { /** A yes/no confirmation for destructive actions. Enter confirms and Esc * cancels, so a confirmed Delete key stays a two-keystroke action. */ -export function ConfirmDialog({ title, body, confirmLabel, onConfirm, onClose }: Props) { +export function ConfirmDialog({ title, body, confirmLabel, tone = 'danger', onConfirm, onClose }: Props) { const [busy, setBusy] = useState(false) const confirm = async () => { @@ -62,14 +65,18 @@ export function ConfirmDialog({ title, body, confirmLabel, onConfirm, onClose }: diff --git a/frontend/src/components/ExportsSection.tsx b/frontend/src/components/ExportsSection.tsx index ae92ff1..fabf39e 100644 --- a/frontend/src/components/ExportsSection.tsx +++ b/frontend/src/components/ExportsSection.tsx @@ -4,6 +4,7 @@ import { api, type ExportSet } from '../api' import { ExportDialog } from './ExportDialog' import { ExportRunDialog } from './ExportRunDialog' import type { Source } from './Sidebar' +import { askConfirm } from '../lib/confirm' import { Icon } from '../lib/icons' /** @@ -104,10 +105,16 @@ export function ExportsSection({ source, onSelect, onDone, onError }: Props) { onSelect={onSelect} onEdit={() => setDialog({ editing: set })} onRun={() => setRunning(set)} - onDelete={() => { + onDelete={async () => { // Deleting a set never touches its destination folder — the files // already exported are the user's, not Konduktor's to clean up. - if (confirm(`Delete the export “${set.name}”? Nothing already exported is removed.`)) + if ( + await askConfirm({ + title: `Delete the export “${set.name}”?`, + body: 'Nothing already exported is removed — the files in its folder stay where they are.', + confirmLabel: 'Delete export', + }) + ) remove.mutate(set.id) }} onError={onError} diff --git a/frontend/src/components/GridControls.tsx b/frontend/src/components/GridControls.tsx index 278f4b5..482160b 100644 --- a/frontend/src/components/GridControls.tsx +++ b/frontend/src/components/GridControls.tsx @@ -1,4 +1,5 @@ import { useEffect, useRef, useState } from 'react' +import { askConfirm } from '../lib/confirm' import { Icon } from '../lib/icons' import { MIN_TAPS, RESET_MS, TapTempo } from '../lib/tapTempo' @@ -278,13 +279,15 @@ export function GridEditStrip({ Marker