Commit Graph

2 Commits

Author SHA1 Message Date
Gauvain
e3f4eea132 fix(chapters): address review findings + trickplay polish
Copilot + CodeRabbit review findings:
- React.memo ChapterTicks and ChapterList (project guideline: hot-path
  components must use React.memo to cut redraw work during control
  updates).
- chapterNameAt now sorts the chapter array once instead of twice per
  call. The previous version went through currentChapterIndex
  (chapterStartsMs + sort) then sortedChapters (sort again). Runs on
  every playback tick, so the duplicate work added up.
- Import getUserLibraryApi from the public barrel
  (@jellyfin/sdk/lib/utils/api) instead of the deep internal path
  (@jellyfin/sdk/lib/utils/api/user-library-api) to match the rest of
  the codebase and avoid coupling to SDK file layout.

TrickplayBubble polish:
- Sit just above the slider (bottom: 0) so the bubble no longer overlaps
  the progress bar.
- Move the chapter-name + timestamp overlay to the bottom-left of the
  preview frame, smaller font, in front of the surrounding overlays
  (zIndex + elevation).

BottomControls cleanup:
- Drop dev-only "pick one to test" comment in favour of a one-line note
  on TICK_HEIGHT.
- Inline scrubMs into its useMemo callback so the scrub-chapter-name
  lookup only recomputes while a slide is active.
2026-05-27 20:08:21 +02:00
Gauvain
8d33aa3ba1 feat(chapters): add pure helpers and unit tests
Adds dependency-free helpers in utils/chapters.ts for working with
Jellyfin chapter markers:

- chapterMarkers(chapters, durationMs): markers within range, with
  precomputed percent for slider overlays.
- chapterStartsMs(chapters): sorted start positions in ms (skips
  entries without StartPositionTicks).
- currentChapterIndex(positionMs, chapters): active chapter index
  for the live playback position (-1 if before the first chapter).
- chapterNameAt(positionMs, chapters): the active chapter name, or
  null if missing/unnamed.
- sortedChapters(chapters): chapter entries paired with ms start.
- formatChapterTime(positionMs): m:ss or h:mm:ss label.

All helpers tolerate null/undefined/empty inputs.

17 unit tests under bun test cover sort order, boundary positions,
missing fields, and out-of-range inputs.
2026-05-27 16:39:05 +02:00