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 {