Bibliothek: Gruppieren nach Autor / Serie / Genre (Gruppen-Überschriften mit Zähler; Serie über Bulk-API mit 24-h-Cache)
This commit is contained in:
@ -32,6 +32,8 @@
|
||||
autostartEnabled,
|
||||
autostartSet,
|
||||
bookDetails,
|
||||
bookSeriesBulk,
|
||||
type SerieRef,
|
||||
type BookExtra,
|
||||
type Bm,
|
||||
type Book,
|
||||
@ -54,6 +56,10 @@
|
||||
let query = $state('')
|
||||
let sortBy = $state<SortKey>('added')
|
||||
let onlyLocal = $state(false)
|
||||
let groupBy = $state<'aus' | 'autor' | 'serie' | 'genre'>('aus')
|
||||
let seriesMap = $state<Record<string, SerieRef>>({})
|
||||
let seriesLoading = $state(false)
|
||||
let seriesLoaded = $state(false)
|
||||
let downloads = $state<Record<string, DlItem>>({})
|
||||
let loadedOverride = $state<Record<string, boolean>>({})
|
||||
let removedLocals = $state<Record<string, boolean>>({})
|
||||
@ -268,9 +274,50 @@
|
||||
runtime: (a, b) => b.runtime_length_min - a.runtime_length_min,
|
||||
percent: (a, b) => b.percent_complete - a.percent_complete,
|
||||
}
|
||||
return [...hits].sort(cmp[sortBy])
|
||||
return [...hits].sort(cmp[sortBy])
|
||||
})
|
||||
|
||||
const groups = $derived.by(() => {
|
||||
if (groupBy === 'aus') {
|
||||
return [{ key: '', books: filtered }]
|
||||
}
|
||||
const val = (b: Book): string => {
|
||||
if (groupBy === 'autor') {
|
||||
return (b.authors.split(',')[0] || '— ohne Autor').trim()
|
||||
}
|
||||
if (groupBy === 'genre') {
|
||||
return (b.genres.split(',')[0] || '— ohne Genre').trim()
|
||||
}
|
||||
const sr = seriesMap[b.asin]
|
||||
return sr ? `${sr.title}` : '— ohne Serie'
|
||||
}
|
||||
const map = new Map<string, Book[]>()
|
||||
for (const b of filtered) {
|
||||
const k = val(b)
|
||||
const list = map.get(k)
|
||||
if (list) list.push(b)
|
||||
else map.set(k, [b])
|
||||
}
|
||||
return [...map.entries()]
|
||||
.map(([key, books]) => ({ key, books }))
|
||||
.sort((a, b) => a.key.localeCompare(b.key, 'de'))
|
||||
})
|
||||
|
||||
async function loadSeries(): Promise<void> {
|
||||
if (seriesLoaded || seriesLoading || groupBy !== 'serie') return
|
||||
seriesLoading = true
|
||||
error = ''
|
||||
try {
|
||||
const m = await bookSeriesBulk(false)
|
||||
seriesMap = m
|
||||
seriesLoaded = true
|
||||
} catch (e) {
|
||||
info = `Serien konnten nicht geladen werden: ${e}`
|
||||
} finally {
|
||||
seriesLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
function fmtRuntime(min: number): string {
|
||||
if (!min || min <= 0) return ''
|
||||
const h = Math.floor(min / 60)
|
||||
@ -580,6 +627,21 @@
|
||||
<option value="runtime">Laufzeit</option>
|
||||
<option value="percent">Fortschritt</option>
|
||||
</select>
|
||||
<select
|
||||
class="speedsel"
|
||||
title="Gruppieren"
|
||||
value={groupBy}
|
||||
onchange={(e) => {
|
||||
const v = e.currentTarget.value as typeof groupBy
|
||||
groupBy = v
|
||||
if (groupBy === 'serie') loadSeries()
|
||||
}}
|
||||
>
|
||||
<option value="aus">Gruppieren: aus</option>
|
||||
<option value="autor">nach Autor</option>
|
||||
<option value="serie">{seriesLoading ? 'nach Serie (lade…)' : 'nach Serie'}</option>
|
||||
<option value="genre">nach Genre</option>
|
||||
</select>
|
||||
<button
|
||||
class="ghost"
|
||||
class:activechip={onlyLocal}
|
||||
@ -603,8 +665,7 @@
|
||||
<p class="muted">{query ? 'Kein Treffer für „' + query + '“' : 'Bibliothek leer.'}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="grid">
|
||||
{#each filtered as b (b.asin)}
|
||||
{#snippet card(b: Book)}
|
||||
{@const d = downloads[b.asin]}
|
||||
{@const dlg = activeDl(b)}
|
||||
<article class="card">
|
||||
@ -694,8 +755,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{/each}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#each groups as g, gi}
|
||||
{#if groupBy !== 'aus'}
|
||||
<h3 class="grouphead" id={gi === 0 ? '' : `group-${gi}`}>
|
||||
{g.key} <span class="muted small">({g.books.length})</span>
|
||||
</h3>
|
||||
{/if}
|
||||
<div class="grid">
|
||||
{#each g.books as b (b.asin)}
|
||||
{@render card(b)}
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
{#if player.loaded}
|
||||
|
||||
14
src/app.css
14
src/app.css
@ -581,3 +581,17 @@ code {
|
||||
color: var(--fg);
|
||||
margin: 0 0 0.4rem;
|
||||
}
|
||||
|
||||
/* Gruppen-Überschriften (Autoren/Serien/Genres) */
|
||||
|
||||
.grouphead {
|
||||
margin: 0.6rem 1.2rem 0.2rem;
|
||||
font-size: 1rem;
|
||||
color: var(--accent);
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.grouphead .muted {
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
|
||||
@ -84,6 +84,13 @@ export const bmSetNote = (asin: string, index: number, note: string) =>
|
||||
export const autostartEnabled = () => invoke<boolean>('autostart_enabled')
|
||||
export const autostartSet = (on: boolean) => invoke<void>('autostart_set', { on })
|
||||
|
||||
export interface SerieRef {
|
||||
title: string
|
||||
sequence: number
|
||||
}
|
||||
export const bookSeriesBulk = (refresh = false) =>
|
||||
invoke<Record<string, SerieRef>>('book_series_bulk', { refresh })
|
||||
|
||||
export interface BookExtra {
|
||||
description: string
|
||||
language: string
|
||||
|
||||
Reference in New Issue
Block a user