Chat / frontend /src /lib /store /libraryStore.ts
kishankrish19's picture
Deploy Stillwave fullstack clean
b0798af
Raw History Blame Contribute Delete
558 Bytes
"use client";
import { create } from "zustand";
import type { TrackActivity } from "../api/apiClient";
// One authenticated poll keeps every visible song up to date. Never persist
// another listener's private library state in the browser.
export const useLibraryStore = create<{
activity: Record<string, TrackActivity>;
sync: (records: TrackActivity[]) => void;
clear: () => void;
}>((set) => ({
activity: {},
sync: (records) =>
set({ activity: Object.fromEntries(records.map((r) => [r.id, r])) }),
clear: () => set({ activity: {} }),
}));