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.
This commit is contained in:
2026-08-24 22:09:52 +02:00
parent 852b227ea2
commit 2e319be569
6 changed files with 53 additions and 3 deletions
@@ -6,6 +6,8 @@ import { qk } from "../lib/queryKeys";
import { api, isIntrinsicReadOnly, type PlexCard, type PlexCollectionDetail } from "../lib/api";
import { formatRuntime } from "../lib/format";
import { notifyActionError, notifyCollectionEditError } from "../lib/actionErrors";
import { notify } from "../lib/notifications";
import { showEpisodeKeys } from "../lib/plexQueue";
import { useConfirm } from "./ConfirmProvider";
import { BackBtn, ActionBtn, DetailHero } from "../lib/plexDetailUi";
import { PlexPosterCard } from "./plexCards";
@@ -87,7 +89,7 @@ export default function PlexCollectionView({
queryKey: qk.plexShow(c.id),
queryFn: () => api.plexShow(c.id),
});
return detail.seasons.flatMap((s) => s.episodes.map((e) => e.id));
return showEpisodeKeys(detail);
}),
);
return perMember.flat();
@@ -98,7 +100,10 @@ export default function PlexCollectionView({
try {
let queue = await buildQueue();
if (shuffle) queue = shuffled(queue);
// canPlay gates on "has a show member", but a show can expand to zero episodes (unmatched /
// empty). An enabled Play-all that silently no-ops is a dishonest state, so say so plainly.
if (queue.length > 0) onPlay(queue[0]!, queue);
else notify({ level: "info", message: t("plex.collection.playEmpty") });
} catch (e) {
notifyActionError(e, t("plex.collection.playFailed"));
} finally {
+3 -2
View File
@@ -8,6 +8,7 @@ import { plexLang } from "../i18n";
import { pickRatingBadge } from "../lib/plexRating";
import { notifyActionError } from "../lib/actionErrors";
import { toggleWatchState } from "../lib/plexWatch";
import { showEpisodeKeys } from "../lib/plexQueue";
import {
ActionBtn,
BackBtn,
@@ -306,7 +307,7 @@ export function PlexShowView({
const show = d?.show;
const showLib = show?.library ?? undefined;
const allKeys = (d?.seasons ?? []).flatMap((se) => se.episodes.map((e) => e.id));
const allKeys = showEpisodeKeys(d);
const watched = show?.status === "watched";
const {
artBg,
@@ -568,7 +569,7 @@ export function PlexSeasonView({
// Play-through queue spans the WHOLE show (all seasons, in order) so a season's last episode rolls
// straight into the next season's first — the same cross-season order the show page already uses.
// seasonKeys stays only for the season-scoped "add to playlist" action.
const allKeys = (d?.seasons ?? []).flatMap((s) => s.episodes.map((e) => e.id));
const allKeys = showEpisodeKeys(d);
const watched = se?.status === "watched";
const { artBg, showCast, crossfade, toggleArtBg, toggleCast, toggleCrossfade } = useDetailPrefs();
useCrossfadeBackdrop(