diff --git a/src/App.svelte b/src/App.svelte index 6ed8eb1..d2260bc 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -327,6 +327,36 @@ .sort((a, b) => a.key.localeCompare(b.key, 'de')) }) + let menuOpen = $state<'sort' | 'group' | null>(null) + + const SORTS: { key: SortKey; label: string; icon: string }[] = [ + { key: 'added', label: 'Zuletzt hinzugefügt', icon: 'clock' }, + { key: 'title', label: 'Titel A–Z', icon: 'alpha' }, + { key: 'author', label: 'Autor', icon: 'user' }, + { key: 'runtime', label: 'Laufzeit', icon: 'hourglass' }, + { key: 'percent', label: 'Fortschritt', icon: 'chart' }, + ] + const GROUPS: { key: typeof groupBy; label: string; icon: string }[] = [ + { key: 'aus', label: 'Gruppieren: aus', icon: 'x' }, + { key: 'autor', label: 'nach Autor', icon: 'user' }, + { key: 'serie', label: 'nach Serie', icon: 'stack' }, + { key: 'genre', label: 'nach Genre', icon: 'tag' }, + ] + + const sortIcon = $derived(SORTS.find((o) => o.key === sortBy)?.icon ?? 'clock') + const sortLabel = $derived('Sortierung: ' + (SORTS.find((o) => o.key === sortBy)?.label ?? '')) + const groupLabel = $derived( + groupBy === 'aus' + ? 'Gruppieren: aus' + : 'Gruppierung: ' + (GROUPS.find((o) => o.key === groupBy)?.label ?? '') + ) + + // Schließen bei Klick außerhalb + function onDocClick(ev: MouseEvent): void { + const t = ev.target as HTMLElement | null + if (!t?.closest('.hwdropdown') && menuOpen) menuOpen = null + } + async function loadSeries(): Promise { if (seriesLoaded || seriesLoading || groupBy !== 'serie') return seriesLoading = true @@ -609,6 +639,7 @@ } } window.addEventListener('keydown', onKey) + document.addEventListener('click', onDocClick) checkAuth() const unlistenLogin = onLoginUrl((u) => { loginUrl = u }) const unlisten = onDownloadUpdate((it) => { @@ -636,6 +667,7 @@ clearPoll() clearInterval(syncId) window.removeEventListener('keydown', onKey) +document.removeEventListener('click', onDocClick) unlisten.then((f) => f()) unlistenPlayer.then((f) => f()) unlistenLogin.then((f: () => void) => f()) @@ -723,28 +755,45 @@ placeholder="Suche Titel, Autor, Sprecher…" bind:value={query} /> - - +
+ + {#if menuOpen === 'sort'} + + {/if} +
+
+ + {#if menuOpen === 'group'} + + {/if} +