diff --git a/web/src/pages/audiobooks/AudiobookDetail.tsx b/web/src/pages/audiobooks/AudiobookDetail.tsx index 96ea1047..5373fc79 100644 --- a/web/src/pages/audiobooks/AudiobookDetail.tsx +++ b/web/src/pages/audiobooks/AudiobookDetail.tsx @@ -31,6 +31,18 @@ function totalDuration(files: AudiobookFile[]): number { return files.reduce((acc, f) => acc + (f.duration_seconds ?? 0), 0); } +function findChapterAt( + chapters: ReturnType, + seconds: number, +): { label: string; index: number } | null { + for (let i = chapters.length - 1; i >= 0; i--) { + if (seconds >= chapters[i].absoluteStart) { + return { label: chapters[i].label, index: i + 1 }; + } + } + return chapters[0] ? { label: chapters[0].label, index: 1 } : null; +} + /** Gather all chapters across files, adjusting start/end by each file's cumulative offset. */ function buildChapterList(files: AudiobookFile[]): Array<{ chapter: AudiobookChapter; @@ -233,20 +245,9 @@ export default function AudiobookDetail() { genres={data.audiobook.genres} actions={ files.length > 0 && ( -
-
- - {hasProgress && ( - - )} -
+
{hasProgress && durationTotal > 0 && ( -
+

- {formatSeconds(resumeSeconds)} listened + {formatSeconds(resumeSeconds)} listened ·{" "} + {Math.round((resumeSeconds / durationTotal) * 100)}%

)} +
+ + {hasProgress && ( + + )} +
) }