Extend lib/queryKeys.ts to the remaining ~34 key roots and migrate every remaining literal (queryKey: [...] AND the positional useLiveQuery keys) in 36 files. All ~200 React Query keys across the app now route through the factory; zero raw key literals remain outside queryKeys.ts. The heterogeneous composite plex keys (plex-library/facets/collections/ playlists carry a filters object, a ratingKeys array, or a union/group discriminator) take a variadic pass-through — the factory centralizes the ROOT string; single-id keys stay precisely typed. Nullable keys (thread, playlist, ytSearch) accept null so a null segment is preserved. Pure substitution — byte-identical key arrays, so TanStack prefix matching is unchanged. Gate green: typecheck (app+node+e2e), eslint (0 err), prettier, 68 vitest. Runtime-verified on a fresh dev server: Feed + Plex modules load, feed/facets/tags/my-status/plex-library/plex-facets/ plex-collections/plex-playlists all 200, full UI renders.
196 lines
6.2 KiB
TypeScript
196 lines
6.2 KiB
TypeScript
import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
|
|
import { qk } from "./queryKeys";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import { SlidersHorizontal } from "lucide-react";
|
|
import { useDismiss } from "./useDismiss";
|
|
import { api } from "./api";
|
|
|
|
// Shared "detail page" UI reused by the movie info page (PlexInfo) and the series show/season pages,
|
|
// so they look consistent (the standing glassy/HTPC brief): the faint fixed art backdrop, the two
|
|
// per-user display prefs (art background / cast row — same keys as the movie info page), and the
|
|
// customize menu that toggles them.
|
|
|
|
export function useDetailPrefs() {
|
|
const qc = useQueryClient();
|
|
const prefs = (qc.getQueryData<{ preferences?: Record<string, unknown> }>(qk.me())?.preferences ??
|
|
{}) as {
|
|
plexInfoArtBg?: boolean;
|
|
plexInfoCast?: boolean;
|
|
plexInfoRelated?: boolean;
|
|
};
|
|
const [artBg, setArtBg] = useState(prefs.plexInfoArtBg !== false);
|
|
const [showCast, setShowCast] = useState(prefs.plexInfoCast !== false);
|
|
const [showRelated, setShowRelated] = useState(prefs.plexInfoRelated !== false);
|
|
const save = (patch: Record<string, unknown>) => {
|
|
api.savePrefs(patch).catch(() => {});
|
|
qc.setQueryData<{ preferences?: Record<string, unknown> } | undefined>(qk.me(), (m) =>
|
|
m ? { ...m, preferences: { ...(m.preferences || {}), ...patch } } : m,
|
|
);
|
|
};
|
|
return {
|
|
artBg,
|
|
showCast,
|
|
showRelated,
|
|
savePref: save, // expose the raw persister for callers with extra per-user prefs (e.g. strip sources)
|
|
toggleArtBg: () => {
|
|
const next = !artBg;
|
|
setArtBg(next);
|
|
save({ plexInfoArtBg: next });
|
|
},
|
|
toggleCast: () => {
|
|
const next = !showCast;
|
|
setShowCast(next);
|
|
save({ plexInfoCast: next });
|
|
},
|
|
toggleRelated: () => {
|
|
const next = !showRelated;
|
|
setShowRelated(next);
|
|
save({ plexInfoRelated: next });
|
|
},
|
|
};
|
|
}
|
|
|
|
// A metadata value that filters the grid when clicked (if onClick is wired), else plain text. Shared
|
|
// by the movie info page (PlexInfo) and the unified grid / show pages (PlexBrowse). The optional
|
|
// `title` gives a hover hint (e.g. "Filter by 1998"); callers that don't need it just omit it.
|
|
export function Filterable({
|
|
onClick,
|
|
title,
|
|
className,
|
|
children,
|
|
}: {
|
|
onClick?: () => void;
|
|
title?: string;
|
|
className?: string;
|
|
children: ReactNode;
|
|
}) {
|
|
if (!onClick) return <span className={className}>{children}</span>;
|
|
return (
|
|
<button
|
|
onClick={onClick}
|
|
title={title}
|
|
className={`${className ?? ""} cursor-pointer hover:text-accent transition`}
|
|
>
|
|
{children}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
// Paint the item's art as a faint FIXED backdrop on the page's <main> scroll container (HTPC-style),
|
|
// so the glass panels float over it. Cleared on unmount / when disabled / when there's no art.
|
|
export function useArtBackdrop(art: string | null | undefined, enabled: boolean) {
|
|
useLayoutEffect(() => {
|
|
const main = document.querySelector("main");
|
|
if (!main) return;
|
|
const s = main.style;
|
|
const clear = () => {
|
|
s.backgroundImage = "";
|
|
s.backgroundSize = "";
|
|
s.backgroundPosition = "";
|
|
s.backgroundRepeat = "";
|
|
s.backgroundAttachment = "";
|
|
};
|
|
if (enabled && art) {
|
|
s.backgroundImage =
|
|
`linear-gradient(color-mix(in srgb, var(--bg) 60%, transparent), ` +
|
|
`color-mix(in srgb, var(--bg) 64%, transparent)), url("${art}")`;
|
|
s.backgroundSize = "cover";
|
|
s.backgroundPosition = "center 20%";
|
|
s.backgroundRepeat = "no-repeat";
|
|
s.backgroundAttachment = "fixed";
|
|
} else {
|
|
clear();
|
|
}
|
|
return clear;
|
|
}, [art, enabled]);
|
|
}
|
|
|
|
export function DetailCustomizeMenu({
|
|
artBg,
|
|
onToggleArtBg,
|
|
showCast,
|
|
onToggleCast,
|
|
hasCast,
|
|
showRelated,
|
|
onToggleRelated,
|
|
hasRelated,
|
|
overlay,
|
|
extra,
|
|
}: {
|
|
artBg: boolean;
|
|
onToggleArtBg: () => void;
|
|
showCast: boolean;
|
|
onToggleCast: () => void;
|
|
hasCast: boolean;
|
|
showRelated?: boolean;
|
|
onToggleRelated?: () => void;
|
|
hasRelated?: boolean;
|
|
overlay?: boolean; // white-on-dark button styling when floated over the player
|
|
extra?: ReactNode; // additional toggles rendered after the built-in ones (e.g. strip-source buckets)
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const [open, setOpen] = useState(false);
|
|
const btnRef = useRef<HTMLButtonElement>(null);
|
|
const menuRef = useRef<HTMLDivElement>(null);
|
|
useDismiss(open, () => setOpen(false), [menuRef, btnRef]);
|
|
return (
|
|
<div className="relative shrink-0">
|
|
<button
|
|
ref={btnRef}
|
|
onClick={() => setOpen((v) => !v)}
|
|
title={t("plex.info.customize")}
|
|
className={`p-1.5 rounded-lg ${overlay ? "text-white/80 hover:bg-white/15" : "text-muted hover:bg-surface hover:text-fg"}`}
|
|
>
|
|
<SlidersHorizontal className="w-4 h-4" />
|
|
</button>
|
|
{open && (
|
|
<div
|
|
ref={menuRef}
|
|
className="glass-menu absolute right-0 top-full z-menu mt-1 w-52 rounded-xl p-1.5 text-sm"
|
|
style={{ background: "color-mix(in srgb, var(--surface) 58%, transparent)" }}
|
|
>
|
|
<PrefToggle label={t("plex.info.prefArtBg")} on={artBg} onClick={onToggleArtBg} />
|
|
{hasCast && (
|
|
<PrefToggle label={t("plex.info.prefCast")} on={showCast} onClick={onToggleCast} />
|
|
)}
|
|
{hasRelated && onToggleRelated && (
|
|
<PrefToggle
|
|
label={t("plex.info.prefRelated")}
|
|
on={showRelated ?? true}
|
|
onClick={onToggleRelated}
|
|
/>
|
|
)}
|
|
{extra}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function PrefToggle({
|
|
label,
|
|
on,
|
|
onClick,
|
|
}: {
|
|
label: string;
|
|
on: boolean;
|
|
onClick: () => void;
|
|
}) {
|
|
return (
|
|
<button
|
|
onClick={onClick}
|
|
className="flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left hover:bg-surface"
|
|
>
|
|
<span>{label}</span>
|
|
<span
|
|
className={`relative h-4 w-7 rounded-full transition ${on ? "bg-accent" : "bg-border"}`}
|
|
>
|
|
<span
|
|
className={`absolute top-0.5 h-3 w-3 rounded-full bg-white transition-all ${on ? "left-3.5" : "left-0.5"}`}
|
|
/>
|
|
</span>
|
|
</button>
|
|
);
|
|
}
|