mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Added batch auto hot cue and reworked remove context menu
This commit is contained in:
1 parent
76bf142fb4
commit
d18db9566c
21 files changed
+1044
-150
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import { useEffect, useState, type ReactNode } from 'react'
|
||||
|
||||
export interface ConfirmRequest {
|
||||
title: string
|
||||
/** What will happen, in a sentence or two. */
|
||||
body: ReactNode
|
||||
/** The confirm button's label, e.g. "Remove 3 tracks". */
|
||||
confirmLabel: string
|
||||
onConfirm: () => Promise<void> | void
|
||||
}
|
||||
|
||||
interface Props extends ConfirmRequest {
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
const confirm = async () => {
|
||||
if (busy) return
|
||||
setBusy(true)
|
||||
try {
|
||||
await onConfirm()
|
||||
onClose()
|
||||
} catch {
|
||||
setBusy(false) // the caller has already reported it; allow a retry
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !busy) onClose()
|
||||
// A focused button handles its own Enter — otherwise tabbing to Cancel
|
||||
// and pressing Enter would run the destructive action.
|
||||
if (e.key === 'Enter' && !(e.target instanceof HTMLButtonElement)) {
|
||||
e.preventDefault()
|
||||
void confirm()
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
})
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-modal="true"
|
||||
className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6"
|
||||
onClick={() => !busy && onClose()}
|
||||
>
|
||||
<div
|
||||
className="w-full max-w-sm overflow-hidden rounded-xl border border-line bg-ink-900 shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="border-b border-line px-5 py-4 text-[15px] font-semibold tracking-tight">
|
||||
{title}
|
||||
</div>
|
||||
<div className="space-y-2 px-5 py-4 text-sm text-muted">{body}</div>
|
||||
<div className="flex items-center justify-end gap-2 border-t border-line px-5 py-3">
|
||||
<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"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={() => void confirm()}
|
||||
disabled={busy}
|
||||
className="rounded-md bg-pink px-4 py-1.5 text-sm font-medium text-ink-950 hover:brightness-110 disabled:opacity-50"
|
||||
>
|
||||
{confirmLabel}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user