T-031: Lesezeichen mit Notiz — bookmarks.json, Panel in der Leiste (Sprung, Notiz editieren, delete)

This commit is contained in:
2026-11-06 20:36:38 +01:00
parent bb1fea60df
commit 06ac4ebd11
7 changed files with 275 additions and 1 deletions

View File

@ -25,6 +25,11 @@
downloadCancel,
downloadDelete,
onDownloadUpdate,
bmList,
bmAdd,
bmRemove,
bmSetNote,
type Bm,
type Book,
type DlItem,
} from './lib/audible'
@ -69,6 +74,54 @@
let sleepMode = $state<SleepMode>({ kind: 'off' })
let sleepLeft = $state<string>('')
let sleepTimer: ReturnType<typeof setInterval> | null = null
// Lesezeichen (T-031)
let bmOpen = $state(false)
let bookmarks = $state<Bm[]>([])
let bmEditIdx = $state<number | null>(null)
let bmDraft = $state('')
function openBookmarks(): void {
bmOpen = !bmOpen
if (bmOpen) {
const asin = player.asin ?? ''
bmList(asin)
.then((l) => (bookmarks = l))
.catch((e) => (error = String(e)))
}
}
function bookmarkAddHere(): void {
const asin = player.asin ?? ''
bmAdd(asin, player.position, '')
.then((l) => {
bookmarks = l
bmEditIdx = l.length - 1
bmDraft = ''
})
.catch((e) => (error = String(e)))
}
function bookmarkDel(idx: number): void {
const asin = player.asin ?? ''
bmRemove(asin, idx)
.then((l) => (bookmarks = l))
.catch((e) => (error = String(e)))
bmEditIdx = null
}
function bookmarkSave(idx: number): void {
const asin = player.asin ?? ''
bmSetNote(asin, idx, bmDraft)
.then((l) => {
bookmarks = l
bmEditIdx = null
})
.catch((e) => (error = String(e)))
}
function bookmarkJump(idx: number): void {
playerSetPosition(bookmarks[idx]?.time ?? 0)
}
function setSleep(sel: string): void {
if (sleepTimer) {
@ -594,6 +647,8 @@
value={player.position}
onchange={(e) => playerSetPosition(Number(e.currentTarget.value))}
/>
<button class="ghost iconbtn" title="Lesezeichen (Panel)" onclick={() => openBookmarks()}><Icon name="flag" size={14} /></button>
<button class="ghost iconbtn" title="Bookmark an aktueller Stelle" onclick={() => bookmarkAddHere()}><Icon name="pencil" size={14} /></button>
<button class="ghost" title="Schließen" onclick={() => playerStop()}><Icon name="x" /></button>
<span class="sleepwrap">
<Icon name="moon" size={13} />
@ -615,6 +670,32 @@
{#if sleepLeft}<span class="muted small">{sleepLeft}</span>{/if}
</span>
</footer>
{#if bmOpen && player.asin}
<div class="bmpanel">
{#if bookmarks.length === 0}
<p class="muted small">kein Lesezeichen — mit ✎ erzeugen.</p>
{/if}
{#each bookmarks as b, i}
<div class="bmrow">
<button class="ghost" title="Dorthin springen" onclick={() => bookmarkJump(i)}><Icon name="play" size={12} /> {fmtClock(b.time)}</button>
{#if bmEditIdx === i}
<input
class="input bmnote"
placeholder="Notiz…"
bind:value={bmDraft}
onkeydown={(e) => e.key === 'Enter' && bookmarkSave(i)}
/>
<button class="primary" title="Notiz speichern" onclick={() => bookmarkSave(i)}><Icon name="check" size={13} /></button>
{:else}
<span class="bmtext muted small">{b.note || '—'}</span>
<button class="ghost" title="Notiz bearbeiten" onclick={() => { bmEditIdx = i; bmDraft = b.note }}><Icon name="pencil" size={12} /></button>
{/if}
<button class="ghost" title="Lesezeichen löschen" onclick={() => bookmarkDel(i)}><Icon name="trash" size={12} /></button>
</div>
{/each}
<button class="ghost" title="Panel schließen" onclick={() => (bmOpen = false)}><Icon name="x" size={12} /></button>
</div>
{/if}
{/if}
</main>
{/if}