Files
siftlode/frontend/src/lib/plexQueue.ts
T
peter 2e319be569 refactor(plex): share showEpisodeKeys + honest empty Play-all
Extract the show->ordered-episode-keys flatten into one pure, unit-tested
helper (lib/plexQueue.ts) and use it at all three sites — the collection
Play-all (S4) and the show/season play-through pages in plexViews — so the
season-then-episode queue-order invariant lives in one place instead of three
hand-rolled copies. Behaviour-identical (the helper's ?? [] is a safe superset
of the collection site's previously non-null read).

Also: a show-collection whose shows expand to zero episodes had an enabled
Play-all that silently no-op'd — the same 'does nothing' state S4 removed for
the empty-queue case. Surface an honest info notice (plex.collection.playEmpty,
HU+EN) instead.
2026-08-24 22:09:52 +02:00

11 lines
705 B
TypeScript

import type { PlexShowDetail } from "./api";
// The ordered episode rating-keys of a show: season order, then episode order within each season —
// the play-queue order the show/season pages and the collection Play-all all rely on. Kept in ONE
// place so that invariant (and any future explicit sort, e.g. pushing season 0 "Specials" last)
// lives at a single site rather than the three hand-rolled `seasons.flatMap(...)` copies it grew
// into. `detail` is nullable so callers can pass an in-flight query's `data` straight through.
export function showEpisodeKeys(detail: PlexShowDetail | null | undefined): string[] {
return (detail?.seasons ?? []).flatMap((s) => s.episodes.map((e) => e.id));
}