diff --git a/CLAUDE.md b/CLAUDE.md index d699892..3e46465 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 diff --git a/frontend/src/components/AppSettings.tsx b/frontend/src/components/AppSettings.tsx new file mode 100644 index 0000000..014b43c --- /dev/null +++ b/frontend/src/components/AppSettings.tsx @@ -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(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(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) => { + setError(null) + try { + qc.setQueryData(['prefs'], await api.patchPrefs(patch)) + } catch (e) { + setError((e as Error).message) + } + } + + return createPortal( +
+
e.stopPropagation()}> +
+

Konduktor settings

+ +
+
+
+

Sidebar

+ +
+ {error &&
{error}
} +
+
+ +
+
+
, + document.body, + ) +} diff --git a/frontend/src/components/SettingsMenu.tsx b/frontend/src/components/SettingsMenu.tsx index 34b857a..e9d8929 100644 --- a/frontend/src/components/SettingsMenu.tsx +++ b/frontend/src/components/SettingsMenu.tsx @@ -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(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' }`} > + {remappable && (