import { getAccountRaw, LS } from "../lib/storage"; import { parsePositiveIntId } from "../lib/parseId"; // The Playlists module's selected-id seed, split out of PlaylistsProvider so its ?pl guard is // unit-testable and the provider stays react-refresh-clean (component-only exports). export function readSelectedId(): number | null { // A ?pl bookmark wins over the stored selection so a pasted link opens that playlist. BOTH must be a // positive-integer id (a bare "?pl=" gives Number("")===0, "?pl=1.5" a fractional id) — either would // select a non-existent playlist, so the stored fallback is guarded exactly like the URL. return ( parsePositiveIntId(new URLSearchParams(window.location.search).get("pl")) ?? parsePositiveIntId(getAccountRaw(LS.playlist)) ); }