Deep-review round 2 over main..improvement/watch-background-audio. Account resolution (server) - A request naming an account that is no longer signed in to this browser (X-Siftlode-Account or ?account=) now acts as nobody instead of the session's default account. A tab still pinned to an account signed out in another tab went on acting as the default: its player checkpoints and preference saves landed in that account, the messages socket and Plex playback ran as it, and its Sign out signed THAT account out. A hidden tab never polls /api/me, so a tab playing in the background kept doing it. The /api/me bootstrap probe alone keeps the fallback, which is how such a tab learns who it now is: the app's 401 handler reloads, and BootGate re-pins the tab. BootGate - On an identity change the tab reloads without moving its pin first. The tree being torn down still runs its unmount saves before the page goes, and with the pin already moved they wrote into the new account's local keys (a player volume still pending). The reloaded page corrects the pin. Share page (/watch) - Only a 404 says the link is gone. A 5xx, a dropped connection, and the unlock's own rate limit all rendered "no longer available ... expired or revoked" to a viewer with a valid link, with no way to try again. A load failure now offers Retry; too many password tries says so and keeps the form; an unlock that gets no answer says so instead of doing nothing. Strings in en/hu/de. Downloads - A cookie-authed asset is recognised under the current signature version and the one before it, so a job queued before a deploy that bumps the version still downloads with its cookie instead of failing on the login wall with an error that says no cookie was used. The app chunk is preloaded through lazyWithPreload, so a failed fetch no longer leaves an unhandled rejection beside the ErrorBoundary. The panel layout seed is one helper (seedLayout). Tests: the stale-tab refusal, its harmless Sign out and the probe fallback; the pre-bump authed asset; BootGate keeping the pin on reload and staying mounted through a same-account change; the reveal clock's later-commit hand-off; the prefs, panel layout and demo-scope seeds from the me cache; the share page's failure states. Each mutation-checked RED for its own reason.
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
// Per-user customization of a side panel's group cards: their order, which are collapsed, and
|
|
// which are hidden — the same "customize" affordance the feed filter rail had, generalized so
|
|
// every panel (feed / plex / playlists) has its own saved layout. Persisted to localStorage and
|
|
// the server-side `preferences` blob (schemaless), so it follows the account across devices.
|
|
import { LS, readAccount, writeAccount } from "./storage";
|
|
|
|
export type PanelId = "feed" | "plex" | "playlists";
|
|
|
|
export interface PanelLayout {
|
|
order: string[];
|
|
collapsed: Record<string, boolean>;
|
|
hidden: Record<string, boolean>;
|
|
}
|
|
|
|
// The default group order per panel. Group ids must match the ids each panel feeds to PanelGroups.
|
|
// Unknown/stale ids are dropped and any missing (e.g. a group added in a later version) are
|
|
// appended by normalizeLayout, so nothing silently disappears.
|
|
const PANEL_ORDER: Record<PanelId, string[]> = {
|
|
feed: ["date", "year", "channel", "tags", "language", "topic"],
|
|
plex: [
|
|
"playlists",
|
|
"watch",
|
|
"people",
|
|
"collection",
|
|
"rating",
|
|
"genre",
|
|
"year",
|
|
"duration",
|
|
"added",
|
|
"contentrating",
|
|
],
|
|
playlists: ["manage", "list"],
|
|
};
|
|
|
|
// localStorage key per panel (feed keeps its original key for backward compatibility).
|
|
const LS_KEY: Record<PanelId, string> = {
|
|
feed: LS.sidebarLayout,
|
|
plex: LS.plexLayout,
|
|
playlists: LS.playlistsLayout,
|
|
};
|
|
|
|
// Key on the server `preferences` blob per panel (feed keeps its original key).
|
|
export const PREF_KEY: Record<PanelId, "sidebarLayout" | "plexLayout" | "playlistsLayout"> = {
|
|
feed: "sidebarLayout",
|
|
plex: "plexLayout",
|
|
playlists: "playlistsLayout",
|
|
};
|
|
|
|
export function defaultLayout(panel: PanelId): PanelLayout {
|
|
return { order: [...PANEL_ORDER[panel]], collapsed: {}, hidden: {} };
|
|
}
|
|
|
|
function normalizeLayout(panel: PanelId, raw: unknown): PanelLayout {
|
|
const all = PANEL_ORDER[panel];
|
|
const r = (raw ?? {}) as Partial<PanelLayout>;
|
|
const order = Array.isArray(r.order) ? r.order.filter((x) => all.includes(x)) : [];
|
|
for (const id of all) if (!order.includes(id)) order.push(id);
|
|
return {
|
|
order,
|
|
collapsed: { ...(r.collapsed ?? {}) },
|
|
hidden: { ...(r.hidden ?? {}) },
|
|
};
|
|
}
|
|
|
|
function loadLayout(panel: PanelId): PanelLayout {
|
|
return normalizeLayout(panel, readAccount<unknown>(LS_KEY[panel], {}));
|
|
}
|
|
|
|
// A panel's layout when the app mounts: the account's server copy (the `me` cache's preferences) when
|
|
// it has one — so a layout changed on another device is right on the first paint — else this browser's.
|
|
export function seedLayout(
|
|
panel: PanelId,
|
|
prefs: Record<string, unknown> | undefined,
|
|
): PanelLayout {
|
|
const raw = prefs?.[PREF_KEY[panel]];
|
|
return raw ? normalizeLayout(panel, raw) : loadLayout(panel);
|
|
}
|
|
|
|
export function saveLayoutLocal(panel: PanelId, l: PanelLayout): void {
|
|
writeAccount(LS_KEY[panel], l);
|
|
}
|