- Add GET /entries/tmdb/preview/:type/:tmdbId endpoint in entryController.js - Fetch TMDB data via tmdbService.fetchEntryData() without persisting to DB - Return normalized preview object with title, poster, genres, rating, season/episode counts
3.3 KiB
3.3 KiB
title, tags, aliases
| title | tags | aliases | |||||
|---|---|---|---|---|---|---|---|
| Stores |
|
|
Stores
Zustand stores in react_frontend/src/stores/. Three stores managing client-side state.
useLibraryStore
[!info] File:
stores/useLibraryStore.ts
The core application store. Holds all library entries in a Map<number, Entry> for O(1) lookups.
State
| Field | Type | Description |
|---|---|---|
entries |
Map<number, Entry> |
All entries keyed by ID |
isLoaded |
boolean |
True after initial fetch completes |
Actions
| Action | Signature | Description |
|---|---|---|
setEntries |
(entries: Entry[]) => void |
Bulk load entries (clears + rebuilds map) |
addEntry |
(entry: Entry) => void |
Add single entry |
updateEntry |
(id: number, data: Partial<Entry>) => void |
Partial update |
removeEntry |
(id: number) => void |
Delete entry from store |
Helper Hook
export function useLibraryEntries(): Entry[] {
return Array.from(useLibraryStore((s) => s.entries).values());
}
Returns all entries as an array. Used by Statistics, Pages, etc.
Usage Pattern
// Read single entry
const entry = useLibraryStore((s) => s.entries.get(entryId));
// Read title (used in breadcrumbs)
const title = useLibraryStore((s) => s.entries.get(id)?.title);
// Check if library is loaded
const isLoaded = useLibraryStore((s) => s.isLoaded);
Population Flow
App.tsxrenders →useLibrary()hook firesGET /api/v1/entries→ backend returns all entries with relations- Each entry passed through
normalizeEntry()→ Normalizers setEntries(normalized)→ map populated,isLoaded = true- Mutations call
addEntry/updateEntry/removeEntryfor optimistic updates
useThemeStore
[!info] File:
stores/useThemeStore.ts
Theme toggle with localStorage persistence.
State
| Field | Type | Description |
|---|---|---|
theme |
'dark' | 'light' |
Current theme |
Actions
| Action | Description |
|---|---|
toggleTheme() |
Switches between dark/light |
setTheme(theme) |
Set specific theme |
Persistence
Uses Zustand persist middleware:
- Storage key:
showy-theme - Stored in
localStorage - On change: toggles
dark/lightclass ondocument.documentElement
useLibraryFiltersStore
[!info] File:
stores/useLibraryFiltersStore.ts
Persists Library filter/search/sort state across navigation so filters survive when navigating to entry details and back.
State
| Field | Type | Description |
|---|---|---|
activeTab |
FilterTab |
'all' | 'movies' | 'series' | 'watchlist' |
search |
string |
Search query |
sortField |
SortField |
'title' | 'date_added' | 'release_date' | 'rating' |
sortDir |
SortDir |
'asc' | 'desc' |
filters |
Filters |
{ genre: string; status: string; year: string } |
Actions
| Action | Description |
|---|---|
setActiveTab(tab) |
Set active tab filter |
setSearch(query) |
Set search query |
setSortField(field) |
Set sort field |
setSortDir(dir) |
Set sort direction |
setFilters(filters) |
Set genre/status/year filters |
clearFilters() |
Reset all filters to defaults |