mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented export creation UI
This commit is contained in:
1 parent
805b95fe5e
commit
7160fa3978
9 files changed
+787
-17
No files matched your search
@@ -0,0 +1,170 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { api, type ExportSet } from '../api'
|
||||
import { FolderPicker } from './FolderPicker'
|
||||
|
||||
/**
|
||||
* Create or edit an export: its name, its target platform and where it lands.
|
||||
*
|
||||
* All three are settled up front, and the destination especially is NOT a
|
||||
* detail deferred to export time. A Traktor `<LOCATION>` is a volume name plus
|
||||
* a volume-relative path — both derived from where the export is written — so
|
||||
* the library file genuinely cannot be built until the destination is known.
|
||||
*/
|
||||
|
||||
interface Props {
|
||||
/** The set being edited, or null to create a new one. */
|
||||
editing: ExportSet | null
|
||||
onClose: () => void
|
||||
onSaved: (set: ExportSet, created: boolean) => void
|
||||
onError: (msg: string) => void
|
||||
}
|
||||
|
||||
export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {
|
||||
const [name, setName] = useState(editing?.name ?? '')
|
||||
const [target, setTarget] = useState(editing?.target ?? 'traktor')
|
||||
const [destination, setDestination] = useState(editing?.destination ?? '')
|
||||
const [browsing, setBrowsing] = useState(false)
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
// Every platform, with `installed` standing for "can be an export target".
|
||||
// The unsupported ones are shown DISABLED with a reason rather than hidden:
|
||||
// an absent option reads as a missing feature, a disabled one as a roadmap.
|
||||
const targets = useQuery({ queryKey: ['export-targets'], queryFn: api.exportTargets })
|
||||
|
||||
// Another set writing to the same folder would have its output wiped, because
|
||||
// an export clears its destination before writing. Caught while the folder is
|
||||
// being chosen — at run time a warning would already be too late.
|
||||
const conflict = useQuery({
|
||||
queryKey: ['export-conflict', editing?.id ?? null],
|
||||
queryFn: () => api.exportContents(editing!.id),
|
||||
enabled: !!editing,
|
||||
}).data?.destination_conflict
|
||||
|
||||
const valid = name.trim() !== '' && destination.trim() !== ''
|
||||
|
||||
const save = async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
const body = { name: name.trim(), target, destination: destination.trim() }
|
||||
const saved = editing
|
||||
? await api.updateExport(editing.id, body)
|
||||
: await api.createExport(body)
|
||||
onSaved(saved, !editing)
|
||||
} catch (e) {
|
||||
onError((e as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{browsing && (
|
||||
<FolderPicker
|
||||
value={destination}
|
||||
onChange={setDestination}
|
||||
onClose={() => setBrowsing(false)}
|
||||
/>
|
||||
)}
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
||||
<div className="w-full max-w-lg rounded-lg border border-line bg-ink-900 shadow-xl">
|
||||
<div className="border-b border-line px-5 py-3">
|
||||
<h2 className="text-sm font-semibold text-text">
|
||||
{editing ? `Edit “${editing.name}”` : 'New export'}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4 px-5 py-4 text-sm">
|
||||
<div>
|
||||
<span className="mb-1 block text-xs text-muted">Name</span>
|
||||
<input
|
||||
autoFocus
|
||||
value={name}
|
||||
placeholder="Ibiza — July"
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && valid && !busy) save()
|
||||
}}
|
||||
className="w-full rounded-md border border-line bg-ink-950 px-2 py-1.5 text-sm text-text outline-none focus:border-accent"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="mb-1 block text-xs text-muted">For</span>
|
||||
<div className="space-y-1">
|
||||
{(targets.data ?? []).map((p) => (
|
||||
<label
|
||||
key={p.platform}
|
||||
className={`flex items-center gap-2 rounded-md px-2 py-1.5 ${
|
||||
p.installed ? 'cursor-pointer hover:bg-ink-850' : 'cursor-not-allowed'
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
disabled={!p.installed}
|
||||
checked={target === p.platform}
|
||||
onChange={() => setTarget(p.platform)}
|
||||
className="accent-accent"
|
||||
/>
|
||||
<span className={p.installed ? 'text-text' : 'text-faint'}>{p.name}</span>
|
||||
{!p.installed && (
|
||||
<span className="ml-auto text-[11px] text-faint">
|
||||
Konduktor cannot write a {p.name} library yet
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="mb-1 block text-xs text-muted">Export to</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
title={destination}
|
||||
dir="rtl"
|
||||
className="min-w-0 flex-1 truncate rounded-md border border-line bg-ink-950 px-2 py-1.5 font-mono text-xs text-text"
|
||||
>
|
||||
{destination || 'Choose a folder…'}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => setBrowsing(true)}
|
||||
className="shrink-0 rounded-md border border-line px-3 py-1.5 text-sm text-muted hover:text-text"
|
||||
>
|
||||
Browse…
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-1 text-[11px] text-faint">
|
||||
The folder gets a <span className="font-mono">collection.nml</span> and a copy of
|
||||
every track, in your own folder structure.
|
||||
</div>
|
||||
{conflict && (
|
||||
<div className="mt-2 rounded border border-line bg-ink-950 px-3 py-2 text-xs text-gold">
|
||||
“{conflict}” already exports here. Exporting replaces whatever the other one
|
||||
wrote.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 border-t border-line px-5 py-3">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="rounded-md border border-line px-3 py-1.5 text-sm text-muted hover:text-text"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
disabled={!valid || busy}
|
||||
onClick={save}
|
||||
className="rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-ink-950 hover:brightness-110 disabled:opacity-40"
|
||||
>
|
||||
{busy ? 'Saving…' : editing ? 'Save' : 'Create'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
import { useState } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { api, type ExportSet } from '../api'
|
||||
import { ExportDialog } from './ExportDialog'
|
||||
import type { Source } from './Sidebar'
|
||||
|
||||
/**
|
||||
* Exports in the sidebar: each one a named, persisted slice of the library
|
||||
* bound to a destination.
|
||||
*
|
||||
* An export expands to show the playlists it references. Those are LIVE links —
|
||||
* what ships is whatever the playlist holds at export time — which is why the
|
||||
* counts here come from `contents`, recomputed on every read, rather than from
|
||||
* anything stored in the set.
|
||||
*
|
||||
* The one deliberate omission: a referenced playlist has no per-track remove.
|
||||
* A live reference and per-track removal are in tension, and honouring both
|
||||
* would need an exclusion list — hidden state quietly deciding what a future
|
||||
* export contains. Remove the whole playlist, or add the tracks instead of it.
|
||||
*/
|
||||
|
||||
interface Props {
|
||||
source: Source
|
||||
onSelect: (s: Source) => void
|
||||
onDone: (msg: string) => void
|
||||
onError: (msg: string) => void
|
||||
}
|
||||
|
||||
export function ExportsSection({ source, onSelect, onDone, onError }: Props) {
|
||||
const qc = useQueryClient()
|
||||
const [dialog, setDialog] = useState<{ editing: ExportSet | null } | null>(null)
|
||||
|
||||
const sets = useQuery({ queryKey: ['exports'], queryFn: api.exports })
|
||||
|
||||
const remove = useMutation({
|
||||
mutationFn: (id: string) => api.deleteExport(id),
|
||||
onSuccess: (_r, id) => {
|
||||
qc.invalidateQueries({ queryKey: ['exports'] })
|
||||
if (
|
||||
(source.kind === 'export' && source.id === id) ||
|
||||
((source.kind === 'export-playlist' || source.kind === 'export-other') &&
|
||||
source.exportId === id)
|
||||
)
|
||||
onSelect({ kind: 'all' })
|
||||
},
|
||||
onError: (e: Error) => onError(e.message),
|
||||
})
|
||||
|
||||
const list = sets.data ?? []
|
||||
|
||||
return (
|
||||
<>
|
||||
{dialog && (
|
||||
<ExportDialog
|
||||
editing={dialog.editing}
|
||||
onClose={() => setDialog(null)}
|
||||
onSaved={(saved, created) => {
|
||||
qc.invalidateQueries({ queryKey: ['exports'] })
|
||||
qc.invalidateQueries({ queryKey: ['export-contents'] })
|
||||
setDialog(null)
|
||||
onDone(created ? `Created “${saved.name}”` : `Saved “${saved.name}”`)
|
||||
if (created) onSelect({ kind: 'export', id: saved.id, name: saved.name })
|
||||
}}
|
||||
onError={onError}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="mt-3 flex items-center justify-between px-4">
|
||||
<span className="text-[10px] font-semibold uppercase tracking-wider text-faint">
|
||||
Exports
|
||||
</span>
|
||||
<button
|
||||
title="New export"
|
||||
onClick={() => setDialog({ editing: null })}
|
||||
className="rounded px-1 text-sm text-faint hover:text-text"
|
||||
>
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-1 px-2">
|
||||
{list.length === 0 && (
|
||||
<div className="px-2 py-1.5 text-[11px] text-faint">
|
||||
A curated set of tracks, copied to a folder with its own library file.
|
||||
</div>
|
||||
)}
|
||||
{list.map((set) => (
|
||||
<ExportRow
|
||||
key={set.id}
|
||||
set={set}
|
||||
source={source}
|
||||
onSelect={onSelect}
|
||||
onEdit={() => setDialog({ editing: set })}
|
||||
onDelete={() => {
|
||||
// Deleting a set never touches its destination folder — the files
|
||||
// already exported are the user's, not Konduktor's to clean up.
|
||||
if (confirm(`Delete the export “${set.name}”? Nothing already exported is removed.`))
|
||||
remove.mutate(set.id)
|
||||
}}
|
||||
onError={onError}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function ExportRow({
|
||||
set,
|
||||
source,
|
||||
onSelect,
|
||||
onEdit,
|
||||
onDelete,
|
||||
onError,
|
||||
}: {
|
||||
set: ExportSet
|
||||
source: Source
|
||||
onSelect: (s: Source) => void
|
||||
onEdit: () => void
|
||||
onDelete: () => void
|
||||
onError: (msg: string) => void
|
||||
}) {
|
||||
const qc = useQueryClient()
|
||||
const selected = source.kind === 'export' && source.id === set.id
|
||||
const inside =
|
||||
selected ||
|
||||
((source.kind === 'export-playlist' || source.kind === 'export-other') &&
|
||||
source.exportId === set.id)
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
// Live: recomputed every read, because a referenced playlist edited after
|
||||
// curation changes what this export would ship.
|
||||
const contents = useQuery({
|
||||
queryKey: ['export-contents', set.id],
|
||||
queryFn: () => api.exportContents(set.id),
|
||||
})
|
||||
|
||||
const dropPlaylist = useMutation({
|
||||
mutationFn: (playlistId: string) =>
|
||||
api.removeFromExport(set.id, { playlist_ids: [playlistId] }),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['export-contents', set.id] })
|
||||
qc.invalidateQueries({ queryKey: ['export-tracks', set.id] })
|
||||
},
|
||||
onError: (e: Error) => onError(e.message),
|
||||
})
|
||||
|
||||
const data = contents.data
|
||||
const expanded = open || inside
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className={`group flex w-full items-center gap-1 rounded-md pr-1 transition-colors ${
|
||||
selected ? 'bg-accent-soft text-text' : 'text-muted hover:bg-ink-800 hover:text-text'
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
title={expanded ? 'Collapse' : 'Expand'}
|
||||
onClick={() => setOpen((o) => !o)}
|
||||
className="w-4 shrink-0 py-1.5 text-center text-[10px] text-faint hover:text-text"
|
||||
>
|
||||
{expanded ? '▾' : '▸'}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onSelect({ kind: 'export', id: set.id, name: set.name })}
|
||||
className="flex min-w-0 flex-1 items-center gap-2 py-1.5 text-left text-sm"
|
||||
>
|
||||
<span className="w-3 shrink-0 text-center text-[11px] text-gold">◈</span>
|
||||
<span className="flex-1 truncate" title={set.destination}>
|
||||
{set.name}
|
||||
</span>
|
||||
<span className="shrink-0 text-[10px] tabular-nums text-faint">
|
||||
{data ? data.tracks : ''}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
title="Edit name, target and destination"
|
||||
onClick={onEdit}
|
||||
className="shrink-0 px-1 text-xs text-faint opacity-0 hover:text-text group-hover:opacity-100"
|
||||
>
|
||||
⚙
|
||||
</button>
|
||||
<button
|
||||
title="Delete this export"
|
||||
onClick={onDelete}
|
||||
className="shrink-0 px-1 text-xs text-faint opacity-0 hover:text-pink group-hover:opacity-100"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{expanded && (
|
||||
<>
|
||||
{(data?.playlists ?? []).map((p) => {
|
||||
const chosen = source.kind === 'export-playlist' && source.id === p.id
|
||||
return (
|
||||
<div
|
||||
key={p.id}
|
||||
className={`group flex items-center gap-1 rounded-md pr-1 ${
|
||||
chosen ? 'bg-accent-soft text-text' : 'text-muted hover:bg-ink-800 hover:text-text'
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
disabled={p.missing}
|
||||
onClick={() =>
|
||||
onSelect({
|
||||
kind: 'export-playlist',
|
||||
exportId: set.id,
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
})
|
||||
}
|
||||
style={{ paddingLeft: 24 }}
|
||||
className="flex min-w-0 flex-1 items-center gap-2 py-1 text-left text-sm disabled:cursor-not-allowed"
|
||||
>
|
||||
<span className="w-3 shrink-0 text-center text-[11px] text-faint">♫</span>
|
||||
{/* A playlist deleted since curation is SHOWN, not dropped:
|
||||
the set records the user's intent, and losing part of it
|
||||
silently is worse than showing something broken. */}
|
||||
<span className={`flex-1 truncate ${p.missing ? 'text-faint line-through' : ''}`}>
|
||||
{p.name}
|
||||
</span>
|
||||
<span className="shrink-0 text-[10px] tabular-nums text-faint">
|
||||
{p.missing ? 'gone' : p.count}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
title="Remove this playlist from the export"
|
||||
onClick={() => dropPlaylist.mutate(p.id)}
|
||||
className="shrink-0 px-1 text-xs text-faint opacity-0 hover:text-pink group-hover:opacity-100"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
{!!data?.loose && (
|
||||
<button
|
||||
onClick={() => onSelect({ kind: 'export-other', exportId: set.id, name: 'Other' })}
|
||||
style={{ paddingLeft: 24 }}
|
||||
className={`flex w-full items-center gap-2 rounded-md py-1 pr-2 text-left text-sm transition-colors ${
|
||||
source.kind === 'export-other' && source.exportId === set.id
|
||||
? 'bg-accent-soft text-text'
|
||||
: 'text-muted hover:bg-ink-800 hover:text-text'
|
||||
}`}
|
||||
>
|
||||
<span className="w-3 shrink-0 text-center text-[11px] text-faint">◇</span>
|
||||
<span className="flex-1 truncate">Other</span>
|
||||
<span className="shrink-0 text-[10px] tabular-nums text-faint">{data.loose}</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
{!!data?.dangling.length && (
|
||||
<div
|
||||
style={{ paddingLeft: 24 }}
|
||||
className="py-1 pr-2 text-[11px] text-pink"
|
||||
title={data.dangling.join('\n')}
|
||||
>
|
||||
{data.dangling.length} track{data.dangling.length === 1 ? '' : 's'} no longer in your
|
||||
library
|
||||
</div>
|
||||
)}
|
||||
|
||||
{expanded && data && data.tracks === 0 && (
|
||||
<div style={{ paddingLeft: 24 }} className="py-1 pr-2 text-[11px] text-faint">
|
||||
Empty — select tracks and use “Add to…”.
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -22,7 +22,27 @@ export function SelectionBar({ count, trackIds, onClear, onDone, onError }: Prop
|
||||
const qc = useQueryClient()
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
const { data: playlists } = useQuery({ queryKey: ['playlists'], queryFn: api.playlists })
|
||||
const { data: exportSets } = useQuery({ queryKey: ['exports'], queryFn: api.exports })
|
||||
const flat = playlists ? flattenPlaylists(playlists) : []
|
||||
const sets = exportSets ?? []
|
||||
|
||||
// Adding to an EXPORT does not touch the library — an export set is
|
||||
// Konduktor's own curation — so unlike the playlist mutation this dirties
|
||||
// nothing and invalidates only the export's own live counts.
|
||||
const addToExport = useMutation({
|
||||
mutationFn: ({ id, ids }: { id: string; ids: string[] }) =>
|
||||
api.addToExport(id, { track_ids: ids }),
|
||||
onSuccess: (_res, vars) => {
|
||||
qc.invalidateQueries({ queryKey: ['export-contents', vars.id] })
|
||||
qc.invalidateQueries({ queryKey: ['export-tracks', vars.id] })
|
||||
qc.invalidateQueries({ queryKey: ['export-loose', vars.id] })
|
||||
const set = sets.find((s) => s.id === vars.id)
|
||||
onDone(`Added ${vars.ids.length} track${vars.ids.length === 1 ? '' : 's'} to ${set?.name ?? 'export'}`)
|
||||
setMenuOpen(false)
|
||||
onClear()
|
||||
},
|
||||
onError: (e: Error) => onError(e.message),
|
||||
})
|
||||
|
||||
const add = useMutation({
|
||||
mutationFn: ({ uuid, ids }: { uuid: string; ids: string[] }) => api.addEntries(uuid, ids),
|
||||
@@ -51,12 +71,15 @@ export function SelectionBar({ count, trackIds, onClear, onDone, onError }: Prop
|
||||
onClick={() => setMenuOpen((o) => !o)}
|
||||
className="rounded-full bg-accent px-3 py-1.5 text-sm font-medium text-ink-950 hover:brightness-110"
|
||||
>
|
||||
Add to playlist ▾
|
||||
Add to… ▾
|
||||
</button>
|
||||
{menuOpen && (
|
||||
<div className="absolute bottom-full right-0 mb-2 max-h-72 w-56 overflow-y-auto rounded-lg border border-line bg-ink-850 p-1 shadow-2xl">
|
||||
<div className="absolute bottom-full right-0 mb-2 max-h-72 w-60 overflow-y-auto rounded-lg border border-line bg-ink-850 p-1 shadow-2xl">
|
||||
<div className="px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-wider text-faint">
|
||||
Playlists
|
||||
</div>
|
||||
{flat.length === 0 && (
|
||||
<div className="px-3 py-2 text-sm text-faint">No playlists yet</div>
|
||||
<div className="px-3 py-1.5 text-sm text-faint">No playlists yet</div>
|
||||
)}
|
||||
{flat.map((p) => (
|
||||
<button
|
||||
@@ -68,6 +91,23 @@ export function SelectionBar({ count, trackIds, onClear, onDone, onError }: Prop
|
||||
<span className="shrink-0 text-[10px] tabular-nums text-faint">{p.count}</span>
|
||||
</button>
|
||||
))}
|
||||
|
||||
<div className="px-3 pb-1 pt-3 text-[10px] font-semibold uppercase tracking-wider text-faint">
|
||||
Exports
|
||||
</div>
|
||||
{sets.length === 0 && (
|
||||
<div className="px-3 py-1.5 text-sm text-faint">No exports yet</div>
|
||||
)}
|
||||
{sets.map((set) => (
|
||||
<button
|
||||
key={set.id}
|
||||
onClick={() => addToExport.mutate({ id: set.id, ids: trackIds })}
|
||||
className="flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-left text-sm text-muted hover:bg-ink-800 hover:text-text"
|
||||
>
|
||||
<span className="shrink-0 text-[11px] text-gold">◈</span>
|
||||
<span className="truncate">{set.name}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { api, type PlaylistKind, type PlaylistNode } from '../api'
|
||||
import { useCaps } from '../lib/capabilities'
|
||||
import { SaveBar } from './SaveBar'
|
||||
import { DevicesSection } from './DevicesSection'
|
||||
import { ExportsSection } from './ExportsSection'
|
||||
|
||||
/**
|
||||
* Which view the main table is showing.
|
||||
@@ -20,6 +21,15 @@ export type Source =
|
||||
| { kind: 'playlist'; id: string; name: string }
|
||||
| { kind: 'device' }
|
||||
| { kind: 'device-playlist'; id: string; name: string }
|
||||
// An export set. `export` is its root — every track it would ship, deduped —
|
||||
// and `export-playlist` is one referenced playlist inside it, read live from
|
||||
// the library rather than from the set, which is the reference doing its job.
|
||||
| { kind: 'export'; id: string; name: string }
|
||||
| { kind: 'export-playlist'; exportId: string; id: string; name: string }
|
||||
// The loose tracks — those added individually rather than via a playlist.
|
||||
// A view of its own, NOT the export root: the root is everything the export
|
||||
// would ship, which is a different question and a different answer.
|
||||
| { kind: 'export-other'; exportId: string; name: string }
|
||||
|
||||
interface Props {
|
||||
source: Source
|
||||
@@ -28,10 +38,17 @@ interface Props {
|
||||
onOpenHistory: () => void
|
||||
onImport: () => void
|
||||
onSwitchLibrary: () => void
|
||||
onDone: (msg: string) => void
|
||||
}
|
||||
|
||||
// Kind picks the icon; every behavioural question is answered by the node's own
|
||||
// flags, so nothing here infers what a node can do from what it is called.
|
||||
/** Every selectable playlist at or under a node, in tree order. */
|
||||
function playlistIdsUnder(node: PlaylistNode): string[] {
|
||||
const here = node.kind === 'folder' ? [] : [node.id]
|
||||
return [...here, ...(node.children ?? []).flatMap(playlistIdsUnder)]
|
||||
}
|
||||
|
||||
const icons: Record<PlaylistKind, string> = {
|
||||
folder: '▸',
|
||||
playlist: '♫',
|
||||
@@ -54,7 +71,23 @@ function NodeRow({
|
||||
const qc = useQueryClient()
|
||||
const [open, setOpen] = useState(true)
|
||||
const [renaming, setRenaming] = useState(false)
|
||||
const [adding, setAdding] = useState(false)
|
||||
const [draft, setDraft] = useState(node.name)
|
||||
const exportSets = useQuery({ queryKey: ['exports'], queryFn: api.exports }).data ?? []
|
||||
|
||||
// A FOLDER contributes its nested playlists; a playlist contributes itself.
|
||||
// Folders are flattened here rather than stored as a folder reference: the
|
||||
// export stores playlist ids, and a folder is a shape in the tree, not a
|
||||
// thing with tracks.
|
||||
const addToExport = useMutation({
|
||||
mutationFn: (setId: string) =>
|
||||
api.addToExport(setId, { playlist_ids: playlistIdsUnder(node) }),
|
||||
onSuccess: (_r, setId) => {
|
||||
qc.invalidateQueries({ queryKey: ['export-contents', setId] })
|
||||
qc.invalidateQueries({ queryKey: ['export-tracks', setId] })
|
||||
},
|
||||
onError: (e: Error) => onError(e.message),
|
||||
})
|
||||
const isFolder = node.kind === 'folder'
|
||||
const selected = source.kind === 'playlist' && source.id === node.id
|
||||
const selectable = node.selectable
|
||||
@@ -136,6 +169,37 @@ function NodeRow({
|
||||
{/* Each action gates on ITS OWN flag: a platform may allow renaming but
|
||||
not deleting. The count shows either way — it is information, not an
|
||||
action, and hiding it on a read-only library loses real data. */}
|
||||
{/* Add this playlist (or folder) to an export. Not gated on the
|
||||
library being writable: an export set is Konduktor's own curation
|
||||
and adding to one changes nothing in the user's library. */}
|
||||
{!renaming && exportSets.length > 0 && (
|
||||
<div className="relative shrink-0">
|
||||
<button
|
||||
title="Add to an export"
|
||||
onClick={() => setAdding((a) => !a)}
|
||||
className="hidden rounded px-1 text-xs text-faint hover:text-gold group-hover:block"
|
||||
>
|
||||
◈
|
||||
</button>
|
||||
{adding && (
|
||||
<div className="absolute right-0 top-full z-30 mt-1 w-48 rounded-md border border-line bg-ink-850 p-1 shadow-2xl">
|
||||
{exportSets.map((set) => (
|
||||
<button
|
||||
key={set.id}
|
||||
onClick={() => {
|
||||
setAdding(false)
|
||||
addToExport.mutate(set.id)
|
||||
}}
|
||||
className="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm text-muted hover:bg-ink-800 hover:text-text"
|
||||
>
|
||||
<span className="shrink-0 text-[11px] text-gold">◈</span>
|
||||
<span className="truncate">{set.name}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{!renaming && node.can_rename && (
|
||||
<button
|
||||
title="Rename"
|
||||
@@ -194,6 +258,7 @@ export function Sidebar({
|
||||
onOpenHistory,
|
||||
onImport,
|
||||
onSwitchLibrary,
|
||||
onDone,
|
||||
}: Props) {
|
||||
const qc = useQueryClient()
|
||||
// Both share a cache entry with App and SaveBar, so the header never
|
||||
@@ -327,6 +392,8 @@ export function Sidebar({
|
||||
))}
|
||||
</div>
|
||||
|
||||
<ExportsSection source={source} onSelect={onSelect} onDone={onDone} onError={onError} />
|
||||
|
||||
<DevicesSection
|
||||
source={source}
|
||||
onSelect={onSelect}
|
||||
|
||||
Reference in new issue
Block a user