Spotiarr zustand

From mralexsaavedra/spotiarr · View interactive version

Spotiarr zustand is an AI agent skill from the GitHub repository mralexsaavedra/spotiarr. Trigger: Zustand, store, client state, usePlayerStore, usePreferencesStore, playerUISlice, ephemeral state, persist middleware. spotiarr Zustand rules: 2 stores + player UI slice, server state stays in TanStack Query, patterns for selectors and bulk hooks.

How to use this skill

Skill file

Activation Contract

Load when adding client-side state, touching Zustand stores, or deciding whether something belongs in Zustand vs TanStack Query.

Hard Rules

The Stores

`usePreferencesStore` — persisted

`usePlayerStore` — partially persisted

Download Status — TanStack Query, not a store

Download status used to be a Zustand store; it is now server state served by TanStack Query.

| Hook | Returns |

| ------------------------------------------------- | ---------------------------------------------- |

| usePlaylistDownloaded(url, expectedTrackCount?) | boolean |

| usePlaylistDownloading(url) | boolean |

| useBulkPlaylistStatus(items) | Map<string, { isDownloaded, isDownloading }> |

| useBulkTrackStatus(urls) | Map<string, TrackStatusEnum> |

Pure derivers deriveIsDownloaded / deriveIsDownloading back the hooks and are unit-testable in isolation. Use bulk hooks in list components to avoid per-item subscriptions.

Auth gate — ephemeral React state (not a store)

useTokenGate (apps/frontend/src/hooks/controllers/useTokenGate.ts) deliberately uses local useState, not a Zustand store:

Promoting it to a store requires a written SDD proposal.

Adding State

To usePreferencesStore: Add field to PreferencesState interface + initial value + setter/toggle. No extra config — persist covers all fields automatically.

To usePlayerStore: Add field to the state interface + initial value + action; if it is UI-only player state, add it to playerUISlice. Extend partialize only when the field must survive a reload.

Download-status-shaped state: Add it to the DownloadStatusResponse contract and a derived selector hook in hooks/queries/useDownloadStatus.ts — do not put it in a store.

New store (discouraged): Requires architectural justification recorded in an SDD proposal. Mixed strategy (partial persist via partialize) is permitted when the store covers state with different lifetimes — see usePlayerStore for the canonical example.

Selector Performance

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.