Added konduktor settings menu

This commit is contained in:
patben8 committed 2026-10-12 10:15:14 +02:00
1 parent 40630ff78e
commit 2c352b76a1
5 files changed
+185 -14

No files matched your search

+1 -1
View File
@@ -876,7 +876,7 @@ Two independent apps that talk over HTTP:
user), quits (`quit_now`) when nothing is unsaved, else asks Save · Discard
· Cancel; the sidecar is killed only at `RunEvent::Exit`, after the answer;
browser dev gets `beforeunload`), `SaveBar` (+ "Discard changes…" when
dirty, and the settings gear beside it, whose menu opens `ShortcutsDialog` — the shortcut list is written out BY HAND, so a new or changed shortcut in `PrepStrip` / `TrackTable` must be added there too), `Toolbar` (search/filters; columns are chosen by right-clicking the table header),
dirty, and the settings gear beside it, whose menu opens `ShortcutsDialog` — the shortcut list is written out BY HAND, so a new or changed shortcut in `PrepStrip` / `TrackTable` must be added there too — and `AppSettings` ("Konduktor Settings…": app-level prefs, each with its default in `APP_SETTING_DEFAULTS` and read through `useAppSetting`; today `expandPlaylistFolders`, default off. The Sidebar holds folder open state as per-id overrides of that setting, reset on a new library or a change of the setting, and carried to the new ids when a rename/move changes a folder's path id)), `Toolbar` (search/filters; columns are chosen by right-clicking the table header),
`TrackTable` (**the one track list** — All Tracks, playlists, exports and
devices. TanStack Table + **virtualized** grid; per-row play button,
configurable columns, header sorting, inline double-click editing, and
+88
View File
@@ -0,0 +1,88 @@
import { createPortal } from 'react-dom'
import { useEffect, useState } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { api } from '../api'
/**
* Settings → Konduktor: preferences about the app itself rather than about a
* library or a feature (those have their own entries in the gear menu). Each
* setting is a pref in userprefs.json, written as soon as it is changed.
*/
/** The prefs this dialog owns, and what each is when never set. */
export const APP_SETTING_DEFAULTS = {
expandPlaylistFolders: false,
}
type AppSettingKey = keyof typeof APP_SETTING_DEFAULTS
/** One app setting, read from the shared ['prefs'] query (the default until it loads). */
export function useAppSetting<K extends AppSettingKey>(key: K): (typeof APP_SETTING_DEFAULTS)[K] {
const prefs = useQuery({ queryKey: ['prefs'], queryFn: api.getPrefs }).data
const v = prefs?.[key]
return typeof v === typeof APP_SETTING_DEFAULTS[key] ? (v as (typeof APP_SETTING_DEFAULTS)[K]) : APP_SETTING_DEFAULTS[key]
}
export function AppSettings({ onClose }: { onClose: () => void }) {
const qc = useQueryClient()
const expandFolders = useAppSetting('expandPlaylistFolders')
const [error, setError] = useState<string | null>(null)
useEffect(() => {
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose])
const set = async (patch: Partial<typeof APP_SETTING_DEFAULTS>) => {
setError(null)
try {
qc.setQueryData(['prefs'], await api.patchPrefs(patch))
} catch (e) {
setError((e as Error).message)
}
}
return createPortal(
<div
aria-modal="true"
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-6 backdrop-blur-[3px]"
onClick={onClose}
>
<div className="flex w-full max-w-md flex-col overflow-hidden glass-overlay" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center justify-between border-b border-line px-5 py-3">
<h2 className="text-sm font-semibold text-text">Konduktor settings</h2>
<button onClick={onClose} className="rounded px-1.5 text-faint hover:text-text" aria-label="Close">
×
</button>
</div>
<div className="space-y-4 px-5 py-4 text-sm">
<section className="space-y-2">
<h3 className="text-[11px] font-semibold uppercase tracking-wider text-faint">Sidebar</h3>
<label className="flex cursor-pointer items-start gap-2.5">
<input
type="checkbox"
className="mt-0.5"
checked={expandFolders}
onChange={(e) => void set({ expandPlaylistFolders: e.target.checked })}
/>
<span className="min-w-0">
<span className="block text-sm text-text">Expand playlist folders by default</span>
<span className="block text-xs text-faint">
Show every folder open when a library is opened. Off, they start collapsed.
</span>
</span>
</label>
</section>
{error && <div className="text-xs text-pink">{error}</div>}
</div>
<div className="flex justify-end gap-2 border-t border-line px-5 py-3">
<button onClick={onClose} className="rounded-full btn-primary px-4 py-1.5 text-sm font-semibold">
Done
</button>
</div>
</div>
</div>,
document.body,
)
}
+16 -3
View File
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { api } from '../api'
import { AppSettings } from './AppSettings'
import { useCaps } from '../lib/capabilities'
import { RemoteCacheSettings } from './RemoteCacheSettings'
import { ShortcutsDialog } from './ShortcutsDialog'
@@ -12,14 +13,15 @@ interface Props {
up?: boolean
}
/** Overflow menu for low-frequency, collection-level settings. Currently holds
* path remapping, Stems and the shortcut list; the natural home for future advanced
* settings. The shortcuts dialog is owned here, since nothing else opens it. */
/** Overflow menu for low-frequency settings: the app's own (Konduktor
* settings), path remapping, Stems and the shortcut list. The dialogs are owned
* here, since nothing else opens them. */
export function SettingsMenu({ onOpenPathMapping, up = false }: Props) {
const [open, setOpen] = useState(false)
const [showShortcuts, setShowShortcuts] = useState(false)
const [showStems, setShowStems] = useState(false)
const [showCache, setShowCache] = useState(false)
const [showApp, setShowApp] = useState(false)
const ref = useRef<HTMLDivElement>(null)
// Path remapping is a library on THIS computer's business; a remote's
// mapping is its server's configuration.
@@ -66,6 +68,16 @@ export function SettingsMenu({ onOpenPathMapping, up = false }: Props) {
up ? 'bottom-full mb-1' : 'mt-1'
}`}
>
<button
onClick={() => {
setShowApp(true)
setOpen(false)
}}
className={item}
>
<span className="text-sm text-text">Konduktor Settings…</span>
<span className="text-[11px] text-faint">How the app behaves, whatever library is open</span>
</button>
{remappable && (
<button
onClick={() => {
@@ -117,6 +129,7 @@ export function SettingsMenu({ onOpenPathMapping, up = false }: Props) {
{showShortcuts && <ShortcutsDialog onClose={() => setShowShortcuts(false)} />}
{showStems && <StemsSettings onClose={() => setShowStems(false)} />}
{showCache && <RemoteCacheSettings onClose={() => setShowCache(false)} />}
{showApp && <AppSettings onClose={() => setShowApp(false)} />}
</div>
)
}
+57 -10
View File
@@ -6,6 +6,7 @@ import { useCaps } from '../lib/capabilities'
import { SaveBar } from './SaveBar'
import { confirmDiscardUnsaved } from '../lib/unsaved'
import { SettingsMenu } from './SettingsMenu'
import { useAppSetting } from './AppSettings'
import { DevicesSection } from './DevicesSection'
import { ExportsSection } from './ExportsSection'
import { ConfirmDialog, type ConfirmRequest } from './ConfirmDialog'
@@ -14,7 +15,7 @@ import { Icon, type IconName } from '../lib/icons'
import { PlatformIcon } from '../lib/platformIcons'
import { addTracksToPlaylist } from '../lib/addTracks'
import { useDragPayload, usePressToDrag, useDropTarget, type DragPayload } from '../lib/drag'
import { nodeIdsUnder, playlistIdsUnder } from '../lib/playlistTree'
import { findNode, idsAfter, nodeIdsUnder, playlistIdsUnder } from '../lib/playlistTree'
/**
* Which view the main table is showing.
@@ -99,8 +100,11 @@ type Draft = { kind: 'playlist' | 'folder'; parentId: string | null }
/** Actions a row can ask of the sidebar. They live there, not in the row, so
* the right-click menu and the hover buttons run the very same code. */
interface RowActions {
/** Whether a folder is open, and opening / closing it. */
isOpen: (node: PlaylistNode) => boolean
setOpen: (node: PlaylistNode, open: boolean) => void
onContextMenu: (e: React.MouseEvent, node: PlaylistNode) => void
onRename: (node: PlaylistNode, name: string) => void
onRename: (node: PlaylistNode, name: string, parentId: string | null) => void
onDelete: (node: PlaylistNode) => void
onAddToExport: (node: PlaylistNode, setId: string) => void
/** The row's export button: the export list as a menu under it. */
@@ -202,7 +206,7 @@ function NodeRow({
exportSets: { id: string; name: string }[]
actions: RowActions
}) {
const [open, setOpen] = useState(true)
const open = actions.isOpen(node)
const renaming = renamingId === node.id
const [renameDraft, setRenameDraft] = useState(node.name)
const isFolder = node.kind === 'folder'
@@ -278,9 +282,11 @@ function NodeRow({
// Holding a drag over a collapsed folder opens it, so a playlist nested in
// it can be reached without letting go.
const opening = over?.zone === 'into' || over?.zone === 'peek'
const openLater = useRef(() => actions.setOpen(node, true))
openLater.current = () => actions.setOpen(node, true)
useEffect(() => {
if (!opening || expanded) return
const t = setTimeout(() => setOpen(true), 600)
const t = setTimeout(() => openLater.current(), 600)
return () => clearTimeout(t)
}, [opening, expanded])
const ringed = over?.zone === 'tracks' || over?.zone === 'into'
@@ -314,7 +320,7 @@ function NodeRow({
)}
<button
onClick={() => {
if (isFolder) setOpen((o) => !o)
if (isFolder) actions.setOpen(node, !open)
else if (selectable) onSelect({ kind: 'playlist', id: node.id, name: node.name })
}}
className={`flex min-w-0 flex-1 items-center gap-2 py-1.5 pl-2 text-left ${
@@ -348,7 +354,7 @@ function NodeRow({
if (e.key === 'Enter') {
setRenamingId(null)
if (renameDraft.trim() && renameDraft.trim() !== node.name)
actions.onRename(node, renameDraft.trim())
actions.onRename(node, renameDraft.trim(), parentId)
} else if (e.key === 'Escape') {
setRenamingId(null)
}
@@ -469,6 +475,32 @@ export function Sidebar({
const [menu, setMenu] = useState<{ x: number; y: number; items: MenuItem[] } | null>(null)
const [confirmReq, setConfirmReq] = useState<ConfirmRequest | null>(null)
// Which folders are open: the setting, except where the user has opened or
// closed one. Held here rather than in each row, so it survives a row
// remounting and can be reset — on a new library, and when the setting
// changes (so changing it visibly does something).
const expandByDefault = useAppSetting('expandPlaylistFolders')
const [openOverrides, setOpenOverrides] = useState<Record<string, boolean>>({})
useEffect(() => setOpenOverrides({}), [library?.path, expandByDefault])
const setFolderOpen = (id: string, open: boolean) =>
setOpenOverrides((o) => ({ ...o, [id]: open }))
// A folder's id — and so every id under it — may change when it is renamed
// or moved (a platform addressing folders by path), so open state follows
// the subtree to its new ids. Reads the tree as refetched after the edit.
const carryOpen = async (before: PlaylistNode, newId: string) => {
if (before.kind !== 'folder') return
await qc.refetchQueries({ queryKey: ['playlists'] })
const after = findNode(qc.getQueryData<PlaylistNode[]>(['playlists']) ?? [], newId)
if (!after) return
const ids = idsAfter(before, after)
setOpenOverrides((o) => {
const next = { ...o }
for (const [from, to] of ids) if (from !== to && from in o) delete next[from]
for (const [from, to] of ids) if (from !== to && from in o) next[to] = o[from]
return next
})
}
const invalidate = () => {
qc.invalidateQueries({ queryKey: ['playlists'] })
qc.invalidateQueries({ queryKey: ['state'] })
@@ -487,10 +519,19 @@ export function Sidebar({
})
const rename = useMutation({
mutationFn: ({ node, name }: { node: PlaylistNode; name: string }) =>
mutationFn: ({ node, name }: { node: PlaylistNode; name: string; parentId: string | null }) =>
api.renamePlaylist(node.id, name),
onSuccess: (_d, { node, name }) => {
onSuccess: async (_d, { node, name, parentId }) => {
invalidate()
// The rename does not answer the new id, so the folder is found by its
// new name among its siblings (a folder may not share a sibling's name).
if (node.kind === 'folder') {
await qc.refetchQueries({ queryKey: ['playlists'] })
const tree = qc.getQueryData<PlaylistNode[]>(['playlists']) ?? []
const siblings = parentId === null ? tree : (findNode(tree, parentId)?.children ?? [])
const renamed = siblings.find((n) => n.kind === 'folder' && n.name === name)
if (renamed) await carryOpen(node, renamed.id)
}
if (source.kind === 'playlist' && source.id === node.id)
onSelect({ kind: 'playlist', id: node.id, name })
},
@@ -525,6 +566,9 @@ export function Sidebar({
const startDraft = (kind: Draft['kind'], parentId: string | null) => {
setRenamingId(null)
// Open the folder it goes in, or the new node would vanish into a
// collapsed folder once named.
if (parentId !== null) setFolderOpen(parentId, true)
setDraft({ kind, parentId })
}
@@ -586,8 +630,10 @@ export function Sidebar({
}
const actions: RowActions = {
isOpen: (node) => openOverrides[node.id] ?? expandByDefault,
setOpen: (node, open) => setFolderOpen(node.id, open),
onContextMenu: (e, node) => openMenu(e, nodeItems(node)),
onRename: (node, name) => rename.mutate({ node, name }),
onRename: (node, name, parentId) => rename.mutate({ node, name, parentId }),
onDelete: confirmDelete,
onAddToExport: (node, setId) => addToExport.mutate({ node, setId }),
// Opened as the shared ContextMenu rather than a popover inside the row: the
@@ -622,8 +668,9 @@ export function Sidebar({
canMove: (node) => caps.writable && node.can_move,
onMoveNode: async (node, parentId, index, into) => {
try {
await api.movePlaylist(node.id, parentId, index)
const { id } = await api.movePlaylist(node.id, parentId, index)
invalidate()
void carryOpen(node, id)
// Into a COLLAPSED folder the node vanishes from view, so say where.
if (into) onDone(`Moved “${node.name}” into ${into.name}`)
} catch (e) {
+23
View File
@@ -20,3 +20,26 @@ export function nodeIdsUnder(node: PlaylistNode): Set<string> {
walk(node)
return ids
}
/** The node with this id, anywhere in the tree. */
export function findNode(nodes: PlaylistNode[], id: string): PlaylistNode | undefined {
for (const n of nodes) {
if (n.id === id) return n
const found = findNode(n.children, id)
if (found) return found
}
return undefined
}
/** Old id → new id for a node and everything nested in it, after a rename or
* move that may have changed them (a platform addressing folders by path).
* Neither changes a subtree's shape, so the two are matched by position. */
export function idsAfter(before: PlaylistNode, after: PlaylistNode): Map<string, string> {
const map = new Map<string, string>()
const walk = (a: PlaylistNode, b: PlaylistNode) => {
map.set(a.id, b.id)
a.children.forEach((c, i) => b.children[i] && walk(c, b.children[i]))
}
walk(before, after)
return map
}