mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-29 02:32:51 +01:00
136 lines
5.4 KiB
TypeScript
136 lines
5.4 KiB
TypeScript
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<HTMLDivElement>(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 (
|
|
<div ref={ref} className="relative">
|
|
<button
|
|
onClick={() => setOpen((o) => !o)}
|
|
className="btn-glass flex h-10 w-10 items-center justify-center rounded-full text-muted hover:text-text"
|
|
title="Settings"
|
|
aria-label="Settings"
|
|
>
|
|
<svg
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
strokeWidth="1.8"
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
className="h-[18px] w-[18px]"
|
|
>
|
|
<circle cx="12" cy="12" r="3" />
|
|
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" />
|
|
</svg>
|
|
</button>
|
|
{open && (
|
|
<div
|
|
className={`glass-overlay absolute right-0 z-30 w-60 !rounded-2xl p-1.5 ${
|
|
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={() => {
|
|
onOpenPathMapping()
|
|
setOpen(false)
|
|
}}
|
|
className={item}
|
|
>
|
|
<span className="text-sm text-text">Path remapping…</span>
|
|
<span className="text-[11px] text-faint">
|
|
Point the collection at moved or relocated files
|
|
</span>
|
|
</button>
|
|
)}
|
|
{remote && (
|
|
<button
|
|
onClick={() => {
|
|
setShowCache(true)
|
|
setOpen(false)
|
|
}}
|
|
className={item}
|
|
>
|
|
<span className="text-sm text-text">Remote audio…</span>
|
|
<span className="text-[11px] text-faint">This computer's copies of the server's tracks</span>
|
|
</button>
|
|
)}
|
|
<button
|
|
onClick={() => {
|
|
setShowStems(true)
|
|
setOpen(false)
|
|
}}
|
|
className={item}
|
|
>
|
|
<span className="text-sm text-text">Stems…</span>
|
|
<span className="text-[11px] text-faint">The stem engine, device and conversion defaults</span>
|
|
</button>
|
|
<button
|
|
onClick={() => {
|
|
setShowShortcuts(true)
|
|
setOpen(false)
|
|
}}
|
|
className={item}
|
|
>
|
|
<span className="text-sm text-text">View Shortcuts</span>
|
|
<span className="text-[11px] text-faint">Every keyboard shortcut in one list</span>
|
|
</button>
|
|
</div>
|
|
)}
|
|
{showShortcuts && <ShortcutsDialog onClose={() => setShowShortcuts(false)} />}
|
|
{showStems && <StemsSettings onClose={() => setShowStems(false)} />}
|
|
{showCache && <RemoteCacheSettings onClose={() => setShowCache(false)} />}
|
|
{showApp && <AppSettings onClose={() => setShowApp(false)} />}
|
|
</div>
|
|
)
|
|
}
|