T-012: Bibliothek komplett — Cover-Raster, Suche (Titel/Autor/Sprecher), Sortierung (5 Optionen), Status-Chips (lokal/fertig), Fortschrittsbalken

This commit is contained in:
2026-11-06 19:40:47 +01:00
parent 7b63719e41
commit 5ef2eb0145
5 changed files with 245 additions and 46 deletions

View File

@ -2,6 +2,7 @@
import { authStatus, startLogin, getLibrary, type Book } from './lib/audible'
type View = 'loading' | 'login' | 'library'
type SortKey = 'added' | 'title' | 'author' | 'runtime' | 'percent'
let view = $state<View>('loading')
let loadingMsg = $state<string>('Prüfe Anmeldung…')
@ -12,6 +13,40 @@
let checking = $state(false)
let pollTimer = $state<ReturnType<typeof setInterval> | null>(null)
let query = $state('')
let sortBy = $state<SortKey>('added')
const filtered = $derived.by(() => {
const q = query.trim().toLowerCase()
const hits = books.filter((b) => {
if (!q) return true
return (
b.title.toLowerCase().includes(q) ||
b.authors.toLowerCase().includes(q) ||
b.narrators.toLowerCase().includes(q)
)
})
const cmp: Record<SortKey, (a: Book, b: Book) => number> = {
added: (a, b) => b.date_added.localeCompare(a.date_added),
title: (a, b) => a.title.localeCompare(b.title, 'de'),
author: (a, b) => a.authors.localeCompare(b.authors, 'de') || a.title.localeCompare(b.title, 'de'),
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])
})
function fmtRuntime(min: number): string {
if (!min || min <= 0) return ''
const h = Math.floor(min / 60)
const m = min % 60
return m ? `${h} h ${m} min` : `${h} h`
}
function hideBrokenCover(e: Event): void {
;(e.currentTarget as HTMLElement).style.display = 'none'
}
function clearPoll() {
if (pollTimer !== null) {
clearInterval(pollTimer)
@ -108,29 +143,61 @@
<main>
<header class="bar">
<h1>Hörwerk</h1>
<span class="muted">{books.length} Titel</span>
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>Aushang prüfen</button>
<span class="muted small">{filtered.length} / {books.length} Titel</span>
<input
class="search"
type="search"
placeholder="Suche Titel, Autor, Sprecher…"
bind:value={query}
/>
<select bind:value={sortBy}>
<option value="added">Zuletzt hinzugefügt</option>
<option value="title">Titel A–Z</option>
<option value="author">Autor</option>
<option value="runtime">Laufzeit</option>
<option value="percent">Fortschritt</option>
</select>
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>
{checking ? '…' : 'Auffrischen'}
</button>
</header>
{#if error}
<p class="error">{error}</p>
<div class="statespace">
<p class="error">{error}</p>
<button class="ghost" onclick={() => checkAuth()} disabled={checking}>Nochmal versuchen</button>
</div>
{:else if filtered.length === 0}
<div class="statespace">
<p class="muted">{query ? 'Kein Treffer für „' + query + '“' : 'Bibliothek leer.'}</p>
</div>
{:else}
<table>
<thead>
<tr><th>Titel</th><th>Autor</th><th>Sprecher</th><th class="num">Min</th></tr>
</thead>
<tbody>
{#each books as b (b.asin)}
<tr>
<td>{b.title}</td>
<td>{b.authors}</td>
<td>{b.narrators}</td>
<td class="num">{b.runtime_length_min}</td>
</tr>
{/each}
</tbody>
</table>
<p class="muted footnote">Bibliotheksansicht minimal (T-012: Cover, Suche, Sortierung, Status).</p>
<div class="grid">
{#each filtered as b (b.asin)}
<article class="card">
<div class="cover">
<img
src={b.cover_url}
alt="Cover von {b.title}"
loading="lazy"
onerror={hideBrokenCover}
/>
</div>
<div class="meta">
<div class="t">{b.title}</div>
<div class="muted small">{b.authors}</div>
<div class="chips">
{#if b.local}<span class="chip ok" title="book.m4b liegt lokal vor">lokal</span>{/if}
{#if b.is_finished}<span class="chip done">fertig</span>{/if}
{#if b.runtime_length_min > 0}<span class="chip">{fmtRuntime(b.runtime_length_min)}</span>{/if}
</div>
{#if b.percent_complete > 0}
<div class="progress"><div class="fill" style={`width:${b.percent_complete}%`}></div></div>
{/if}
</div>
</article>
{/each}
</div>
{/if}
</main>
{/if}