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' import { StemsSettings } from './StemsSettings' interface Props { onOpenPathMapping: () => void /** Open the menu above the button — for a button at the bottom of the window. */ up?: boolean } /** 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. const remappable = useCaps().paths.remappable const collection = useQuery({ queryKey: ['collection'], queryFn: api.collection }) const remote = !!collection.data?.library?.remote useEffect(() => { if (!open) return const onDoc = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false) } document.addEventListener('mousedown', onDoc) return () => document.removeEventListener('mousedown', onDoc) }, [open]) const item = 'flex w-full flex-col items-start rounded-[10px] px-2.5 py-1.5 text-left hover:bg-ink-800' return (
{open && (
{remappable && ( )} {remote && ( )}
)} {showShortcuts && setShowShortcuts(false)} />} {showStems && setShowStems(false)} />} {showCache && setShowCache(false)} />} {showApp && setShowApp(false)} />}
) }