feat(player): a bookmark reopens every player as it was, once

The Plex player names the playlist it plays through (v=player:<id>:playlist:<pid>), so a bookmark
rebuilds the queue from the playlist's own order while the item is still in it.

Found in the browser and fixed:
- after a reload the shell's player opened a second one over Home and the feed: it read the catalog
  row the page had fetched (a disabled query still reads the shared cache); it now waits for ready.
- every reload under an open overlay left a dead history step: the first overlay to open takes over
  the entry the document was loaded on.
- the feed's address was implicit, the same as the start-page landing, so a reloaded or bookmarked
  feed opened as Home: the feed now names itself (page=feed) like every page.
- a linked file or video that is gone was said, but stayed in the address and was said again on
  every reload: its keys are taken off.

The overlay address is written in one place (the entry is named once it is current), and the player
keys only the codec reads are no longer exported.
This commit is contained in:
2026-10-27 07:33:55 +01:00
parent fa893c73a3
commit 3d26ca0efa
23 changed files with 343 additions and 53 deletions
@@ -30,6 +30,11 @@ vi.mock("./PlexPlayer", () => ({
</div>
),
}));
vi.mock("./PlexPlaylistView", () => ({
default: ({ onPlay }: { onPlay: (rk: string, queue: string[]) => void }) => (
<button onClick={() => onPlay("e1", ["e1", "e2"])}>play from the playlist</button>
),
}));
vi.mock("./plexSavedViews", async (importOriginal) => ({
...(await importOriginal<typeof import("./plexSavedViews")>()),
usePlexSavedViews: () => ({ views: [], displayView: null, isDirty: false, activeViewId: null }),
@@ -100,3 +105,39 @@ describe("the Plex player on a reload", () => {
expect(await screen.findByText("player e2 queue none")).toBeTruthy();
});
});
describe("the Plex player opened from a playlist", () => {
const playlist = (ids: string[]) =>
vi.spyOn(api, "plexPlaylist").mockResolvedValue({
id: 7,
title: "Road trip",
items: ids.map((id) => ({ id, title: id })),
} as never);
it("names the playlist after the item, as it moves on too", async () => {
window.history.replaceState(null, "", "/?page=plex&v=playlist:7");
mount();
fireEvent.click(await screen.findByText("play from the playlist"));
expect(await screen.findByText("player e1 queue e1,e2")).toBeTruthy();
expect(new URLSearchParams(window.location.search).get("v")).toBe("player:e1:playlist:7");
fireEvent.click(screen.getByText("next"));
expect(new URLSearchParams(window.location.search).get("v")).toBe("player:e2:playlist:7");
});
it("a bookmark plays on through the playlist, its order rebuilt from it", async () => {
window.history.replaceState(null, "", "/?page=plex&v=player:e2:playlist:7");
const read = playlist(["e1", "e2", "e3"]);
mount();
expect(await screen.findByText("player e2 queue e1,e2,e3")).toBeTruthy();
expect(read).toHaveBeenCalledWith(7, "en");
});
it("a bookmark whose item has left the playlist plays it on its own neighbours", async () => {
window.history.replaceState(null, "", "/?page=plex&v=player:e9:playlist:7");
const read = playlist(["e1", "e2"]);
mount();
await vi.waitFor(() => expect(read).toHaveBeenCalled());
await new Promise((r) => setTimeout(r, 20));
expect(screen.getByText("player e9 queue none")).toBeTruthy();
});
});