Moved native confirmation dialogs to custom component

This commit is contained in:
patben8 committed 2026-09-25 17:19:44 +02:00
1 parent c6aaded26d
commit ce06731dc8
7 files changed
+101 -13

No files matched your search

+10 -3
View File
@@ -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> | 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 }:
<button
onClick={onClose}
disabled={busy}
className="rounded-md px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text disabled:opacity-40"
className="btn-glass rounded-full px-4 py-1.5 text-sm text-muted hover:text-text disabled:opacity-40"
>
Cancel
</button>
<button
onClick={() => void confirm()}
disabled={busy}
className="rounded-full bg-pink/15 shadow-[inset_0_1px_0_rgb(255_255_255/0.12),inset_0_0_0_1px_rgb(255_122_154/0.55)] hover:bg-pink/25 px-4 py-1.5 text-sm font-semibold text-[#ffd0da] disabled:opacity-50"
className={`rounded-full px-4 py-1.5 text-sm font-semibold disabled:opacity-50 ${
tone === 'primary'
? 'btn-primary'
: 'bg-pink/15 text-[#ffd0da] shadow-[inset_0_1px_0_rgb(255_255_255/0.12),inset_0_0_0_1px_rgb(255_122_154/0.55)] hover:bg-pink/25'
}`}
>
{confirmLabel}
</button>
+9 -2
View File
@@ -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}
+9 -6
View File
@@ -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({
<span className="hidden @[34rem]:inline">Marker</span>
</button>
<button
onClick={() => {
onClick={async () => {
if (
confirm(
flexible
? `Delete this track's beatgrid? All ${markerCount} grid markers will be removed.`
: "Delete this track's beatgrid?",
)
await askConfirm({
title: "Delete this track's beatgrid?",
body: flexible
? `All ${markerCount} grid markers will be removed.`
: 'The grid marker will be removed.',
confirmLabel: 'Delete grid',
})
) {
onDeleteGrid()
}
+7 -2
View File
@@ -7,6 +7,7 @@ import { SettingsMenu } from './SettingsMenu'
import { DevicesSection } from './DevicesSection'
import { ExportsSection } from './ExportsSection'
import { ConfirmDialog, type ConfirmRequest } from './ConfirmDialog'
import { askConfirm } from '../lib/confirm'
import { ContextMenu, type MenuItem } from './ContextMenu'
import { Icon, type IconName } from '../lib/icons'
import { PlatformIcon } from '../lib/platformIcons'
@@ -325,10 +326,14 @@ export function Sidebar({
// Switching library throws away every unsaved edit — the adapter holds them in
// its native model, and opening another library replaces it. Worth a confirm:
// until now there was no way to switch at all, so this hazard is new.
const switchLibrary = () => {
const switchLibrary = async () => {
if (
dirty &&
!confirm('You have unsaved changes. Opening a different library will discard them.')
!(await askConfirm({
title: 'Discard unsaved changes?',
body: 'You have unsaved changes. Opening a different library will discard them.',
confirmLabel: 'Discard and switch',
}))
)
return
onSwitchLibrary()