fix(player): short-video auto-watch + player cleanups

BUG (YB1): the auto-watch checkpoint marked a video watched once position
crossed `duration - FINISH_MARGIN` (10s). For clips shorter than ~10s that
threshold is negative, and for ~11-20s clips it's only a few seconds in, so the
5s checkpoint tick marked short videos watched almost immediately (clearing their
resume position). Cap the margin at half the clip: Math.min(FINISH_MARGIN, dur/2).

Cleanups (behavior-neutral):
- Extract format.formatDate(iso, lang) — the day/month/year toLocaleDateString
  option object was duplicated verbatim in PlayerModal (fullDate) and VideoCard.
  (ChannelPage's "joined" is month/year only, so it's left as-is.)
- The in-bar prev/next buttons now reuse goPrev/goNext instead of re-implementing
  the step + bounds inline (they already exist for the side arrows + keyboard).
- Memoize savedPrefs so the ['me'] cache read + spread runs once, not on every
  render (it only seeds the initial autoMode/loopMode state).

tsc green, knip clean, localdev boots healthy.
This commit is contained in:
npeter83 2026-07-11 18:49:56 +02:00
parent c0e941bc0c
commit 31c1284eb7
3 changed files with 26 additions and 26 deletions

View file

@ -106,3 +106,10 @@ export function formatViews(n: number | null): string {
export function formatCountOrDash(n: number | null | undefined): string {
return n != null ? formatViews(n) : "—";
}
// Absolute day-precision date (e.g. "12 Jan 2017"), shown alongside a relative time. Empty for null.
export function formatDate(iso: string | null | undefined, lang: string): string {
return iso
? new Date(iso).toLocaleDateString(lang, { year: "numeric", month: "short", day: "numeric" })
: "";
}