diff --git a/CLAUDE.md b/CLAUDE.md index aa5d405..686ffaa 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -353,7 +353,8 @@ Two independent apps that talk over HTTP: slot, a per-slot Replace tick for occupied slots — never remembered, since overwriting is a decision about THIS track — and the template itself persisted as `autoCueTemplate` in userprefs), - `SelectionBar` (bulk add-to-playlist), `ContextMenu` + `EditTagsDialog` + `ContextMenu` (supports `▸` submenus and section headings; "Add to" lists + playlists + exports and acts on the whole selection) + `EditTagsDialog` (right-click → multi-field metadata + album-art edit), `StatusBar`, `RatingStars` (read-only, or click-to-set when given `onChange`), `Toast`, `UpdateDialog` (`UpdateCheck`, mounted in `main.tsx` beside `App` so it shows @@ -394,7 +395,7 @@ Two independent apps that talk over HTTP: the digit shortcuts all read `cues.hotcue_slots`), the cue-type dropdown (`cues.types`), the rating scale (`tracks.rating_max`), the grid Lock button (`grid.lockable`). Per-node playlist flags (`can_rename`, `can_delete`, - `can_add_tracks`) gate the sidebar and `SelectionBar` — each on its OWN flag, + `can_add_tracks`) gate the sidebar and the context menu's "Add to" — each on its OWN flag, since a platform may allow renaming but not deleting. Carried but deliberately unused until a second adapter exists: `slot_labels: 'letter'`, `palette`, `loops: 'separate_bank'`, and memory-cue *editing* (one-platform features stay preserved-but-uneditable). @@ -790,8 +791,8 @@ that number and nothing else — everything derives from it: tests. Exporters declare **static** capabilities: no instance, no path, because the library being described does not exist yet. **Steps 1–3 done**: `library_id.py`; `exports.py` + 10 routes + `api.ts`; and - the UI (`ExportsSection`, `ExportDialog`, export views in `App`, "Add to…" on - `SelectionBar`, the track context menu and each sidebar playlist row). + the UI (`ExportsSection`, `ExportDialog`, export views in `App`, "Add to" on + the track context menu and each sidebar playlist row). Next: `core/exporter.py` + the Traktor writer, and the export run itself on top of `jobs.py` and `importer.py`'s copy machinery — **there is no Export button yet**, since nothing can be written. Note the OneLibrary work already demonstrated diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 68b97db..ca022bd 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -3,7 +3,7 @@ import { useQuery, useQueryClient } from '@tanstack/react-query' import type { ColumnSizingState, SortingState, VisibilityState } from '@tanstack/react-table' import { CapabilitiesContext } from './lib/capabilities' import { writeHint } from './lib/platformCopy' -import { api, type Track } from './api' +import { api, type PlaylistNode, type Track } from './api' import { DEFAULT_COLUMN_ORDER, DEFAULT_COLUMN_VISIBILITY, @@ -11,11 +11,10 @@ import { import { Sidebar, type Source } from './components/Sidebar' import { Toolbar, emptyFilters, type Filters } from './components/Toolbar' import { TrackTable, PlaylistTable } from './components/TrackTable' -import { SelectionBar } from './components/SelectionBar' import { StatusBar } from './components/StatusBar' import { Toast, type ToastMsg } from './components/Toast' import { CollectionPicker } from './components/CollectionPicker' -import { ContextMenu } from './components/ContextMenu' +import { ContextMenu, type MenuItem } from './components/ContextMenu' import { EditTagsDialog } from './components/EditTagsDialog' import { PathMappingDialog } from './components/PathMappingDialog' import { HistoryPanel } from './components/HistoryPanel' @@ -236,6 +235,15 @@ export default function App() { }) const openDevice = useQuery({ queryKey: ['source'], queryFn: api.source }) const exportSets = useQuery({ queryKey: ['exports'], queryFn: api.exports, enabled: loaded }) + const playlists = useQuery({ queryKey: ['playlists'], queryFn: api.playlists, enabled: loaded }) + // Every playlist the context menu's "Add to" can target, flattened out of + // folders. Each node carries its own `can_add_tracks`, so a read-only library + // simply offers none. + const addablePlaylists = useMemo(() => { + const walk = (nodes: PlaylistNode[]): PlaylistNode[] => + nodes.flatMap((n) => [...(n.can_add_tracks ? [n] : []), ...walk(n.children)]) + return walk(playlists.data ?? []) + }, [playlists.data]) // 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. @@ -260,6 +268,21 @@ export default function App() { }, [refreshExport, exportSets.data, notify, onError], ) + 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}`) + } catch (e) { + onError((e as Error).message) + } + }, + [qc, addablePlaylists, notify, onError], + ) const removeFromExport = useCallback( async (id: string, ids: string[]) => { try { @@ -407,6 +430,28 @@ export default function App() { y, }) + // The "Add to" submenu. Exports are listed even on a read-only library: + // adding to one touches no library data — an export is Konduktor's own + // curation. The playlist being viewed is left out; adding a track to the + // playlist it came from would only duplicate it. + const addToItems = (ids: string[]): MenuItem[] => { + const lists = addablePlaylists.filter((p) => !(source.kind === 'playlist' && p.id === source.id)) + return [ + { heading: 'Playlists', empty: lists.length ? undefined : 'No playlists' }, + ...lists.map((p) => ({ + label: p.name, + hint: String(p.count), + onClick: () => addToPlaylist(p.id, ids), + })), + { heading: 'Exports', empty: exportSets.data?.length ? undefined : 'No exports yet' }, + ...(exportSets.data ?? []).map((set) => ({ + label: set.name, + icon: '◈', + onClick: () => addToExport(set.id, ids), + })), + ] + } + return (
@@ -428,12 +473,9 @@ export default function App() { ...(canEdit && menu.ids.length === 1 ? [{ 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.ids), - })), + // A device's track ids belong to the stick, not the collection, so + // there is nothing they could be added to. + ...(viewingDevice ? [] : [{ label: 'Add to', submenu: addToItems(menu.ids) }]), // 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 @@ -588,7 +630,7 @@ export default function App() { 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. */ + Selection stays on, so right-click → Add to works from inside an export. */ filtered.length === 0 ? (
@@ -596,7 +638,7 @@ export default function App() {
{tracks.length === 0 - ? 'Select tracks in All Tracks and use “Add to…”, or add a whole playlist.' + ? 'Right-click tracks in All Tracks and choose Add to, or add a whole playlist.' : 'Try clearing some filters.'}
@@ -621,7 +663,7 @@ export default function App() { /* A device uses the plain table, not the playlist one: a stick's playlists cannot be reordered or have entries removed, so the drag handle and the × would exist only to be inert. Selection is - omitted for the same reason — SelectionBar adds to the loaded + omitted too: its bulk action, "Add to", targets the loaded COLLECTION's playlists, and these ids belong to the device. */ filtered.length === 0 ? (
@@ -702,23 +744,13 @@ export default function App() { /> )} - {/* Also inside an export: its rows ARE collection tracks, so "Add - to…" means the same thing there as in All Tracks. */} - {(isAll || viewingExport) && ( - setSelected(new Set())} - onDone={(msg) => notify('success', msg)} - onError={onError} - /> - )}
setForcePicker(true)} diff --git a/frontend/src/components/ContextMenu.tsx b/frontend/src/components/ContextMenu.tsx index 5fd7b2b..2fdd5a7 100644 --- a/frontend/src/components/ContextMenu.tsx +++ b/frontend/src/components/ContextMenu.tsx @@ -1,10 +1,10 @@ -import { useEffect, useRef } from 'react' +import { useEffect, useRef, useState } from 'react' -export interface MenuItem { - label: string - onClick: () => void - danger?: boolean -} +/** One row of a menu: an action, a submenu (`label ▸`), or a section heading. */ +export type MenuItem = + | { label: string; onClick: () => void; danger?: boolean; hint?: string; icon?: string } + | { label: string; submenu: MenuItem[] } + | { heading: string; empty?: string } interface Props { x: number @@ -13,8 +13,12 @@ interface Props { onClose: () => void } +const SUBMENU_WIDTH = 240 +const SUBMENU_MAX_HEIGHT = 288 + // Lightweight fixed-position menu. Closes on outside click, scroll, or Escape. export function ContextMenu({ x, y, items, onClose }: Props) { + const rootRef = useRef(null) // Read through a ref so the listeners are attached ONCE. Callers pass an // inline `onClose`; if the effect depended on it, a click that re-renders the // parent (e.g. selecting a row) would detach the listeners before the @@ -23,47 +27,124 @@ export function ContextMenu({ x, y, items, onClose }: Props) { onCloseRef.current = onClose useEffect(() => { const close = () => onCloseRef.current() + // Scrolling a long submenu must not dismiss the menu it belongs to. + const onScroll = (e: Event) => { + if (e.target instanceof Node && rootRef.current?.contains(e.target)) return + close() + } const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onCloseRef.current() // Defer attaching outside-dismiss listeners by a tick so the very // right-click/click that opened the menu can't immediately close it. const id = setTimeout(() => { window.addEventListener('click', close) window.addEventListener('contextmenu', close) - window.addEventListener('scroll', close, true) + window.addEventListener('scroll', onScroll, true) window.addEventListener('keydown', onKey) }, 0) return () => { clearTimeout(id) window.removeEventListener('click', close) window.removeEventListener('contextmenu', close) - window.removeEventListener('scroll', close, true) + window.removeEventListener('scroll', onScroll, true) window.removeEventListener('keydown', onKey) } }, []) return ( -
e.stopPropagation()} - > - {items.map((item, i) => ( - - ))} +
e.stopPropagation()}> +
) } + +function MenuPanel({ + items, + onClose, + className = '', + style, +}: { + items: MenuItem[] + onClose: () => void + className?: string + style: React.CSSProperties +}) { + // The open submenu: which row, and where to draw it. Fixed-positioned from + // the row's rect, flipping left / up when it would run off the window. + const [open, setOpen] = useState<{ index: number; style: React.CSSProperties } | null>(null) + + const openSubmenu = (index: number, row: HTMLElement) => { + const r = row.getBoundingClientRect() + const left = + r.right + SUBMENU_WIDTH > window.innerWidth ? Math.max(0, r.left - SUBMENU_WIDTH) : r.right + const top = Math.max(8, Math.min(r.top - 4, window.innerHeight - SUBMENU_MAX_HEIGHT - 8)) + setOpen({ index, style: { left, top, width: SUBMENU_WIDTH, maxHeight: SUBMENU_MAX_HEIGHT } }) + } + + const openItem = open ? items[open.index] : null + + return ( + <> +
+ {items.map((item, i) => { + if ('heading' in item) { + return ( +
+
+ {item.heading} +
+ {item.empty &&
{item.empty}
} +
+ ) + } + if ('submenu' in item) { + return ( + + ) + } + return ( + + ) + })} +
+ {open && openItem && 'submenu' in openItem && ( + + )} + + ) +} diff --git a/frontend/src/components/ExportsSection.tsx b/frontend/src/components/ExportsSection.tsx index f294ed1..fedbf37 100644 --- a/frontend/src/components/ExportsSection.tsx +++ b/frontend/src/components/ExportsSection.tsx @@ -279,7 +279,7 @@ function ExportRow({ {expanded && data && data.tracks === 0 && (
- Empty — select tracks and use “Add to…”. + Empty — right-click tracks and choose Add to.
)} diff --git a/frontend/src/components/SelectionBar.tsx b/frontend/src/components/SelectionBar.tsx deleted file mode 100644 index 62c57c6..0000000 --- a/frontend/src/components/SelectionBar.tsx +++ /dev/null @@ -1,123 +0,0 @@ -import { useState } from 'react' -import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' -import { api, type PlaylistNode } from '../api' - -interface Props { - count: number - trackIds: string[] - onClear: () => void - onDone: (msg: string) => void - onError: (msg: string) => void -} - -function flattenPlaylists(nodes: PlaylistNode[]): PlaylistNode[] { - return nodes.flatMap((n) => [ - ...(n.can_add_tracks ? [n] : []), - ...flattenPlaylists(n.children), - ]) -} - -// Floating action bar shown when tracks are selected in the explorer. -export function SelectionBar({ count, trackIds, onClear, onDone, onError }: Props) { - 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), - onSuccess: (res, vars) => { - qc.invalidateQueries({ queryKey: ['state'] }) - qc.invalidateQueries({ queryKey: ['playlists'] }) - qc.invalidateQueries({ queryKey: ['playlist', vars.uuid] }) - const pl = flat.find((p) => p.id === vars.uuid) - onDone(`Added ${res.added} track${res.added === 1 ? '' : 's'} to ${pl?.name ?? 'playlist'}`) - setMenuOpen(false) - onClear() - }, - onError: (e: Error) => onError(e.message), - }) - - if (count === 0) return null - - return ( -
-
- - {count} selected - -
- - {menuOpen && ( -
-
- Playlists -
- {flat.length === 0 && ( -
No playlists yet
- )} - {flat.map((p) => ( - - ))} - -
- Exports -
- {sets.length === 0 && ( -
No exports yet
- )} - {sets.map((set) => ( - - ))} -
- )} -
- -
-
- ) -} diff --git a/frontend/src/components/StatusBar.tsx b/frontend/src/components/StatusBar.tsx index b69a887..f973661 100644 --- a/frontend/src/components/StatusBar.tsx +++ b/frontend/src/components/StatusBar.tsx @@ -2,6 +2,8 @@ interface Props { showing: number total: number sourceName: string + /** Rows currently selected; shown only when non-zero. */ + selected?: number loading?: boolean collectionName?: string | null onChangeCollection?: () => void @@ -11,6 +13,7 @@ export function StatusBar({ showing, total, sourceName, + selected = 0, loading, collectionName, onChangeCollection, @@ -32,6 +35,12 @@ export function StatusBar({ )} )} + {selected > 0 && ( + <> + · + {selected.toLocaleString()} selected + + )} {collectionName && (