Files
movie-advisor/components/Preview/components/Torrents/usePinnedTorrents.ts
T
nerandClaude Fable 5 06f142510b feat(torrents): pin played torrents to the top
Pin torrents (via the pin toggle or automatically on play/stream) so
they stick to the top of the list regardless of the active sort, and
persist the pins to localStorage. The pin sits before the title,
revealing on row hover on desktop and always shown on touch or when
pinned.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-06 22:38:57 +03:00

27 lines
776 B
TypeScript

import { useAtom } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
const pinnedAtom = atomWithStorage<string[]>('pinned-torrents', [], undefined, {
unstable_getOnInit: true
});
const usePinnedTorrents = () => {
const [pinned, setPinned] = useAtom(pinnedAtom);
const isPinned = (key?: string) => Boolean(key) && pinned.includes(key!);
const pin = (key?: string) =>
void setPinned((current) => (!key || current.includes(key) ? current : [...current, key]));
const toggle = (key?: string) =>
void setPinned((current) => {
if (!key) return current;
return current.includes(key) ? current.filter((item) => item !== key) : [...current, key];
});
return { pinned, isPinned, pin, toggle };
};
export default usePinnedTorrents;