From 89c7dade25f492f4697e5922724c058319752b31 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Tue, 6 Oct 2026 22:41:29 +0200 Subject: [PATCH] Tracks can be added to playlists via drag --- frontend/src/App.tsx | 13 ++-- frontend/src/components/ConfirmDialog.tsx | 18 +++++- frontend/src/components/ExportsSection.tsx | 47 ++++++++++++++- frontend/src/components/Sidebar.tsx | 62 ++++++++++++++++--- frontend/src/lib/addTracks.ts | 69 ++++++++++++++++++++++ frontend/src/lib/confirm.tsx | 22 ++++--- frontend/src/lib/drag.tsx | 28 +++++++++ frontend/src/lib/playlistTree.ts | 10 ++++ 8 files changed, 246 insertions(+), 23 deletions(-) create mode 100644 frontend/src/lib/addTracks.ts create mode 100644 frontend/src/lib/playlistTree.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a50b2ea..3bf86d7 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -4,6 +4,7 @@ import type { ColumnSizingState, SortingState, VisibilityState } from '@tanstack import { CapabilitiesContext, slotLabeller } from './lib/capabilities' import { removalNote, writeHint } from './lib/platformCopy' import { invalidateTrackLists } from './lib/trackQueries' +import { addTracksToPlaylist } from './lib/addTracks' import { api, type AnalyzeOptions, type AnalyzeResult, type CueBatchResult, type AutoCueSlot, type PlaylistNode, type StemBatchResult, type Track, type TrackOrigin } from './api' import { confirmDiscardUnsaved } from './lib/unsaved' import { @@ -342,20 +343,20 @@ export default function App() { }, [refreshExport, exportSets.data, notify, onError], ) + // The same path as a drop on a sidebar playlist (lib/addTracks.ts), so the + // menu and the drag ask about duplicates alike. + const duplicatesAllowed = !!capabilities.data?.playlists.duplicates const addToPlaylist = useCallback( async (uuid: string, ids: string[]) => { try { - const res = await api.addEntries(uuid, ids) - qc.invalidateQueries({ queryKey: ['state'] }) - qc.invalidateQueries({ queryKey: ['playlists'] }) - qc.invalidateQueries({ queryKey: ['playlist', uuid] }) const name = addablePlaylists.find((p) => p.id === uuid)?.name ?? 'playlist' - notify('success', `Added ${res.added} track${res.added === 1 ? '' : 's'} to ${name}`) + const msg = await addTracksToPlaylist({ qc, playlist: { id: uuid, name }, ids, duplicatesAllowed }) + if (msg) notify('success', msg) } catch (e) { onError((e as Error).message) } }, - [qc, addablePlaylists, notify, onError], + [qc, addablePlaylists, duplicatesAllowed, notify, onError], ) const removeFromExport = useCallback( async (id: string, ids: string[]) => { diff --git a/frontend/src/components/ConfirmDialog.tsx b/frontend/src/components/ConfirmDialog.tsx index 62dcb22..dc8444b 100644 --- a/frontend/src/components/ConfirmDialog.tsx +++ b/frontend/src/components/ConfirmDialog.tsx @@ -10,6 +10,10 @@ export interface ConfirmRequest { /** `danger` (default) for destructive actions — a pink button; `primary` * for a caution that is not destruction, e.g. switching library. */ tone?: 'danger' | 'primary' + /** A second way to go ahead, as a plain button beside the confirm one + * (e.g. "Add them again" next to "Add 6 new"). Enter still means confirm. */ + altLabel?: string + onAlt?: () => void onConfirm: () => Promise | void } @@ -19,7 +23,7 @@ interface Props extends ConfirmRequest { /** A yes/no confirmation for destructive actions. Enter confirms and Esc * cancels, so a confirmed Delete key stays a two-keystroke action. */ -export function ConfirmDialog({ title, body, confirmLabel, tone = 'danger', onConfirm, onClose }: Props) { +export function ConfirmDialog({ title, body, confirmLabel, tone = 'danger', altLabel, onAlt, onConfirm, onClose }: Props) { const [busy, setBusy] = useState(false) const confirm = async () => { @@ -69,6 +73,18 @@ export function ConfirmDialog({ title, body, confirmLabel, tone = 'danger', onCo > Cancel + {altLabel && onAlt && ( + + )}