feat(plex): a Surprise reshuffle deals the previous draw last
The rail draws three unseen titles per kind under the sidebar filters; on a small filtered pool every reshuffle dealt the same few again. The redraw now sends the draw on screen (exclude=), the server deals the rest of the pool first and tops up from the excluded titles only when the pool is short, so a small pool still fills the rail. (The two discover.py baseline entries went with the rewritten draw.)
This commit is contained in:
@@ -218,6 +218,9 @@ describe("PlexDiscover", () => {
|
||||
fireEvent.click(screen.getByRole("button", { name: "plex.discover.reshuffle" }));
|
||||
await waitFor(() => expect(plexSurprise).toHaveBeenCalledTimes(2));
|
||||
expect(plexDiscover).toHaveBeenCalledTimes(1); // the whole surface was NOT refetched
|
||||
// The first draw asks for anything; the redraw hands over the one on screen to deal it last.
|
||||
expect(plexSurprise.mock.calls[0]?.[4]).toEqual([]);
|
||||
expect(plexSurprise.mock.calls[1]?.[4]).toEqual(["sp1"]);
|
||||
});
|
||||
|
||||
it("shows the empty message when every rail is empty", async () => {
|
||||
|
||||
@@ -119,9 +119,20 @@ export default function PlexDiscover({
|
||||
queryFn: () => api.plexDiscover(scope, lang, filters),
|
||||
});
|
||||
// Surprise-me is its own query so the ↻ button can redraw it without refetching the whole surface.
|
||||
// A redraw hands over the draw on screen, so a small filtered pool deals its other titles first.
|
||||
const surpriseKey = qk.plexSurprise(scope, lang, filters);
|
||||
const surpriseQ = useQuery({
|
||||
queryKey: qk.plexSurprise(scope, lang, filters),
|
||||
queryFn: () => api.plexSurprise(scope, undefined, filters, lang),
|
||||
queryKey: surpriseKey,
|
||||
queryFn: () => {
|
||||
const shown = qc.getQueryData<{ items: PlexCard[] }>(surpriseKey)?.items ?? [];
|
||||
return api.plexSurprise(
|
||||
scope,
|
||||
undefined,
|
||||
filters,
|
||||
lang,
|
||||
shown.map((c) => c.id),
|
||||
);
|
||||
},
|
||||
staleTime: 0,
|
||||
});
|
||||
|
||||
|
||||
@@ -625,15 +625,17 @@ export const plexApi = {
|
||||
return req(`/api/plex/discover?${u.toString()}`);
|
||||
},
|
||||
// A fresh random sample for the Surprise-me rail — a new draw every call (the ↻ refetch), narrowed by
|
||||
// the active filters like the other rails.
|
||||
// the active filters like the other rails. `exclude` is the previous draw: dealt last, not first.
|
||||
plexSurprise: (
|
||||
scope: string,
|
||||
limit?: number,
|
||||
filters?: PlexFilters,
|
||||
lang?: string,
|
||||
exclude: string[] = [],
|
||||
): Promise<{ scope: string; items: PlexCard[] }> => {
|
||||
const u = new URLSearchParams({ scope });
|
||||
if (limit) u.set("limit", String(limit));
|
||||
for (const id of exclude) u.append("exclude", id);
|
||||
if (lang === "hu") u.set("lang", "hu");
|
||||
if (filters) appendPlexFilters(u, filters);
|
||||
return req(`/api/plex/surprise?${u.toString()}`);
|
||||
|
||||
Reference in New Issue
Block a user