Added quick target location change button in export dialog

This commit is contained in:
patben8 committed 2026-10-19 11:33:23 +02:00
1 parent 9329236955
commit 5c9387f136
1 file changed
+253 -195
+253 -195
View File
@@ -2,6 +2,7 @@ import { createPortal } from 'react-dom'
import { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query' import { useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type ExportPreview, type ExportSet, type JobStatus } from '../api' 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. * 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 * 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 * "do it anyway" — the whole point is that Konduktor never deletes what it did
* not put there. * 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 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. // starts from the same answer. Older sets without it read as on.
const [lockGrids, setLockGrids] = useState(set.lock_grids ?? true) const [lockGrids, setLockGrids] = useState(set.lock_grids ?? true)
const pollRef = useRef<number | null>(null) const pollRef = useRef<number | null>(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. // Platform names for wording the facts the preview and result carry as ids.
const platforms = useQuery({ queryKey: ['export-targets'], queryFn: api.exportTargets }) const platforms = useQuery({ queryKey: ['export-targets'], queryFn: api.exportTargets })
@@ -50,7 +62,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
) )
const preview = useQuery<ExportPreview>({ const preview = useQuery<ExportPreview>({
queryKey: ['export-preview', set.id], queryKey: ['export-preview', set.id, current.destination],
queryFn: () => api.exportPreview(set.id), queryFn: () => api.exportPreview(set.id),
enabled: !job, enabled: !job,
staleTime: 0, staleTime: 0,
@@ -87,6 +99,28 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
} }
}, [job, qc, set.id, onDone, onError]) }, [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 () => { const start = async () => {
setStarting(true) setStarting(true)
try { try {
@@ -122,212 +156,236 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
const blocked = p?.blocked ?? null const blocked = p?.blocked ?? null
return createPortal( return createPortal(
<div aria-modal="true" className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-[3px] p-4"> <>
<div className="w-full max-w-lg glass-overlay"> {browsing && (
<div className="border-b border-line px-5 py-3"> <FolderPicker
<h2 className="text-sm font-semibold text-text">Export “{set.name}”</h2> value={current.destination}
</div> onChange={changeDestination}
onClose={() => setBrowsing(false)}
/>
)}
<div aria-modal="true" className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-[3px] p-4">
<div className="w-full max-w-lg glass-overlay">
<div className="border-b border-line px-5 py-3">
<h2 className="text-sm font-semibold text-text">Export “{set.name}”</h2>
</div>
<div className="space-y-4 px-5 py-4 text-sm"> <div className="space-y-4 px-5 py-4 text-sm">
{!job && ( {!job && (
<> <>
<div> <div>
<span className="mb-1 block text-xs text-muted">To</span> <span className="mb-1 block text-xs text-muted">To</span>
<div <div className="flex items-center gap-2">
dir="rtl" <div
title={set.destination} dir="rtl"
className="truncate rounded-md well px-2 py-1.5 font-mono text-xs text-text" title={current.destination}
> className="min-w-0 flex-1 truncate rounded-md well px-2 py-1.5 font-mono text-xs text-text"
{set.destination} >
</div> {current.destination}
</div> </div>
<button
{preview.isLoading && <div className="text-faint">Checking…</div>} onClick={() => setBrowsing(true)}
{preview.isError && ( disabled={moving || starting}
<div className="text-pink">{(preview.error as Error).message}</div> className="shrink-0 btn-glass rounded-full px-3 py-1 text-xs text-muted hover:text-text disabled:opacity-40"
)} >
{moving ? 'Saving…' : 'Change…'}
{p && !blocked && ( </button>
<div className="space-y-2">
<div className="text-text">
{p.exportable} track{p.exportable === 1 ? '' : 's'}
{p.playlists.length > 0 &&
` · ${p.playlists.length} playlist${p.playlists.length === 1 ? '' : 's'}`}
<span className="text-muted">
{p.unchanged > 0 && ` · ${p.unchanged} unchanged`} · {gb(p.total_bytes)} to copy
</span>
</div> </div>
{p.free_bytes != null && ( {conflict && (
<div className={p.enough_space === false ? 'text-pink' : 'text-faint'}> <div className="mt-2 rounded well px-3 py-2 text-xs text-gold">
{gb(p.free_bytes)} free “{conflict}” already exports here. Exporting replaces whatever the other one
{p.enough_space === false && ' — not enough space'} wrote.
</div> </div>
)} )}
{/* Reported and skipped, not a failure halfway through a long </div>
copy. A gig stick short four tracks must never be silent. */}
{p.missing.length > 0 && ( {preview.isLoading && <div className="text-faint">Checking…</div>}
<div className="rounded well px-3 py-2 text-xs text-pink"> {preview.isError && (
{p.missing.length} track{p.missing.length === 1 ? '' : 's'} will be skipped — <div className="text-pink">{(preview.error as Error).message}</div>
the audio file is not on this disk: )}
<div className="mt-1 text-faint">{p.missing.slice(0, 4).join(', ')}</div>
</div> {p && !blocked && (
)} <div className="space-y-2">
{p.replacing && ( <div className="text-text">
<div className="rounded well px-3 py-2 text-xs text-gold"> {p.exportable} track{p.exportable === 1 ? '' : 's'}
This folder already holds an export. Tracks that haven’t changed are kept; everything else is replaced. {p.playlists.length > 0 &&
</div> ` · ${p.playlists.length} playlist${p.playlists.length === 1 ? '' : 's'}`}
)} <span className="text-muted">
{/* A warning, not a block: the other targets are fine anywhere, {p.unchanged > 0 && ` · ${p.unchanged} unchanged`} · {gb(p.total_bytes)} to copy
and staging a stick's contents in a folder is legitimate. */}
{p.not_drive_root.length > 0 && (
<div className="rounded well px-3 py-2 text-xs text-gold">
{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.
</div>
)}
{lockable && (
<label className="flex cursor-pointer items-start gap-2.5">
<input
type="checkbox"
className="mt-0.5"
checked={lockGrids}
onChange={(e) => setLockGrids(e.target.checked)}
/>
<span className="min-w-0">
<span className="block text-sm text-text">Lock beatgrids</span>
<span className="block text-xs text-faint">
Stops tracks being re-analysed when they’re loaded, which can change the
BPM or move the grid.
</span>
</span> </span>
</label>
)}
<div className="text-xs text-faint">
Writes a library for {set.targets.map(nameOf).join(' and ')}, sharing one copy
of every track under <span className="font-mono">Contents/</span>, in your own
folder structure.
</div>
</div>
)}
{blocked === 'destination_not_empty' && (
<div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink">
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.
</div>
)}
{blocked === 'nothing_to_export' && p && p.tracks === 0 && (
<div className="rounded well px-3 py-2 text-xs text-muted">
There’s nothing to export yet — add some tracks or a playlist.
</div>
)}
{/* 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 && (
<div className="rounded well px-3 py-2 text-xs text-pink">
None of the {p.tracks} track{p.tracks === 1 ? '' : 's'} can be exported — their
audio files are not on this disk:
<div className="mt-1 text-faint">{p.missing.slice(0, 4).join(', ')}</div>
</div>
)}
{blocked === 'unsupported_target' && (
<div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink">
Konduktor can’t write that kind of library yet.
</div>
)}
</>
)}
{job && (
<div className="space-y-3">
<div className="text-text">
{job.state === 'done' ? finishedLine(job.result) : job.message || 'Working…'}
</div>
<div className="h-2 overflow-hidden rounded-full bg-well">
<div
className={`h-full transition-[width] duration-200 ${
job.state === 'failed' ? 'bg-pink' : 'bg-accent'
} ${pct == null ? 'w-1/3 animate-pulse' : ''}`}
style={pct == null ? undefined : { width: `${pct}%` }}
/>
</div>
{/* Tracks say their count in the message ("Analysing … (12/207)"). */}
{pct != null && running && job.unit === 'bytes' && (
<div className="text-xs text-faint">
{gb(job.done)} of {gb(job.total)}
</div>
)}
{job.state === 'cancelled' && (
<div className="text-xs text-muted">
Cancelled. Everything this export copied was removed, and no library was
written.
</div>
)}
{job.state === 'failed' && (
<div className="text-xs text-pink">
{job.error} — nothing was left behind: no audio, and no library for any platform.
</div>
)}
{job.state === 'done' && (
<div className="space-y-1 text-xs text-mint">
<div>Done — the folder is ready.</div>
{(
(job.result as { libraries?: { platform: string; library: string }[] } | null)
?.libraries ?? []
).map((l) => (
<div key={l.platform} className="text-faint">
{nameOf(l.platform)}: <span className="font-mono">{l.library}</span>
</div> </div>
))} {p.free_bytes != null && (
</div> <div className={p.enough_space === false ? 'text-pink' : 'text-faint'}>
)} {gb(p.free_bytes)} free
</div> {p.enough_space === false && ' — not enough space'}
)} </div>
</div> )}
{/* 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 && (
<div className="rounded well px-3 py-2 text-xs text-pink">
{p.missing.length} track{p.missing.length === 1 ? '' : 's'} will be skipped —
the audio file is not on this disk:
<div className="mt-1 text-faint">{p.missing.slice(0, 4).join(', ')}</div>
</div>
)}
{p.replacing && (
<div className="rounded well px-3 py-2 text-xs text-gold">
This folder already holds an export. Tracks that haven’t changed are kept; everything else is replaced.
</div>
)}
{/* 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 && (
<div className="rounded well px-3 py-2 text-xs text-gold">
{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.
</div>
)}
{lockable && (
<label className="flex cursor-pointer items-start gap-2.5">
<input
type="checkbox"
className="mt-0.5"
checked={lockGrids}
onChange={(e) => setLockGrids(e.target.checked)}
/>
<span className="min-w-0">
<span className="block text-sm text-text">Lock beatgrids</span>
<span className="block text-xs text-faint">
Stops tracks being re-analysed when they’re loaded, which can change the
BPM or move the grid.
</span>
</span>
</label>
)}
<div className="text-xs text-faint">
Writes a library for {set.targets.map(nameOf).join(' and ')}, sharing one copy
of every track under <span className="font-mono">Contents/</span>, in your own
folder structure.
</div>
</div>
)}
<div className="flex justify-end gap-2 border-t border-line px-5 py-3"> {blocked === 'destination_not_empty' && (
{running ? ( <div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink">
<> That folder already has files in it that Konduktor didn’t put there. An export
<button replaces what it wrote last time, so it will only write into an empty folder or
onClick={cancel} one of its own. Choose another folder.
className="btn-glass rounded-full px-3 py-1.5 text-sm text-muted hover:text-text" </div>
> )}
Cancel export {blocked === 'nothing_to_export' && p && p.tracks === 0 && (
</button> <div className="rounded well px-3 py-2 text-xs text-muted">
<button There’s nothing to export yet — add some tracks or a playlist.
onClick={onClose} </div>
className="rounded-md px-3 py-1.5 text-sm text-faint hover:text-text" )}
title="The export keeps running" {/* Tracks exist but none of their audio does: saying "nothing to
> export" here sends the user looking in the wrong place. */}
Hide {blocked === 'nothing_to_export' && p && p.tracks > 0 && (
</button> <div className="rounded well px-3 py-2 text-xs text-pink">
</> None of the {p.tracks} track{p.tracks === 1 ? '' : 's'} can be exported — their
) : ( audio files are not on this disk:
<> <div className="mt-1 text-faint">{p.missing.slice(0, 4).join(', ')}</div>
<button </div>
onClick={onClose} )}
className="btn-glass rounded-full px-3 py-1.5 text-sm text-muted hover:text-text" {blocked === 'unsupported_target' && (
> <div className="rounded border border-pink/40 bg-well px-3 py-2 text-xs text-pink">
{finished ? 'Close' : 'Cancel'} Konduktor can’t write that kind of library yet.
</button> </div>
{!finished && ( )}
</>
)}
{job && (
<div className="space-y-3">
<div className="text-text">
{job.state === 'done' ? finishedLine(job.result) : job.message || 'Working…'}
</div>
<div className="h-2 overflow-hidden rounded-full bg-well">
<div
className={`h-full transition-[width] duration-200 ${
job.state === 'failed' ? 'bg-pink' : 'bg-accent'
} ${pct == null ? 'w-1/3 animate-pulse' : ''}`}
style={pct == null ? undefined : { width: `${pct}%` }}
/>
</div>
{/* Tracks say their count in the message ("Analysing … (12/207)"). */}
{pct != null && running && job.unit === 'bytes' && (
<div className="text-xs text-faint">
{gb(job.done)} of {gb(job.total)}
</div>
)}
{job.state === 'cancelled' && (
<div className="text-xs text-muted">
Cancelled. Everything this export copied was removed, and no library was
written.
</div>
)}
{job.state === 'failed' && (
<div className="text-xs text-pink">
{job.error} — nothing was left behind: no audio, and no library for any platform.
</div>
)}
{job.state === 'done' && (
<div className="space-y-1 text-xs text-mint">
<div>Done — the folder is ready.</div>
{(
(job.result as { libraries?: { platform: string; library: string }[] } | null)
?.libraries ?? []
).map((l) => (
<div key={l.platform} className="text-faint">
{nameOf(l.platform)}: <span className="font-mono">{l.library}</span>
</div>
))}
</div>
)}
</div>
)}
</div>
<div className="flex justify-end gap-2 border-t border-line px-5 py-3">
{running ? (
<>
<button <button
disabled={ onClick={cancel}
starting || !p || !!blocked || p.exportable === 0 || p.enough_space === false className="btn-glass rounded-full px-3 py-1.5 text-sm text-muted hover:text-text"
}
onClick={start}
className="rounded-full btn-primary px-3 py-1.5 text-sm font-semibold disabled:opacity-40"
> >
{starting ? 'Starting…' : `Export ${p && !blocked ? p.exportable : ''}`.trim()} Cancel export
</button> </button>
)} <button
</> onClick={onClose}
)} className="rounded-md px-3 py-1.5 text-sm text-faint hover:text-text"
title="The export keeps running"
>
Hide
</button>
</>
) : (
<>
<button
onClick={onClose}
className="btn-glass rounded-full px-3 py-1.5 text-sm text-muted hover:text-text"
>
{finished ? 'Close' : 'Cancel'}
</button>
{!finished && (
<button
disabled={
starting || moving || preview.isFetching || !p || !!blocked || p.exportable === 0 || p.enough_space === false
}
onClick={start}
className="rounded-full btn-primary px-3 py-1.5 text-sm font-semibold disabled:opacity-40"
>
{starting ? 'Starting…' : `Export ${p && !blocked ? p.exportable : ''}`.trim()}
</button>
)}
</>
)}
</div>
</div> </div>
</div> </div>
</div>, </>,
document.body, document.body,
) )
} }