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}

View File

@ -6,6 +6,7 @@
--fg-muted: #9aa0a8;
--accent: #c2762f;
--error: #d4645c;
--ok: #6fa06b;
--border: #2a2e36;
}
@ -30,6 +31,7 @@ h1 {
font-size: 1.4rem;
font-weight: 600;
margin: 0;
white-space: nowrap;
}
.muted {
@ -37,19 +39,40 @@ h1 {
line-height: 1.5;
}
.small {
font-size: 0.86rem;
}
.bar {
display: flex;
align-items: center;
gap: 1rem;
gap: 0.7rem;
padding: 0.8rem 1.2rem;
border-bottom: 1px solid var(--border);
position: sticky;
top: 0;
background: var(--bg);
z-index: 1;
}
.bar .muted {
white-space: nowrap;
}
.input,
.bar input,
.bar select {
border: 1px solid var(--border);
border-radius: 6px;
padding: 0.4rem 0.7rem;
background: var(--bg-card);
color: var(--fg);
font-size: 0.92rem;
}
.bar input.search {
flex: 1;
min-width: 12rem;
}
button {
@ -59,6 +82,8 @@ button {
background: var(--bg-card);
color: var(--fg);
cursor: pointer;
font-size: 0.92rem;
white-space: nowrap;
}
button:hover:enabled {
@ -81,29 +106,6 @@ button.ghost {
background: transparent;
}
table {
width: calc(100% - 2.4rem);
margin: 1rem 1.2rem;
border-collapse: collapse;
}
th,
td {
border-bottom: 1px solid var(--border);
padding: 0.4rem 0.6rem;
text-align: left;
}
th.num,
td.num {
text-align: right;
}
.footnote {
margin: 0.6rem 1.2rem 2rem;
font-size: 0.85rem;
}
.info {
color: #7fa9d4;
}
@ -111,3 +113,107 @@ td.num {
.error {
color: var(--error);
}
/* Bibliotheksraster */
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
gap: 1rem;
padding: 1rem 1.2rem 2rem;
}
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 8px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.cover {
aspect-ratio: 1 / 1;
width: 100%;
background: linear-gradient(160deg, #262a31, #1b1e24);
position: relative;
}
.cover img {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.meta {
padding: 0.55rem 0.65rem 0.7rem;
display: flex;
flex-direction: column;
gap: 0.3rem;
flex: 1;
}
.meta .t {
font-size: 0.92rem;
font-weight: 600;
line-height: 1.25;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 0.3rem;
margin-top: auto;
padding-top: 0.25rem;
}
.chip {
font-size: 0.72rem;
padding: 0.1rem 0.45rem;
border: 1px solid var(--border);
border-radius: 99px;
color: var(--fg-muted);
}
.chip.ok {
color: var(--ok);
border-color: var(--ok);
}
.chip.done {
color: var(--accent);
border-color: var(--accent);
}
.progress {
height: 3px;
border-radius: 2px;
background: var(--border);
overflow: hidden;
}
.progress .fill {
height: 100%;
background: var(--accent);
}
.statespace {
display: flex;
flex-direction: column;
gap: 0.8rem;
align-items: flex-start;
padding: 2.4rem 1.2rem;
}
code {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 4px;
padding: 0.05rem 0.3rem;
}

View File

@ -15,6 +15,8 @@ export interface Book {
cover_url: string
percent_complete: number
is_finished: boolean
date_added: string
local: boolean
}
export const authStatus = () => invoke<AuthStatus>('auth_status')