From 4fdb2b7ce18a1c93d658c150cf1039e1319f589d Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Mon, 2 Nov 2026 13:13:17 +0100 Subject: [PATCH] Unified pop-up modals and out-click close behaviour --- CLAUDE.md | 14 ++- frontend/src/components/AddFilesDialog.tsx | 14 +-- frontend/src/components/AnalyzeDialog.tsx | 21 +--- frontend/src/components/AppSettings.tsx | 21 +--- frontend/src/components/AutoCueDialog.tsx | 18 +--- frontend/src/components/ConfirmDialog.tsx | 19 +--- .../src/components/ConvertStemsDialog.tsx | 15 +-- frontend/src/components/EditTagsDialog.tsx | 13 +-- frontend/src/components/ExportDialog.tsx | 11 +-- frontend/src/components/ExportRunDialog.tsx | 11 +-- frontend/src/components/FolderPicker.tsx | 9 +- frontend/src/components/HistoryPanel.tsx | 13 +-- frontend/src/components/ImportDialog.tsx | 11 +-- .../src/components/LocalLibrariesSettings.tsx | 25 ++--- frontend/src/components/Modal.tsx | 97 +++++++++++++++++++ frontend/src/components/NormalizeDialog.tsx | 21 +--- frontend/src/components/PathMappingDialog.tsx | 13 +-- frontend/src/components/PushRunDialog.tsx | 9 +- frontend/src/components/QuitGuard.tsx | 21 +--- frontend/src/components/RelocateDialog.tsx | 24 ++--- .../src/components/RemoteCacheSettings.tsx | 23 ++--- frontend/src/components/RemotePicker.tsx | 13 +-- frontend/src/components/SetPositionDialog.tsx | 22 +---- frontend/src/components/ShortcutsDialog.tsx | 14 +-- frontend/src/components/StemReportDialog.tsx | 22 +---- frontend/src/components/StemsSettings.tsx | 22 +---- frontend/src/components/TrackInfoDialog.tsx | 24 +---- frontend/src/components/UpdateDialog.tsx | 13 +-- 28 files changed, 234 insertions(+), 319 deletions(-) create mode 100644 frontend/src/components/Modal.tsx diff --git a/CLAUDE.md b/CLAUDE.md index 1d3d158..57200e6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2132,6 +2132,18 @@ frontend at `http://localhost:5173`. `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. +- **Every dialog is a ``** (`components/Modal.tsx`; decided 2026-11-02): + the portal, backdrop, `aria-modal`, Esc and outside click in ONE place — + never a hand-rolled backdrop or a per-dialog Esc listener. `onDismiss` is + what the dialog's Cancel / Close (or Hide, while a job runs) does, `null` + while that is unavailable (busy): Esc and the backdrop then do nothing. An + outside click closes only when the press AND the release are both on the + backdrop — a plain `onClick` fires on the common ancestor, so a text + selection dragged out of the dialog closed it. Esc reaches only the TOP + modal (by opening order) and never while a menu is open. `layer="nested"` + = `z-[60]` (a dialog opened from a dialog, QuitGuard). The one exception is + `RelocateDialog`'s `backdropDismiss={false}` (Esc only: "Not now" lasts + until the library is reopened). ## Theme — "dark liquid glass" @@ -2156,7 +2168,7 @@ easy to break: opened far from the cursor. `.glass`'s blur and tint therefore live on its `::after` (z-index -1 under `isolation: isolate`), not on the panel. - **Every overlay renders through `createPortal(…, document.body)`** — all - dialogs, `ContextMenu` and `Toast`. Each `.glass` panel is a stacking context + dialogs (via `Modal`), `ContextMenu` and `Toast`. Each `.glass` panel is a stacking context (`isolation`), so an overlay rendered INSIDE one can never rise above a neighbouring panel, whatever its z-index: New Export (from the sidebar) sat behind the library, and the deck's Auto Hotcues dialog behind both. One diff --git a/frontend/src/components/AddFilesDialog.tsx b/frontend/src/components/AddFilesDialog.tsx index 91ac891..4e031fd 100644 --- a/frontend/src/components/AddFilesDialog.tsx +++ b/frontend/src/components/AddFilesDialog.tsx @@ -1,10 +1,10 @@ -import { createPortal } from 'react-dom' import { useEffect, useRef, useState, type ReactNode } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, isServerPath, type FolderAddPreview, type FolderAddRequest, type JobStatus, type TrackOrigin } from '../api' import { useCaps } from '../lib/capabilities' import { placedAudioSummary } from '../lib/platformCopy' import { FolderPicker } from './FolderPicker' +import { Modal } from './Modal' /** * Add browsed files to the collection — and, optionally, to a playlist or export. @@ -253,7 +253,7 @@ export function AddFilesDialog({ trackIds, target: requested, note, onClose, onD ) - return createPortal( + return ( <> {browsing && ( setBrowsing(false)} /> )} -
+

{title}

@@ -461,9 +458,8 @@ export function AddFilesDialog({ trackIds, target: requested, note, onClose, onD )}
-
- , - document.body, +
+ ) } diff --git a/frontend/src/components/AnalyzeDialog.tsx b/frontend/src/components/AnalyzeDialog.tsx index 854cea4..55c02f0 100644 --- a/frontend/src/components/AnalyzeDialog.tsx +++ b/frontend/src/components/AnalyzeDialog.tsx @@ -1,7 +1,7 @@ -import { createPortal } from 'react-dom' import { useEffect, useState, type ReactNode } from 'react' import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query' import { api, type AnalyzeOptions, type AnalyzePreview, type TrackOrigin } from '../api' +import { Modal } from './Modal' interface Props { /** The selected tracks. */ @@ -100,12 +100,6 @@ export function AnalyzeDialog({ ids, origin, gridWhy, keyWhy, gainWhy, preset, o const nothingTicked = !!what && !(what.bpm || what.grid || what.key || what.loudness || what.gain) const count = nothingTicked ? 0 : (p?.tracks_to_analyze ?? 0) - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && !busy && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [busy, onClose]) - const run = async () => { if (!opts || busy || count === 0) return setBusy(true) @@ -186,13 +180,9 @@ export function AnalyzeDialog({ ids, origin, gridWhy, keyWhy, gainWhy, preset, o if (p.grid_locked) gridLines.push(
{plural(p.grid_locked, 'locked grid')} — skipped
) } - return createPortal( -
!busy && onClose()} - > -
e.stopPropagation()}> + return ( + +
Analyze
{plural(ids.length, 'track')} selected
@@ -265,7 +255,6 @@ export function AnalyzeDialog({ ids, origin, gridWhy, keyWhy, gainWhy, preset, o
-
, - document.body, + ) } diff --git a/frontend/src/components/AppSettings.tsx b/frontend/src/components/AppSettings.tsx index 7d3c4ad..d70830e 100644 --- a/frontend/src/components/AppSettings.tsx +++ b/frontend/src/components/AppSettings.tsx @@ -1,7 +1,7 @@ -import { createPortal } from 'react-dom' import { useEffect, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api } from '../api' +import { Modal } from './Modal' /** * Settings → Konduktor: preferences about the app itself rather than about a @@ -42,12 +42,6 @@ export function AppSettings({ onClose }: { onClose: () => void }) { const levelCeiling = useAppSetting('levelCeiling') const [error, setError] = useState(null) - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose]) - const set = async (patch: Partial) => { setError(null) try { @@ -57,13 +51,9 @@ export function AppSettings({ onClose }: { onClose: () => void }) { } } - return createPortal( -
-
e.stopPropagation()}> + return ( + +

Konduktor settings

-
, - document.body, + ) } diff --git a/frontend/src/components/AutoCueDialog.tsx b/frontend/src/components/AutoCueDialog.tsx index 8206eb2..06e4de2 100644 --- a/frontend/src/components/AutoCueDialog.tsx +++ b/frontend/src/components/AutoCueDialog.tsx @@ -1,4 +1,3 @@ -import { createPortal } from 'react-dom' import { useEffect, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { @@ -10,6 +9,7 @@ import { type Track, } from '../api' import { formatDuration } from '../lib/format' +import { Modal } from './Modal' /** * Auto Hotcues: bind each hotcue slot to a structural event plus an offset in @@ -109,14 +109,6 @@ export function AutoCueDialog(props: Props) { if (rows === null && (prefs.data || prefs.isError)) setRows(loadTemplate(prefs.data, slotCount)) }, [prefs.data, prefs.isError, rows, slotCount]) - useEffect(() => { - const onKey = (e: KeyboardEvent) => { - if (e.key === 'Escape' && !busy) onClose() - } - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [busy, onClose]) - const setRow = (i: number, patch: Partial) => setRows((rs) => rs && rs.map((r, j) => (j === i ? { ...r, ...patch } : r))) const nudge = (i: number, by: number) => @@ -152,11 +144,10 @@ export function AutoCueDialog(props: Props) { } } - return createPortal( -
!busy && onClose()}> + return ( +
e.stopPropagation()} >
Auto Hotcues
@@ -294,7 +285,6 @@ export function AutoCueDialog(props: Props) {
-
, - document.body, + ) } diff --git a/frontend/src/components/ConfirmDialog.tsx b/frontend/src/components/ConfirmDialog.tsx index 4eb9bc6..b1ec4f1 100644 --- a/frontend/src/components/ConfirmDialog.tsx +++ b/frontend/src/components/ConfirmDialog.tsx @@ -1,5 +1,5 @@ -import { createPortal } from 'react-dom' import { useEffect, useState, type ReactNode } from 'react' +import { Modal } from './Modal' export interface ConfirmRequest { title: string @@ -42,7 +42,6 @@ export function ConfirmDialog({ title, body, confirmLabel, tone = 'danger', altL 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)) { @@ -54,16 +53,9 @@ export function ConfirmDialog({ title, body, confirmLabel, tone = 'danger', altL return () => window.removeEventListener('keydown', onKey) }) - return createPortal( -
!busy && onClose()} - > -
e.stopPropagation()} - > + return ( + +
{title}
@@ -101,7 +93,6 @@ export function ConfirmDialog({ title, body, confirmLabel, tone = 'danger', altL
-
, - document.body, + ) } diff --git a/frontend/src/components/ConvertStemsDialog.tsx b/frontend/src/components/ConvertStemsDialog.tsx index f14a676..8f5e235 100644 --- a/frontend/src/components/ConvertStemsDialog.tsx +++ b/frontend/src/components/ConvertStemsDialog.tsx @@ -1,4 +1,3 @@ -import { createPortal } from 'react-dom' import { useEffect, useMemo, useState, type ReactNode } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { @@ -12,6 +11,7 @@ import { import { FolderPicker } from './FolderPicker' import { useServerFolder } from './AddFilesDialog' import { useCaps } from '../lib/capabilities' +import { Modal } from './Modal' /** * Convert to Stems — one dialog (decided, see the stem-conversion discussion @@ -224,7 +224,7 @@ export function ConvertStemsDialog({ trackIds, onClose, onStarted, onDownloading ) const count = trackIds.length - return createPortal( + return ( <> {browsing && opts && ( setBrowsing(false)} /> )} -
e.key === 'Escape' && !starting && onClose()} - > +

@@ -477,8 +473,7 @@ export function ConvertStemsDialog({ trackIds, onClose, onStarted, onDownloading

-
- , - document.body, + + ) } diff --git a/frontend/src/components/EditTagsDialog.tsx b/frontend/src/components/EditTagsDialog.tsx index 0ff4008..227773c 100644 --- a/frontend/src/components/EditTagsDialog.tsx +++ b/frontend/src/components/EditTagsDialog.tsx @@ -1,4 +1,3 @@ -import { createPortal } from 'react-dom' import { useRef, useState } from 'react' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { api, type Track } from '../api' @@ -7,6 +6,7 @@ import { useCaps } from '../lib/capabilities' import { RatingStars } from './RatingStars' import { writeHint } from '../lib/platformCopy' import { invalidateTrackLists } from '../lib/trackQueries' +import { Modal } from './Modal' interface Props { track: Track @@ -96,14 +96,10 @@ export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) { apply.mutate() } - return createPortal( -
+ return ( +
e.stopPropagation()} >
Edit Tags
@@ -240,7 +236,6 @@ export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
-
, - document.body, + ) } diff --git a/frontend/src/components/ExportDialog.tsx b/frontend/src/components/ExportDialog.tsx index 1979069..418a8b3 100644 --- a/frontend/src/components/ExportDialog.tsx +++ b/frontend/src/components/ExportDialog.tsx @@ -1,9 +1,9 @@ -import { createPortal } from 'react-dom' import { useState } from 'react' import { useQuery } from '@tanstack/react-query' import { api, type ExportSet, type LocalLibrary } from '../api' import { localLibraryProblem } from '../lib/platformCopy' import { FolderPicker } from './FolderPicker' +import { Modal } from './Modal' /** * Create or edit an export: its name, its target platforms and where it lands. @@ -119,7 +119,7 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) { } } - return createPortal( + return ( <> {browsing && ( setBrowsing(false)} /> )} -
+

@@ -336,8 +336,7 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {

-
- , - document.body, + + ) } diff --git a/frontend/src/components/ExportRunDialog.tsx b/frontend/src/components/ExportRunDialog.tsx index 236a003..f4c712f 100644 --- a/frontend/src/components/ExportRunDialog.tsx +++ b/frontend/src/components/ExportRunDialog.tsx @@ -1,9 +1,9 @@ -import { createPortal } from 'react-dom' import { useEffect, useRef, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, type ExportPreview, type ExportRunOptions, type ExportSet, type JobStatus, type NormalizeOptions } from '../api' import { FolderPicker } from './FolderPicker' import { LevelInput, useAppSetting } from './AppSettings' +import { Modal } from './Modal' /** * Run an export: confirm what is about to happen, then watch it happen. @@ -175,7 +175,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { : null const blocked = p?.blocked ?? null - return createPortal( + return ( <> {browsing && ( setBrowsing(false)} /> )} -
+

Export “{set.name}”

@@ -472,9 +472,8 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { )}
-
- , - document.body, + + ) } diff --git a/frontend/src/components/FolderPicker.tsx b/frontend/src/components/FolderPicker.tsx index d9db68d..0b874dd 100644 --- a/frontend/src/components/FolderPicker.tsx +++ b/frontend/src/components/FolderPicker.tsx @@ -1,6 +1,6 @@ -import { createPortal } from 'react-dom' import { useState } from 'react' import { FileBrowser, useFsListing, type Listing } from './FileBrowser' +import { Modal } from './Modal' /** * Pick a FOLDER, by browsing. @@ -33,8 +33,8 @@ export function FolderPicker({ value, onChange, onClose, listing = 'host' }: Pro onClose() } - return createPortal( -
+ return ( +

Choose a folder

@@ -84,7 +84,6 @@ export function FolderPicker({ value, onChange, onClose, listing = 'host' }: Pro
-
, - document.body, + ) } diff --git a/frontend/src/components/HistoryPanel.tsx b/frontend/src/components/HistoryPanel.tsx index 88f5da4..53aa99c 100644 --- a/frontend/src/components/HistoryPanel.tsx +++ b/frontend/src/components/HistoryPanel.tsx @@ -1,10 +1,10 @@ -import { createPortal } from 'react-dom' import { useState } from 'react' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { api, type HistoryEntry } from '../api' import { useCaps } from '../lib/capabilities' import { restoreWarning } from '../lib/platformCopy' import type { ToastMsg } from './Toast' +import { Modal } from './Modal' interface Props { onClose: () => void @@ -79,14 +79,10 @@ export function HistoryPanel({ onClose, onNotify, onError }: Props) { const entries = history.data ?? [] - return createPortal( -
+ return ( +
e.stopPropagation()} >
Version History
@@ -208,7 +204,6 @@ export function HistoryPanel({ onClose, onNotify, onError }: Props) { )}
-
, - document.body, + ) } diff --git a/frontend/src/components/ImportDialog.tsx b/frontend/src/components/ImportDialog.tsx index 87cc1e2..2963168 100644 --- a/frontend/src/components/ImportDialog.tsx +++ b/frontend/src/components/ImportDialog.tsx @@ -1,4 +1,3 @@ -import { createPortal } from 'react-dom' import { useEffect, useRef, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, type ImportPreview, type JobStatus } from '../api' @@ -7,6 +6,7 @@ import { placedAudioSummary } from '../lib/platformCopy' import type { AddTarget } from './AddFilesDialog' import { FolderPicker } from './FolderPicker' import { useServerImportFolder, usePlaylistToggle } from './AddFilesDialog' +import { Modal } from './Modal' /** * Import a browsed device into the loaded collection. @@ -173,7 +173,7 @@ export function ImportDialog({ playlistId, trackIds, target: requested, deviceLa const finished = job != null && job.state !== 'running' const pct = job && job.total > 0 ? Math.min(100, (job.done / job.total) * 100) : null - return createPortal( + return ( <> {browsing && ( setBrowsing(false)} /> )} -
+

@@ -373,8 +373,7 @@ export function ImportDialog({ playlistId, trackIds, target: requested, deviceLa )}

-
- , - document.body, + + ) } diff --git a/frontend/src/components/LocalLibrariesSettings.tsx b/frontend/src/components/LocalLibrariesSettings.tsx index f7a1496..0a34f64 100644 --- a/frontend/src/components/LocalLibrariesSettings.tsx +++ b/frontend/src/components/LocalLibrariesSettings.tsx @@ -1,10 +1,10 @@ -import { createPortal } from 'react-dom' -import { useEffect, useState } from 'react' +import { useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, type NormalizeOptions } from '../api' import { localLibraryProblem } from '../lib/platformCopy' import { FolderPicker } from './FolderPicker' import { LevelInput, useAppSetting } from './AppSettings' +import { Modal } from './Modal' /** * Settings → Local libraries: where a "This computer" set is pushed. @@ -32,12 +32,6 @@ export function LocalLibrariesSettings({ onClose }: { onClose: () => void }) { const [picking, setPicking] = useState(null) // a platform, or 'audio' const [error, setError] = useState(null) - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && !picking && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose, picking]) - const p = prefs.data ?? {} const overrides = (p.localLibraries as Record | undefined) ?? {} const normalise = p.localNormalise === true @@ -74,17 +68,13 @@ export function LocalLibrariesSettings({ onClose }: { onClose: () => void }) { ? d?.audio_root ?? '' : (d?.libraries.find((l) => l.platform === picking)?.path ?? '').replace(/[\\/][^\\/]*$/, '') - return createPortal( + return ( <> {picking && ( setPicking(null)} /> )} -
-
e.stopPropagation()}> + +

Local libraries

-
- , - document.body, + + ) } diff --git a/frontend/src/components/Modal.tsx b/frontend/src/components/Modal.tsx new file mode 100644 index 0000000..0749fff --- /dev/null +++ b/frontend/src/components/Modal.tsx @@ -0,0 +1,97 @@ +import { createPortal } from 'react-dom' +import { useEffect, useRef, useState, type AriaRole, type ReactNode } from 'react' + +// Open modals by opening order (taken at first render, so a dialog opened +// from another always ranks above it). Esc is answered by the top one only. +const open = new Set() +let opened = 0 + +const menuOpen = () => document.querySelector('[role="menu"]') != null + +interface Props { + /** What Esc and a click on the backdrop do: the dialog's Cancel / Close. + * `null` while that is not available (a run in progress), so neither + * can close the dialog when its own Cancel could not. */ + onDismiss: (() => void) | null + /** `false`: Esc only. For a dialog whose dismissal decides something a + * stray click should not (RelocateDialog). */ + backdropDismiss?: boolean + /** `nested` for a dialog opened from a dialog or above every other one. */ + layer?: 'dialog' | 'nested' + /** The backdrop's padding (default `p-6`). */ + padding?: string + role?: AriaRole + 'aria-label'?: string + 'aria-labelledby'?: string + children: ReactNode +} + +/** The ONE modal container: portal, dimmed backdrop, Esc and outside click. + * + * An outside click closes only when the press AND the release are both on + * the backdrop. A `click` alone fires on the nearest common ancestor, so a + * text selection started inside the dialog and released outside it used to + * land on the backdrop and close the dialog. */ +export function Modal({ + onDismiss, + backdropDismiss = true, + layer = 'dialog', + padding = 'p-6', + role, + children, + ...aria +}: Props) { + const [id] = useState(() => ++opened) + const dismissRef = useRef(onDismiss) + dismissRef.current = onDismiss + + useEffect(() => { + open.add(id) + const onKey = (e: KeyboardEvent) => { + if (e.key !== 'Escape' || e.defaultPrevented) return + if (id !== Math.max(...open)) return + // A menu over the dialog closes itself on Esc; the dialog stays. + if (menuOpen()) return + const dismiss = dismissRef.current + if (!dismiss) return + e.preventDefault() + dismiss() + } + window.addEventListener('keydown', onKey) + return () => { + open.delete(id) + window.removeEventListener('keydown', onKey) + } + }, [id]) + + const pressed = useRef(false) + const released = useRef(false) + + return createPortal( +
{ + // A press that closes an open menu closes only the menu. + pressed.current = e.target === e.currentTarget && e.button === 0 && !menuOpen() + released.current = false + }} + onPointerUp={(e) => { + released.current = e.target === e.currentTarget + }} + onClick={(e) => { + const outside = pressed.current && released.current && e.target === e.currentTarget + pressed.current = released.current = false + if (outside && backdropDismiss) dismissRef.current?.() + }} + > + {children} +
, + document.body, + ) +} diff --git a/frontend/src/components/NormalizeDialog.tsx b/frontend/src/components/NormalizeDialog.tsx index 747c4f0..dd63fd2 100644 --- a/frontend/src/components/NormalizeDialog.tsx +++ b/frontend/src/components/NormalizeDialog.tsx @@ -1,9 +1,9 @@ -import { createPortal } from 'react-dom' import { useEffect, useMemo, useState } from 'react' import { keepPreviousData, useQuery } from '@tanstack/react-query' import { api, type NormalizeOptions, type NormalizePreview, type NormalizeRow } from '../api' import { LevelInput, useAppSetting } from './AppSettings' import { Icon } from '../lib/icons' +import { Modal } from './Modal' interface Props { ids: string[] @@ -58,12 +58,6 @@ export function NormalizeDialog({ ids, onRun, onClose, onError }: Props) { const p: NormalizePreview | undefined = preview.data const count = p?.tracks_to_process ?? 0 - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && !busy && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [busy, onClose]) - const summary = useMemo(() => { if (!p) return [] const rows = p.rows @@ -105,13 +99,9 @@ export function NormalizeDialog({ ids, onRun, onClose, onError }: Props) { const measureUnit = opts?.measure === 'rms' ? 'dB' : 'LUFS' - return createPortal( -
!busy && onClose()} - > -
e.stopPropagation()}> + return ( + +
Normalize
@@ -198,7 +188,6 @@ export function NormalizeDialog({ ids, onRun, onClose, onError }: Props) {
-
, - document.body, +
) } diff --git a/frontend/src/components/PathMappingDialog.tsx b/frontend/src/components/PathMappingDialog.tsx index 234ee1f..e5a9eba 100644 --- a/frontend/src/components/PathMappingDialog.tsx +++ b/frontend/src/components/PathMappingDialog.tsx @@ -1,10 +1,10 @@ -import { createPortal } from 'react-dom' import { useEffect, useRef, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, type RemapPreview } from '../api' import type { ToastMsg } from './Toast' import { Icon } from '../lib/icons' import { invalidateTrackLists } from '../lib/trackQueries' +import { Modal } from './Modal' interface Props { onClose: () => void @@ -107,14 +107,10 @@ export function PathMappingDialog({ onClose, onNotify, onError }: Props) { const collides = (preview?.collisions ?? 0) > 0 const canCommit = !!from.trim() && !!to.trim() && !collides - return createPortal( -
+ return ( +
e.stopPropagation()} >
Path Remapping
@@ -264,8 +260,7 @@ export function PathMappingDialog({ onClose, onNotify, onError }: Props) {
-
, - document.body, + ) } diff --git a/frontend/src/components/PushRunDialog.tsx b/frontend/src/components/PushRunDialog.tsx index e5113c0..f094a0b 100644 --- a/frontend/src/components/PushRunDialog.tsx +++ b/frontend/src/components/PushRunDialog.tsx @@ -1,9 +1,9 @@ -import { createPortal } from 'react-dom' import { useEffect, useRef, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, type ExportRunOptions, type ExportSet, type JobStatus, type PushPreview, type PushTarget } from '../api' import { askConfirm } from '../lib/confirm' import { localLibraryProblem } from '../lib/platformCopy' +import { Modal } from './Modal' /** * Push a "computer" set into this computer's Traktor / rekordbox: confirm what @@ -136,8 +136,8 @@ export function PushRunDialog({ set, onClose, onDone, onError }: Props) { job?.state === 'done' ? 100 : job && job.total > 0 ? Math.min(100, (job.done / job.total) * 100) : null const results = ((job?.result as { targets?: TargetResult[] } | null)?.targets ?? []) - return createPortal( -
+ return ( +

@@ -323,8 +323,7 @@ export function PushRunDialog({ set, onClose, onDone, onError }: Props) { )}

-
, - document.body, + ) } diff --git a/frontend/src/components/QuitGuard.tsx b/frontend/src/components/QuitGuard.tsx index 982b6c2..f8ebe52 100644 --- a/frontend/src/components/QuitGuard.tsx +++ b/frontend/src/components/QuitGuard.tsx @@ -1,8 +1,8 @@ -import { createPortal } from 'react-dom' import { useEffect, useRef, useState } from 'react' import { useQuery } from '@tanstack/react-query' import { api } from '../api' import { flushPrefs } from '../lib/prefs' +import { Modal } from './Modal' /** * Ask before quitting with unsaved changes: Save · Discard · Cancel. @@ -99,21 +99,9 @@ export function QuitGuard() { } } - useEffect(() => { - if (!asking) return - const onKey = (e: KeyboardEvent) => { - if (e.key === 'Escape' && !busy) void cancel() - } - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }) - if (!asking) return null - return createPortal( -
+ return ( + void cancel()} layer="nested">
Save changes before quitting? @@ -147,7 +135,6 @@ export function QuitGuard() {
-
, - document.body, + ) } diff --git a/frontend/src/components/RelocateDialog.tsx b/frontend/src/components/RelocateDialog.tsx index d26b425..d454a75 100644 --- a/frontend/src/components/RelocateDialog.tsx +++ b/frontend/src/components/RelocateDialog.tsx @@ -1,6 +1,6 @@ -import { createPortal } from 'react-dom' -import { useEffect, useState } from 'react' +import { useState } from 'react' import { api, type PathMapping, type RelocationVolume } from '../api' +import { Modal } from './Modal' interface Props { volumes: RelocationVolume[] @@ -51,21 +51,12 @@ export function RelocateDialog({ volumes, onAnswered, onOpenManual, onError }: P } } - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && !busy && answer([]) - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }) - const set = (root: string, to: string | null) => setChoice((c) => ({ ...c, [root]: to })) - return createPortal( - // No close on a backdrop click: dismissing lasts until the library is - // reopened, which is too much for a stray click to decide. -
+ return ( + // Esc is "Not now", but a backdrop click is not: dismissing lasts until + // the library is reopened, which is too much for a stray click to decide. + void answer([])} backdropDismiss={false}>
Tracks not found
@@ -116,8 +107,7 @@ export function RelocateDialog({ volumes, onAnswered, onOpenManual, onError }: P
-
, - document.body, + ) } diff --git a/frontend/src/components/RemoteCacheSettings.tsx b/frontend/src/components/RemoteCacheSettings.tsx index ce8d8b1..c4b8185 100644 --- a/frontend/src/components/RemoteCacheSettings.tsx +++ b/frontend/src/components/RemoteCacheSettings.tsx @@ -1,8 +1,8 @@ -import { createPortal } from 'react-dom' -import { useEffect, useState } from 'react' +import { useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api } from '../api' import { size } from './ConvertStemsDialog' +import { Modal } from './Modal' /** * Settings → Remote audio: this computer's copies of a remote library's audio. @@ -21,12 +21,6 @@ export function RemoteCacheSettings({ onClose }: { onClose: () => void }) { const [busy, setBusy] = useState(false) const [error, setError] = useState(null) - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose]) - const u = usage.data const capGb = u ? Math.round(u.cap / 1024 ** 3) : null @@ -54,13 +48,9 @@ export function RemoteCacheSettings({ onClose }: { onClose: () => void }) { } } - return createPortal( -
-
e.stopPropagation()}> + return ( + +

Remote audio

-
, - document.body, + ) } diff --git a/frontend/src/components/RemotePicker.tsx b/frontend/src/components/RemotePicker.tsx index b1d8762..f786cca 100644 --- a/frontend/src/components/RemotePicker.tsx +++ b/frontend/src/components/RemotePicker.tsx @@ -1,5 +1,4 @@ import { useState, type ReactNode } from 'react' -import { createPortal } from 'react-dom' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, @@ -14,6 +13,7 @@ import { import { askConfirm } from '../lib/confirm' import { Icon } from '../lib/icons' import { remoteHolder } from '../lib/platformCopy' +import { Modal } from './Modal' import { OptionCard } from './OptionCard' /** @@ -329,12 +329,8 @@ function PendingEditsDialog({ setBusy(false) } } - return createPortal( -
e.key === 'Escape' && !busy && void choose('later')} - > + return ( + void choose('later')}>
Unsaved edits from {edits.machine || 'another computer'} @@ -369,7 +365,6 @@ function PendingEditsDialog({
-
, - document.body, + ) } diff --git a/frontend/src/components/SetPositionDialog.tsx b/frontend/src/components/SetPositionDialog.tsx index 2fef983..e25d704 100644 --- a/frontend/src/components/SetPositionDialog.tsx +++ b/frontend/src/components/SetPositionDialog.tsx @@ -1,8 +1,8 @@ -import { createPortal } from 'react-dom' import { useEffect, useRef, useState, type ReactNode } from 'react' import type { SortingState } from '@tanstack/react-table' import { maxPosition, moveToPosition } from '../lib/playlistOrder' import { COLUMN_MENU } from '../lib/trackColumns' +import { Modal } from './Modal' interface Props { /** The playlist's full entry order — never the sorted or filtered view, so @@ -50,14 +50,6 @@ export function SetPositionDialog({ order, ids, sorting, onMove, onClose }: Prop onClose() } - useEffect(() => { - const onKey = (e: KeyboardEvent) => { - if (e.key === 'Escape') onClose() - } - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose]) - const option = (value: 'playlist' | 'sorted', label: string, detail: ReactNode) => (
, - document.body, + ) } diff --git a/frontend/src/components/ShortcutsDialog.tsx b/frontend/src/components/ShortcutsDialog.tsx index d16cbc0..04f1b8c 100644 --- a/frontend/src/components/ShortcutsDialog.tsx +++ b/frontend/src/components/ShortcutsDialog.tsx @@ -1,4 +1,3 @@ -import { createPortal } from 'react-dom' import { useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react' import { useCaps } from '../lib/capabilities' import { Icon } from '../lib/icons' @@ -24,6 +23,7 @@ import { type Layer, type MouseGesture, } from '../lib/shortcuts' +import { Modal } from './Modal' interface Props { onClose: () => void @@ -162,15 +162,10 @@ export function ShortcutsDialog({ onClose }: Props) { onPick: pickLayer, } - return createPortal( -
+ return ( +
e.stopPropagation()} >
Keyboard Shortcuts
@@ -309,8 +304,7 @@ export function ShortcutsDialog({ onClose }: Props) {
-
, - document.body, + ) } diff --git a/frontend/src/components/StemReportDialog.tsx b/frontend/src/components/StemReportDialog.tsx index b1bc7a5..22e52f3 100644 --- a/frontend/src/components/StemReportDialog.tsx +++ b/frontend/src/components/StemReportDialog.tsx @@ -1,6 +1,5 @@ -import { createPortal } from 'react-dom' -import { useEffect } from 'react' import type { StemBatchResult } from '../api' +import { Modal } from './Modal' /** * The Details behind a finished conversion's toast: every track that was @@ -8,24 +7,14 @@ import type { StemBatchResult } from '../api' * into a toast). */ export function StemReportDialog({ result, onClose }: { result: StemBatchResult; onClose: () => void }) { - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose]) - const rows = [ ...result.failed.map((s) => ({ ...s, failed: true })), ...result.skipped.map((s) => ({ ...s, failed: false })), ] const n = result.converted.length - return createPortal( -
-
e.stopPropagation()}> + return ( + +
{n} converted to stems · {result.skipped.length} skipped · {result.failed.length} failed
@@ -49,7 +38,6 @@ export function StemReportDialog({ result, onClose }: { result: StemBatchResult;
-
, - document.body, + ) } diff --git a/frontend/src/components/StemsSettings.tsx b/frontend/src/components/StemsSettings.tsx index 4c00385..c9dc39f 100644 --- a/frontend/src/components/StemsSettings.tsx +++ b/frontend/src/components/StemsSettings.tsx @@ -1,10 +1,10 @@ -import { createPortal } from 'react-dom' import { useEffect, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, type StemTarget } from '../api' import { askConfirm } from '../lib/confirm' import { FolderPicker } from './FolderPicker' import { size } from './ConvertStemsDialog' +import { Modal } from './Modal' /** * Settings → Stems (decided contents): the engine (status, download, install @@ -40,12 +40,6 @@ export function StemsSettings({ onClose }: Props) { } }, [install.data, qc]) - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && !picking && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose, picking]) - const act = async (fn: () => Promise) => { setBusy(true) setError(null) @@ -72,7 +66,7 @@ export function StemsSettings({ onClose }: Props) { const targetLabel = (t: StemTarget) => t === 'macos-arm64' ? 'Apple silicon (GPU)' : t === 'windows-x64-cuda' ? 'NVIDIA GPU' : 'processor only' - return createPortal( + return ( <> {picking && ( setPicking(null)} /> )} -
+
e.stopPropagation()} >

Stems

@@ -241,8 +230,7 @@ export function StemsSettings({ onClose }: Props) { {error &&
{error}
}
-
- , - document.body, + + ) } diff --git a/frontend/src/components/TrackInfoDialog.tsx b/frontend/src/components/TrackInfoDialog.tsx index 26f8b0f..5cb0d27 100644 --- a/frontend/src/components/TrackInfoDialog.tsx +++ b/frontend/src/components/TrackInfoDialog.tsx @@ -1,10 +1,10 @@ -import { createPortal } from 'react-dom' -import { useEffect, useState, type ReactNode } from 'react' +import { useState, type ReactNode } from 'react' import type { Track } from '../api' import { formatBpm, formatDuration, keyColor } from '../lib/format' import { useCaps } from '../lib/capabilities' import { Icon } from '../lib/icons' import { RatingStars } from './RatingStars' +import { Modal } from './Modal' interface Props { track: Track @@ -27,12 +27,6 @@ export function TrackInfoDialog({ track, artUrl, onClose, onEditTags }: Props) { const [artFailed, setArtFailed] = useState(false) const showArt = artUrl != null && !artFailed - useEffect(() => { - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose]) - const grid = track.grid_marker_count === 0 ? null @@ -60,17 +54,10 @@ export function TrackInfoDialog({ track, artUrl, onClose, onEditTags }: Props) { ] as [string, ReactNode][] ).filter(([, v]) => v != null && v !== '') - return createPortal( -
+ return ( +
e.stopPropagation()} > {/* The sleeve, bled into the card behind everything: a soft wash of the art's own colours. `filter` on this leaf is safe — nothing can open @@ -166,8 +153,7 @@ export function TrackInfoDialog({ track, artUrl, onClose, onEditTags }: Props) { )}
-
, - document.body, + ) } diff --git a/frontend/src/components/UpdateDialog.tsx b/frontend/src/components/UpdateDialog.tsx index 133ef25..5978dac 100644 --- a/frontend/src/components/UpdateDialog.tsx +++ b/frontend/src/components/UpdateDialog.tsx @@ -1,7 +1,7 @@ -import { createPortal } from 'react-dom' import { useEffect, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api } from '../api' +import { Modal } from './Modal' /** * Startup update check against GitHub Releases. @@ -285,14 +285,10 @@ export function UpdateCheck() { const sections = newer.map((r) => ({ tag: r.tag_name, changes: whatsChanged(r.body) })) const grouped = sections.length > 1 - return createPortal( -
+ return ( +
e.stopPropagation()} >
{title}
@@ -418,7 +414,6 @@ export function UpdateCheck() { )}
-
, - document.body, + ) }