T-031: Lesezeichen mit Notiz — bookmarks.json, Panel in der Leiste (Sprung, Notiz editieren, delete)
This commit is contained in:
@ -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}
|
||||
|
||||
49
src/app.css
49
src/app.css
@ -388,3 +388,52 @@ code {
|
||||
font-size: 0.85rem;
|
||||
padding: 0.25rem 0.4rem;
|
||||
}
|
||||
|
||||
/* Lesezeichen-Panel (T-031) */
|
||||
|
||||
.bmpanel {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 5.2rem;
|
||||
width: min(26rem, calc(100vw - 2rem));
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 0.8rem 0.9rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
z-index: 6;
|
||||
max-height: 12rem;
|
||||
overflow: auto;
|
||||
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.bmrow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.bmrow button {
|
||||
padding: 0.2rem 0.5rem;
|
||||
font-size: 0.85rem;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.bmtext {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bmnote {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 0.85rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
forward:
|
||||
'<path d="m4 6 6 6-6 6"/><path d="m13 6 6 6-6 6"/>',
|
||||
check: '<path d="M4 12l5 5L20 6"/>',
|
||||
flag: '<path d="M6 21V4h11l-2.5 4L17 12H6"/>',
|
||||
pencil:
|
||||
'<path d="M4 20h4L20 8l-4-4L4 16v4z"/><path d="M13.5 6.5l4 4"/>',
|
||||
x: '<path d="M5 5l14 14"/><path d="M19 5 5 19"/>',
|
||||
|
||||
@ -67,6 +67,15 @@ export const playerSnapshot = () => invoke<PlayerState>('player_snapshot')
|
||||
export const onPlayerState = (cb: (s: PlayerState) => void) =>
|
||||
listen<PlayerState>('player-state', (ev) => cb(ev.payload))
|
||||
export const assetUri = (path: string) => convertFileSrc(path)
|
||||
|
||||
export interface Bm { time: number; note: string }
|
||||
export const bmList = (asin: string) => invoke<Bm[]>('bookmark_list', { asin })
|
||||
export const bmAdd = (asin: string, time: number, note: string) =>
|
||||
invoke<Bm[]>('bookmark_add', { asin, time, note })
|
||||
export const bmRemove = (asin: string, index: number) =>
|
||||
invoke<Bm[]>('bookmark_remove', { asin, index })
|
||||
export const bmSetNote = (asin: string, index: number, note: string) =>
|
||||
invoke<Bm[]>('bookmark_set_note', { asin, index, note })
|
||||
export function fmtClock(sec: number): string {
|
||||
const t = Math.max(0, Math.floor(sec))
|
||||
const h = Math.floor(t / 3600)
|
||||
|
||||
Reference in New Issue
Block a user