Implemented export creation UI

This commit is contained in:
patben8 committed 2026-09-23 15:04:53 +02:00
1 parent 805b95fe5e
commit 7160fa3978
9 files changed
+787 -17

No files matched your search

+177 -10
View File
@@ -174,6 +174,39 @@ export default function App() {
enabled: loaded && source.kind === 'playlist',
})
// An export set being browsed. Its tracks ARE collection tracks — an export is
// a slice of the loaded library, not another library — so these share the
// collection's capabilities and stay fully editable, unlike a device.
const viewingExport =
source.kind === 'export' ||
source.kind === 'export-playlist' ||
source.kind === 'export-other'
const exportTracks = useQuery({
queryKey: ['export-tracks', source.kind === 'export' ? source.id : null],
queryFn: () => api.exportTracks((source as { id: string }).id),
enabled: source.kind === 'export',
})
const exportPlaylistTracks = useQuery({
queryKey: [
'export-playlist-tracks',
source.kind === 'export-playlist' ? source.exportId : null,
source.kind === 'export-playlist' ? source.id : null,
],
queryFn: () =>
api.exportPlaylistTracks(
(source as { exportId: string }).exportId,
(source as { id: string }).id,
),
enabled: source.kind === 'export-playlist',
})
// The loose tracks only. A separate query, not a filter on the root view: the
// root is everything the export would ship, which is a different answer.
const exportLooseTracks = useQuery({
queryKey: ['export-loose', source.kind === 'export-other' ? source.exportId : null],
queryFn: () => api.exportLooseTracks((source as { exportId: string }).exportId),
enabled: source.kind === 'export-other',
})
// A browsed device. Separate queries and separate cache keys from the
// collection's: the two libraries can hold tracks with identical ids, and one
// shared key would serve a stick's track as if it were a collection track.
@@ -200,6 +233,42 @@ export default function App() {
staleTime: Infinity,
})
const openDevice = useQuery({ queryKey: ['source'], queryFn: api.source })
const exportSets = useQuery({ queryKey: ['exports'], queryFn: api.exports, enabled: loaded })
// Export membership. Both are no-ops on the library itself, so neither dirties
// it nor touches version history — an export set is Konduktor's own data.
const refreshExport = useCallback(
(id: string) => {
qc.invalidateQueries({ queryKey: ['export-contents', id] })
qc.invalidateQueries({ queryKey: ['export-tracks', id] })
qc.invalidateQueries({ queryKey: ['export-loose', id] })
},
[qc],
)
const addToExport = useCallback(
async (id: string, ids: string[]) => {
try {
await api.addToExport(id, { track_ids: ids })
refreshExport(id)
const name = exportSets.data?.find((s) => s.id === id)?.name ?? 'export'
notify('success', `Added ${ids.length} track${ids.length === 1 ? '' : 's'} to ${name}`)
} catch (e) {
onError((e as Error).message)
}
},
[refreshExport, exportSets.data, notify, onError],
)
const removeFromExport = useCallback(
async (id: string, ids: string[]) => {
try {
await api.removeFromExport(id, { track_ids: ids })
refreshExport(id)
} catch (e) {
onError((e as Error).message)
}
},
[refreshExport, onError],
)
// What the VIEW can do, as opposed to what the loaded collection can do. While
// a device is being browsed these are its read-only capabilities, so the
@@ -230,16 +299,28 @@ export default function App() {
? source.kind === 'device'
? (deviceTracks.data?.items ?? [])
: (devicePlaylistTracks.data ?? [])
: isAll
? (allTracks.data?.items ?? [])
: (playlistTracks.data ?? [])
: viewingExport
? source.kind === 'export'
? (exportTracks.data ?? [])
: source.kind === 'export-other'
? (exportLooseTracks.data ?? [])
: (exportPlaylistTracks.data ?? [])
: isAll
? (allTracks.data?.items ?? [])
: (playlistTracks.data ?? [])
const loading = viewingDevice
? source.kind === 'device'
? deviceTracks.isLoading
: devicePlaylistTracks.isLoading
: isAll
? allTracks.isLoading
: playlistTracks.isLoading
: viewingExport
? source.kind === 'export'
? exportTracks.isLoading
: source.kind === 'export-other'
? exportLooseTracks.isLoading
: exportPlaylistTracks.isLoading
: isAll
? allTracks.isLoading
: playlistTracks.isLoading
// Search / filters apply to both the library and playlists (the toolbar is
// always visible). In a playlist a filtered view disables drag-reorder — see
// `canReorder` below — so a partial order can't overwrite the full entry list.
@@ -339,6 +420,28 @@ export default function App() {
...(canEdit
? [{ label: 'Edit Tags…', onClick: () => setEditing(menu.track) }]
: []),
// Adding to an export touches no library data, so it is offered even
// on a read-only one — an export is Konduktor's own curation.
...(exportSets.data ?? []).map((set) => ({
label: `Add to “${set.name}”`,
onClick: () => addToExport(set.id, [menu.track.id]),
})),
// Only on the export's ROOT view. Inside a referenced playlist there
// is nothing to remove: the reference is live, and per-track removal
// would need an exclusion list — hidden state deciding what a future
// export contains. Remove the whole playlist, or add tracks instead.
...(source.kind === 'export' || source.kind === 'export-other'
? [
{
label: 'Remove from this export',
onClick: () =>
removeFromExport(
source.kind === 'export' ? source.id : source.exportId,
[menu.track.id],
),
},
]
: []),
]}
onClose={() => setMenu(null)}
/>
@@ -398,6 +501,7 @@ export default function App() {
onOpenHistory={() => setShowHistory(true)}
onImport={() => setImporting(true)}
onSwitchLibrary={() => setForcePicker(true)}
onDone={(msg) => notify('success', msg)}
/>
<CapabilitiesContext.Provider value={viewCaps}>
@@ -413,11 +517,33 @@ export default function App() {
/>
{(!isAll || viewingDevice) && (
<div className="flex items-center gap-3 border-b border-line bg-ink-900 px-4 py-2">
<span className={`text-[11px] ${viewingDevice ? 'text-gold' : 'text-accent'}`}>
{viewingDevice ? '⬒' : '♫'}
<span
className={`text-[11px] ${
viewingDevice ? 'text-gold' : viewingExport ? 'text-gold' : 'text-accent'
}`}
>
{viewingDevice ? '⬒' : viewingExport ? (source.kind === 'export' ? '◈' : '♫') : '♫'}
</span>
<span className="font-semibold text-text">{viewName}</span>
{viewingDevice ? (
{viewingExport ? (
<>
<span className="text-xs text-faint">
{filtersActive
? `${filtered.length} of ${tracks.length} tracks`
: `${tracks.length} tracks`}
{source.kind === 'export'
? ' · everything this export would ship'
: source.kind === 'export-other'
? ' · added individually — these become an “Other” playlist'
: ' · live — what ships is whatever this playlist holds at export time'}
</span>
<span className="ml-auto flex items-center gap-2">
<span className="rounded bg-ink-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-gold">
Export
</span>
</span>
</>
) : viewingDevice ? (
<>
<span className="text-xs text-faint">
{filtersActive
@@ -449,6 +575,45 @@ export default function App() {
<div className="min-h-0 flex-1">
{loading ? (
<div className="flex h-full items-center justify-center text-muted">Loading…</div>
) : viewingExport ? (
/* An export uses the plain table, NOT the playlist one. The playlist
table's × removes a track from the user's REAL playlist — same
pixels, opposite meaning — and an export's own removal is offered
through the context menu instead, on its root view only.
Selection stays on, so "Add to…" works from inside an export. */
filtered.length === 0 ? (
<div className="flex h-full flex-col items-center justify-center gap-2 text-muted">
<div className="text-lg">
{tracks.length === 0 ? 'Nothing in this export yet' : 'No tracks match'}
</div>
<div className="text-sm text-faint">
{tracks.length === 0
? 'Select tracks in All Tracks and use “Add to…”, or add a whole playlist.'
: 'Try clearing some filters.'}
</div>
</div>
) : (
<TrackTable
tracks={filtered}
sorting={sorting}
onSortingChange={setSorting}
selection={{
selected,
onToggle: toggle,
onToggleAll: toggleAll,
allSelected: selected.size > 0 && selected.size === filtered.length,
}}
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
onPlay={playTrack}
onEditField={canEdit ? editField : undefined}
activeTrackId={prepTrack?.id ?? null}
columnVisibility={columnVisibility}
columnOrder={columnOrder}
columnSizing={columnSizing}
onColumnOrderChange={setColumnOrder}
onColumnSizingChange={setColumnSizing}
/>
)
) : viewingDevice ? (
/* A device uses the plain table, not the playlist one: a stick's
playlists cannot be reordered or have entries removed, so the
@@ -539,7 +704,9 @@ export default function App() {
/>
)}
{isAll && (
{/* Also inside an export: its rows ARE collection tracks, so "Add
to…" means the same thing there as in All Tracks. */}
{(isAll || viewingExport) && (
<SelectionBar
count={selected.size}
trackIds={[...selected]}
+5
View File
@@ -504,6 +504,11 @@ export const api = {
getJSON<ExportContents>(`/api/exports/${encodeURIComponent(id)}/contents`),
exportTracks: (id: string) =>
getJSON<Track[]>(`/api/exports/${encodeURIComponent(id)}/tracks`),
// Only the tracks added individually — the "Other" bucket, which becomes its
// own playlist in the exported library. Not a filter on exportTracks: that one
// is everything the export would ship, playlists included and deduped.
exportLooseTracks: (id: string) =>
getJSON<Track[]>(`/api/exports/${encodeURIComponent(id)}/loose`),
exportPlaylistTracks: (id: string, playlistId: string) =>
getJSON<Track[]>(
`/api/exports/${encodeURIComponent(id)}/playlists/${encodeURIComponent(playlistId)}/tracks`,
+170
View File
@@ -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>
</>
)
}
+275
View File
@@ -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>
)
}
+43 -3
View File
@@ -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>
+67
View File
@@ -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}