fix(plex): the show and season restart names its object and starts at 0 (E28 S3f2)

The header button said only "Play from start" and resumed the first
episode at its saved point. It now reads "Season from the start · S6 · E1"
or "Show from the start · S1 · E1" and asks the player for 0.
This commit is contained in:
2026-09-27 03:30:04 +02:00
parent dc5206f9d3
commit d510c8a534
5 changed files with 145 additions and 8 deletions
+3 -1
View File
@@ -484,7 +484,9 @@ export default function PlexBrowse() {
<PlexShowView
showId={showId}
onBack={sub.back}
onPlay={(epRk, queue) => sub.open({ kind: "player", id: epRk, queue })}
onPlay={(epRk, queue, fromStart) =>
sub.open({ kind: "player", id: epRk, queue, fromStart })
}
onOpenSeason={(seasonId) => sub.open({ kind: "season", showId, seasonId })}
onOpenShow={(id) => sub.open({ kind: "show", id })}
onFilter={applyFilter}
@@ -0,0 +1,131 @@
// @vitest-environment jsdom
//
// The show's and the season's restart button. It said only "Play from start" — of what? (the owner,
// 2026-09-27) — and it resumed the first episode at its saved point instead of at 0. Now it names its
// object and the episode ("Season from the start · S6 · E1"), and it asks the player for 0.
import { describe, it, expect, afterEach, beforeAll, vi } from "vitest";
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
beforeAll(() => {
class Stub {
observe() {}
unobserve() {}
disconnect() {}
takeRecords() {
return [];
}
}
globalThis.ResizeObserver ??= Stub as unknown as typeof ResizeObserver;
});
vi.mock("react-i18next", async (importOriginal) => {
const actual = await importOriginal<typeof import("react-i18next")>();
return { ...actual, useTranslation: () => ({ t: (key: string) => key }) };
});
const ep = (id: string, season: number, episode: number, position = 0) => ({
id,
type: "episode",
title: `Ep ${id}`,
season_number: season,
episode_number: episode,
duration_seconds: 1500,
thumb: `/api/plex/image/${id}`,
playable: "direct",
status: position > 0 ? "in_progress" : "new",
position_seconds: position,
});
// The first episode is half-watched: a restart that resumed it would start at 600, not 0.
const s1 = [ep("e11", 1, 1, 600), ep("e12", 1, 2)];
const s2 = [ep("e21", 2, 1, 300), ep("e22", 2, 2)];
const detail = {
show: {
id: "show",
title: "Show",
thumb: "",
art: "",
genres: [],
cast: [],
status: "in_progress",
resume: s2[1],
first: s1[0],
episode_count: 4,
collection_keys: [],
},
seasons: [
{
id: "s1",
season_number: 1,
title: "Season 1",
thumb: "",
episode_count: 2,
status: "in_progress",
resume: s1[1],
first: s1[0],
episodes: s1,
},
{
id: "s2",
season_number: 2,
title: "Season 2",
thumb: "",
episode_count: 2,
status: "in_progress",
resume: s2[1],
first: s2[0],
episodes: s2,
},
],
related: [],
};
vi.mock("../lib/api", () => ({
api: {
plexShow: () => Promise.resolve(detail),
plexSetState: () => Promise.resolve(),
plexSeasonState: () => Promise.resolve(),
},
EMPTY_PLEX_FILTERS: {},
plexFilterCount: () => 0,
}));
import { PlexSeasonView, PlexShowView } from "./plexViews";
afterEach(cleanup);
function wrap(ui: React.ReactElement) {
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(<QueryClientProvider client={qc}>{ui}</QueryClientProvider>);
}
const ALL = ["e11", "e12", "e21", "e22"];
describe("the restart button on a show and a season", () => {
it("a season's names the season and its first episode, and starts that episode at 0", async () => {
const onPlay = vi.fn();
wrap(<PlexSeasonView showId="show" seasonId="s2" onBack={() => {}} onPlay={onPlay} />);
const btn = await screen.findByRole("button", { name: /plex\.series\.seasonFromStart/ });
expect(btn.textContent).toContain("S2 · E1");
fireEvent.click(btn);
expect(onPlay).toHaveBeenCalledWith("e21", ALL, true);
});
it("a show's names the show and its first episode, and starts that episode at 0", async () => {
const onPlay = vi.fn();
wrap(
<PlexShowView
showId="show"
onBack={() => {}}
onPlay={onPlay}
onOpenSeason={() => {}}
onOpenShow={() => {}}
/>,
);
const btn = await screen.findByRole("button", { name: /plex\.series\.showFromStart/ });
expect(btn.textContent).toContain("S1 · E1");
fireEvent.click(btn);
expect(onPlay).toHaveBeenCalledWith("e11", ALL, true);
});
});
+7 -5
View File
@@ -328,7 +328,7 @@ export function PlexShowView({
}: {
showId: string;
onBack: () => void;
onPlay: (epRk: string, queue: string[]) => void;
onPlay: (epRk: string, queue: string[], fromStart?: boolean) => void;
onOpenSeason: (seasonId: string) => void;
onOpenShow: (id: string) => void;
onFilter?: (patch: Partial<PlexFilters>) => void;
@@ -559,9 +559,10 @@ export function PlexShowView({
)}
{show.first && show.status !== "new" && (
<ActionBtn
onClick={() => onPlay(show.first!.id, allKeys)}
onClick={() => onPlay(show.first!.id, allKeys, true)}
icon={RotateCcw}
label={t("plex.series.playFromStart")}
label={t("plex.series.showFromStart")}
sub={epLabel(show.first)}
/>
)}
<WatchedToggle
@@ -765,9 +766,10 @@ export function PlexSeasonView({
)}
{se.first && se.status !== "new" && (
<ActionBtn
onClick={() => onPlay(se.first!.id, allKeys)}
onClick={() => onPlay(se.first!.id, allKeys, true)}
icon={RotateCcw}
label={t("plex.series.playFromStart")}
label={t("plex.series.seasonFromStart")}
sub={epLabel(se.first)}
/>
)}
<WatchedToggle
+2 -1
View File
@@ -138,7 +138,8 @@
"seasons": "Seasons",
"backToShow": "Back to show",
"episodeCount": "{{count}} episodes",
"playFromStart": "Play from start",
"showFromStart": "Show from the start",
"seasonFromStart": "Season from the start",
"related": "Related shows",
"markShowWatched": "Mark show watched",
"markShowUnwatched": "Mark show unwatched",
+2 -1
View File
@@ -138,7 +138,8 @@
"seasons": "Évadok",
"backToShow": "Vissza a sorozathoz",
"episodeCount": "{{count}} rész",
"playFromStart": "Lejátszás az elejéről",
"showFromStart": "Sorozat elejéről",
"seasonFromStart": "Évad elejéről",
"related": "Kapcsolódó sorozatok",
"markShowWatched": "Egész sorozat megnézve",
"markShowUnwatched": "Sorozat jelölés visszavonása",