diff --git a/frontend/src/components/ExportRunDialog.tsx b/frontend/src/components/ExportRunDialog.tsx index 53a2de3..0aae192 100644 --- a/frontend/src/components/ExportRunDialog.tsx +++ b/frontend/src/components/ExportRunDialog.tsx @@ -2,6 +2,7 @@ import { createPortal } from 'react-dom' import { useEffect, useRef, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { api, type ExportPreview, type ExportSet, type JobStatus } from '../api' +import { FolderPicker } from './FolderPicker' /** * Run an export: confirm what is about to happen, then watch it happen. @@ -15,6 +16,12 @@ import { api, type ExportPreview, type ExportSet, type JobStatus } from '../api' * folder Konduktor did not write is REFUSED rather than confirmed. There is no * "do it anyway" — the whole point is that Konduktor never deletes what it did * not put there. + * + * The destination can be changed HERE, without going back to Edit: a wrong + * folder is usually noticed at this last look. The change is SAVED on the set, + * not used for this run only — a set is bound to its destination, and a run + * somewhere the set does not know would leave its next export (and the + * incremental re-export's manifest) pointing at the old folder. */ const POLL_MS = 300 @@ -40,6 +47,11 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { // starts from the same answer. Older sets without it read as on. const [lockGrids, setLockGrids] = useState(set.lock_grids ?? true) const pollRef = useRef(null) + // The set as last saved from here: `set` is a snapshot, and a destination + // changed in this dialog must reach the preview and the run. + const [current, setCurrent] = useState(set) + const [browsing, setBrowsing] = useState(false) + const [moving, setMoving] = useState(false) // Platform names for wording the facts the preview and result carry as ids. const platforms = useQuery({ queryKey: ['export-targets'], queryFn: api.exportTargets }) @@ -50,7 +62,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { ) const preview = useQuery({ - queryKey: ['export-preview', set.id], + queryKey: ['export-preview', set.id, current.destination], queryFn: () => api.exportPreview(set.id), enabled: !job, staleTime: 0, @@ -87,6 +99,28 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { } }, [job, qc, set.id, onDone, onError]) + // Another set writing here would have its output replaced — the same warning + // the Edit dialog gives, since a folder can now be chosen here too. + const conflict = useQuery({ + queryKey: ['export-conflict', set.id, current.destination], + queryFn: () => api.exportContents(set.id), + enabled: !job, + }).data?.destination_conflict + + const changeDestination = async (destination: string) => { + if (destination === current.destination) return + setMoving(true) + try { + setCurrent(await api.updateExport(set.id, { destination })) + qc.invalidateQueries({ queryKey: ['exports'] }) + qc.invalidateQueries({ queryKey: ['export-contents', set.id] }) + } catch (e) { + onError((e as Error).message) + } finally { + setMoving(false) + } + } + const start = async () => { setStarting(true) try { @@ -122,212 +156,236 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) { const blocked = p?.blocked ?? null return createPortal( -
-
-
-

Export “{set.name}”

-
+ <> + {browsing && ( + setBrowsing(false)} + /> + )} +
+
+
+

Export “{set.name}”

+
-
- {!job && ( - <> -
- To -
- {set.destination} -
-
- - {preview.isLoading &&
Checking…
} - {preview.isError && ( -
{(preview.error as Error).message}
- )} - - {p && !blocked && ( -
-
- {p.exportable} track{p.exportable === 1 ? '' : 's'} - {p.playlists.length > 0 && - ` · ${p.playlists.length} playlist${p.playlists.length === 1 ? '' : 's'}`} - - {p.unchanged > 0 && ` · ${p.unchanged} unchanged`} · {gb(p.total_bytes)} to copy - +
+ {!job && ( + <> +
+ To +
+
+ {current.destination} +
+
- {p.free_bytes != null && ( -
- {gb(p.free_bytes)} free - {p.enough_space === false && ' — not enough space'} + {conflict && ( +
+ “{conflict}” already exports here. Exporting replaces whatever the other one + wrote.
)} - {/* Reported and skipped, not a failure halfway through a long - copy. A gig stick short four tracks must never be silent. */} - {p.missing.length > 0 && ( -
- {p.missing.length} track{p.missing.length === 1 ? '' : 's'} will be skipped — - the audio file is not on this disk: -
{p.missing.slice(0, 4).join(', ')}
-
- )} - {p.replacing && ( -
- This folder already holds an export. Tracks that haven’t changed are kept; everything else is replaced. -
- )} - {/* A warning, not a block: the other targets are fine anywhere, - and staging a stick's contents in a folder is legitimate. */} - {p.not_drive_root.length > 0 && ( -
- {p.not_drive_root.map(nameOf).join(' and ')} is only found at the top of a - drive, and this folder isn’t one — players won’t see it unless you move the - folder’s contents to a drive’s top level. -
- )} - {lockable && ( -
+ + {preview.isLoading &&
Checking…
} + {preview.isError && ( +
{(preview.error as Error).message}
+ )} + + {p && !blocked && ( +
+
+ {p.exportable} track{p.exportable === 1 ? '' : 's'} + {p.playlists.length > 0 && + ` · ${p.playlists.length} playlist${p.playlists.length === 1 ? '' : 's'}`} + + {p.unchanged > 0 && ` · ${p.unchanged} unchanged`} · {gb(p.total_bytes)} to copy - - )} -
- Writes a library for {set.targets.map(nameOf).join(' and ')}, sharing one copy - of every track under Contents/, in your own - folder structure. -
-
- )} - - {blocked === 'destination_not_empty' && ( -
- That folder already has files in it that Konduktor didn’t put there. An export - replaces what it wrote last time, so it will only write into an empty folder or - one of its own. Edit the export and choose somewhere else. -
- )} - {blocked === 'nothing_to_export' && p && p.tracks === 0 && ( -
- There’s nothing to export yet — add some tracks or a playlist. -
- )} - {/* Tracks exist but none of their audio does: saying "nothing to - export" here sends the user looking in the wrong place. */} - {blocked === 'nothing_to_export' && p && p.tracks > 0 && ( -
- None of the {p.tracks} track{p.tracks === 1 ? '' : 's'} can be exported — their - audio files are not on this disk: -
{p.missing.slice(0, 4).join(', ')}
-
- )} - {blocked === 'unsupported_target' && ( -
- Konduktor can’t write that kind of library yet. -
- )} - - )} - - {job && ( -
-
- {job.state === 'done' ? finishedLine(job.result) : job.message || 'Working…'} -
-
-
-
- {/* Tracks say their count in the message ("Analysing … (12/207)"). */} - {pct != null && running && job.unit === 'bytes' && ( -
- {gb(job.done)} of {gb(job.total)} -
- )} - {job.state === 'cancelled' && ( -
- Cancelled. Everything this export copied was removed, and no library was - written. -
- )} - {job.state === 'failed' && ( -
- {job.error} — nothing was left behind: no audio, and no library for any platform. -
- )} - {job.state === 'done' && ( -
-
Done — the folder is ready.
- {( - (job.result as { libraries?: { platform: string; library: string }[] } | null) - ?.libraries ?? [] - ).map((l) => ( -
- {nameOf(l.platform)}: {l.library}
- ))} -
- )} -
- )} -
+ {p.free_bytes != null && ( +
+ {gb(p.free_bytes)} free + {p.enough_space === false && ' — not enough space'} +
+ )} + {/* Reported and skipped, not a failure halfway through a long + copy. A gig stick short four tracks must never be silent. */} + {p.missing.length > 0 && ( +
+ {p.missing.length} track{p.missing.length === 1 ? '' : 's'} will be skipped — + the audio file is not on this disk: +
{p.missing.slice(0, 4).join(', ')}
+
+ )} + {p.replacing && ( +
+ This folder already holds an export. Tracks that haven’t changed are kept; everything else is replaced. +
+ )} + {/* A warning, not a block: the other targets are fine anywhere, + and staging a stick's contents in a folder is legitimate. */} + {p.not_drive_root.length > 0 && ( +
+ {p.not_drive_root.map(nameOf).join(' and ')} is only found at the top of a + drive, and this folder isn’t one — players won’t see it unless you move the + folder’s contents to a drive’s top level. +
+ )} + {lockable && ( + + )} +
+ Writes a library for {set.targets.map(nameOf).join(' and ')}, sharing one copy + of every track under Contents/, in your own + folder structure. +
+
+ )} -
- {running ? ( - <> - - - - ) : ( - <> - - {!finished && ( + {blocked === 'destination_not_empty' && ( +
+ That folder already has files in it that Konduktor didn’t put there. An export + replaces what it wrote last time, so it will only write into an empty folder or + one of its own. Choose another folder. +
+ )} + {blocked === 'nothing_to_export' && p && p.tracks === 0 && ( +
+ There’s nothing to export yet — add some tracks or a playlist. +
+ )} + {/* Tracks exist but none of their audio does: saying "nothing to + export" here sends the user looking in the wrong place. */} + {blocked === 'nothing_to_export' && p && p.tracks > 0 && ( +
+ None of the {p.tracks} track{p.tracks === 1 ? '' : 's'} can be exported — their + audio files are not on this disk: +
{p.missing.slice(0, 4).join(', ')}
+
+ )} + {blocked === 'unsupported_target' && ( +
+ Konduktor can’t write that kind of library yet. +
+ )} + + )} + + {job && ( +
+
+ {job.state === 'done' ? finishedLine(job.result) : job.message || 'Working…'} +
+
+
+
+ {/* Tracks say their count in the message ("Analysing … (12/207)"). */} + {pct != null && running && job.unit === 'bytes' && ( +
+ {gb(job.done)} of {gb(job.total)} +
+ )} + {job.state === 'cancelled' && ( +
+ Cancelled. Everything this export copied was removed, and no library was + written. +
+ )} + {job.state === 'failed' && ( +
+ {job.error} — nothing was left behind: no audio, and no library for any platform. +
+ )} + {job.state === 'done' && ( +
+
Done — the folder is ready.
+ {( + (job.result as { libraries?: { platform: string; library: string }[] } | null) + ?.libraries ?? [] + ).map((l) => ( +
+ {nameOf(l.platform)}: {l.library} +
+ ))} +
+ )} +
+ )} +
+ +
+ {running ? ( + <> - )} - - )} + + + ) : ( + <> + + {!finished && ( + + )} + + )} +
-
, + , document.body, ) }