mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 18:22:53 +01:00
Added quick target location change button in export dialog
This commit is contained in:
1 parent
9329236955
commit
5c9387f136
1 file changed
+65
-7
@@ -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<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.
|
||||
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>({
|
||||
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,6 +156,14 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
|
||||
const blocked = p?.blocked ?? null
|
||||
|
||||
return createPortal(
|
||||
<>
|
||||
{browsing && (
|
||||
<FolderPicker
|
||||
value={current.destination}
|
||||
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">
|
||||
@@ -133,13 +175,28 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
|
||||
<>
|
||||
<div>
|
||||
<span className="mb-1 block text-xs text-muted">To</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
dir="rtl"
|
||||
title={set.destination}
|
||||
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}
|
||||
{current.destination}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setBrowsing(true)}
|
||||
disabled={moving || starting}
|
||||
className="shrink-0 btn-glass rounded-full px-3 py-1 text-xs text-muted hover:text-text disabled:opacity-40"
|
||||
>
|
||||
{moving ? 'Saving…' : 'Change…'}
|
||||
</button>
|
||||
</div>
|
||||
{conflict && (
|
||||
<div className="mt-2 rounded well px-3 py-2 text-xs text-gold">
|
||||
“{conflict}” already exports here. Exporting replaces whatever the other one
|
||||
wrote.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{preview.isLoading && <div className="text-faint">Checking…</div>}
|
||||
@@ -215,7 +272,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
|
||||
<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.
|
||||
one of its own. Choose another folder.
|
||||
</div>
|
||||
)}
|
||||
{blocked === 'nothing_to_export' && p && p.tracks === 0 && (
|
||||
@@ -315,7 +372,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
|
||||
{!finished && (
|
||||
<button
|
||||
disabled={
|
||||
starting || !p || !!blocked || p.exportable === 0 || p.enough_space === false
|
||||
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"
|
||||
@@ -327,7 +384,8 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
</div>
|
||||
</>,
|
||||
document.body,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user