135 lines
4.3 KiB
Markdown
135 lines
4.3 KiB
Markdown
---
|
|
title: Hooks
|
|
tags:
|
|
- frontend
|
|
- hooks
|
|
- react-query
|
|
---
|
|
|
|
# Hooks
|
|
|
|
Custom hooks in `react_frontend/src/hooks/`. All query hooks wrap TanStack Query. All mutation hooks invalidate relevant caches and update [[Stores|Zustand store]] when applicable.
|
|
|
|
---
|
|
|
|
## useEntries
|
|
|
|
> [!info] File: `hooks/useEntries.ts`
|
|
|
|
The main library hooks. Mutations update [[Stores|useLibraryStore]] optimistically.
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useLibrary()` | Query | Fetch all entries → loads into Zustand store. Runs once on mount. |
|
|
| `useEntry(id)` | Query | Single entry by ID (triggers lazy refresh on backend) |
|
|
| `useEntrySeasons(id)` | Query | Seasons for an entry |
|
|
| `useCreateEntry()` | Mutation | `POST /entries` → adds to Zustand store |
|
|
| `useUpdateEntry()` | Mutation | `PUT /entries/:id` → updates Zustand store |
|
|
| `useDeleteEntry()` | Mutation | `DELETE /entries/:id` → removes from Zustand store |
|
|
| `useRefreshEntry()` | Mutation | `PUT /entries/:id/refresh` |
|
|
| `useUpdateEntryRatings()` | Mutation | `PUT /entries/:id/ratings` |
|
|
| `useUploadMedia()` | Mutation | `POST /entries/:id/media` |
|
|
|
|
## useCollections
|
|
|
|
> [!info] File: `hooks/useCollections.ts`
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useCollections()` | Query | All collections |
|
|
| `useCollection(id)` | Query | Single collection with entries |
|
|
| `useCreateCollection()` | Mutation | Create user collection |
|
|
| `useUpdateCollection()` | Mutation | Update collection (with media) |
|
|
| `useDeleteCollection()` | Mutation | Delete collection |
|
|
| `useAddEntryToCollection()` | Mutation | Add entry to collection |
|
|
| `useRemoveEntryFromCollection()` | Mutation | Remove entry from collection |
|
|
|
|
## useSeasons
|
|
|
|
> [!info] File: `hooks/useSeasons.ts`
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useSeason(id)` | Query | Season by ID (includes episodes) |
|
|
| `useSeasonEpisodes(id)` | Query | Episodes for a season |
|
|
|
|
## useEntrySeen
|
|
|
|
> [!info] File: `hooks/useEntrySeen.ts`
|
|
|
|
See [[Watch Tracking]].
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useEntrySeenByEntry(entryId)` | Query | Watch records for an entry |
|
|
| `useCreateEntrySeen()` | Mutation | Create watch record |
|
|
| `useUpdateEntrySeen()` | Mutation | Update watch record |
|
|
| `useDeleteEntrySeen()` | Mutation | Delete watch record |
|
|
|
|
## useEpisodeSeen
|
|
|
|
> [!info] File: `hooks/useEpisodeSeen.ts`
|
|
|
|
See [[Watch Tracking]].
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useEpisodeSeenByEpisode(episodeId)` | Query | Watch records for an episode |
|
|
| `useCreateEpisodeSeen()` | Mutation | Create episode watch record |
|
|
| `useUpdateEpisodeSeen()` | Mutation | Update episode watch record |
|
|
| `useDeleteEpisodeSeen()` | Mutation | Delete episode watch record |
|
|
|
|
## usePeople
|
|
|
|
> [!info] File: `hooks/usePeople.ts`
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `usePerson(id)` | Query | Person by ID (lazy-fetch from TMDB) |
|
|
| `usePersonCredits(id)` | Query | Person's credits |
|
|
| `usePopularPeople(limit)` | Query | Popular people (local) |
|
|
| `useSearchPeople(query)` | Query | Search people (local) |
|
|
|
|
## useTmdb
|
|
|
|
> [!info] File: `hooks/useTmdb.ts`
|
|
|
|
Infinite queries for TMDB browse/search pages. All return paginated results.
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useTmdbTrending(type)` | Infinite Query | Trending movies/tv |
|
|
| `useTmdbPopular(type)` | Infinite Query | Popular movies/tv |
|
|
| `useTmdbTopRated(type)` | Infinite Query | Top-rated movies/tv |
|
|
| `useTmdbUpcoming()` | Infinite Query | Upcoming movies |
|
|
| `useTmdbSearch(query)` | Infinite Query | Multi-search |
|
|
| `useTmdbPopularPeople()` | Infinite Query | Popular people |
|
|
| `useTmdbSearchPeople(query)` | Infinite Query | People search |
|
|
|
|
## useStatistics
|
|
|
|
> [!info] File: `hooks/useStatistics.ts`
|
|
|
|
See [[Statistics]].
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useAllTimeWatchTime()` | Query | Total watch time (all time) |
|
|
| `useYearlyWatchTime(year)` | Query | Watch time by month |
|
|
| `useYearlyWatchCount(year)` | Query | Watch count by month |
|
|
| `useWatchdayDistribution()` | Query | Day-of-week distribution |
|
|
|
|
## useEpisodes
|
|
|
|
> [!info] File: `hooks/useEpisodes.ts`
|
|
|
|
| Hook | Type | Description |
|
|
|---|---|---|
|
|
| `useEpisodesByMonth(start, end)` | Query | Episodes airing in date range (for [[Calendar]]) |
|
|
|
|
## useDebounce
|
|
|
|
> [!info] File: `hooks/useDebounce.ts`
|
|
|
|
Utility hook: `useDebounce(value, delay)` — returns debounced value. Used by search inputs.
|