Skip to content

Reference: State

Unwrap splits state between TanStack Query (server state) and Zustand (client state). This page is a navigational index. For the rationale, see Architecture: state management.

TanStack Query (server state)

Hooks live in src/hooks/. Each hook wraps a service from src/services/api.ts with a TanStack Query cache key.

HookServiceCache key
useTopTracks()fetchTopTracks['top-tracks', TimeRange, limit, offset]
useTopArtists()fetchTopArtists['top-artists', TimeRange, limit, offset]
useTopGenres()fetchTopGenres['top-genres', TimeRange, limit, offset]
useTopSkips()fetchTopSkips['top-skips', TimeRange, limit, offset]
useTopReplays()fetchTopReplays['top-replays', TimeRange, limit, offset]
usePeakHour()fetchPeakHour['peak-hour', TimeRange]
useMostActiveDay()fetchMostActiveDay['most-active-day', TimeRange]
useTimeListened()fetchTimeListened['time-listened', TimeRange]
useConnectedServices()fetchConnectedServices['connected-services']
useUploadHistory()uploadHistory(mutation; invalidates dashboard queries on success)

Conventions

  • Cache keys are arrays starting with the resource name, then any parameters that affect the response.
  • Components consume { data, isLoading, isError } and never reach into the QueryClient directly.

Zustand (client state)

Two stores in src/stores/. Each owns one concern.

authStore

Holds the currently authenticated user, derived from the session cookie at app load time.

FieldTypePurpose
userUser | nullCached user object. null when not signed in.
isAuthenticatedbooleanConvenience derived flag.
isLoadingbooleanTrue while useInitAuth is fetching on app load.
setUser()actionSets the user. Used after login.
clearUser()actionClears the user. Used after logout.
updateUser(u)actionPatches user fields. Used by the Settings page.

dashboardStore

Holds dashboard display preferences. Persists to localStorage under the key unwrap-dashboard-preferences.

FieldTypePurpose
timeRangeTimeRangeThe selected time window.
categoriesDashboardCategory[]Visible categories, in display order.
setTimeRange()actionUpdates the time range.
toggleCategory()actionAdds or removes a category. Refuses to remove the last one.
setCategories()actionReplaces the full category list.
resetToDefaults()actionRestores the out-of-the-box dashboard.

CATEGORY_LABELS

A single Record<DashboardCategory, string> mapping category IDs to display labels. Source of truth for both the picker UI and the dashboard rendering. Add a new category here and the picker, persistence, and UI all pick it up automatically.

Built for SE_07 — Technical Documentation