Updated the Obsidian docs-vault

This commit is contained in:
Mohammed Abad committed 2026-04-22 14:48:43 +01:00
1 parent 72fd77ee01
commit 260282a0e2
36 files changed
+3497 -144

No files matched your search

+116 -19
View File
@@ -1,32 +1,129 @@
---
title: Frontend
tags:
- frontend
- react
- typescript
---
# Frontend
## Overview
React 18 + TypeScript SPA built with Vite. Uses shadcn/ui for components, TanStack Query for server state, Zustand for client state, and Recharts for charts.
React 19 + TypeScript SPA built with Vite 8. Located in `react_frontend/`.
| Concern | Solution |
|---|---|
| UI Components | shadcn/ui (base-nova theme) + Tailwind CSS 4 |
| Server State | TanStack Query 5 (react-query) |
| Client State | Zustand 5 → [[Stores]] |
| Routing | React Router 7 → [[Routing]] |
| Forms | react-hook-form 7 + Zod 4 |
| Charts | Recharts 3 → [[Statistics]] |
| Toasts | Sonner |
| Icons | Lucide |
| Dates | date-fns |
| HTTP | Axios |
## Entry Point
```
main.tsx → App.tsx → QueryClientProvider → TooltipProvider → RouterProvider → Toaster
```
**QueryClient config:**
- `retry: 1`
- `refetchOnWindowFocus: false`
- `staleTime: 2 minutes`
## Architecture
```mermaid
graph TD
subgraph UI["UI Layer"]
Pages --> Components
Components --> ShadcnUI[shadcn/ui]
end
subgraph State["State Layer"]
Pages --> Hooks
Hooks --> TQ[TanStack Query]
Hooks --> Store[Zustand Store]
TQ --> APIClients[API Clients]
end
APIClients --> |Axios| Backend[Backend REST API]
```
### Data Flow
1. App mounts → `useLibrary()` fetches all entries → [[Stores|useLibraryStore]] loaded
2. Pages use [[Hooks]] wrapping TanStack Query for server data
3. Mutations update Zustand optimistically → invalidate Query caches
4. [[Normalizers]] transform backend responses to frontend [[Types]]
## Project Structure
```
react_frontend/src/
├── api/ → [[API Clients]] (11 Axios modules)
├── components/ → [[Components]] (by category)
│ ├── dashboard/ → Chart components
│ ├── dialogs/ → Modal dialogs
│ ├── entries/ → Entry-related components
│ ├── layout/ → AppLayout, Sidebar
│ ├── skeletons/ → Loading skeletons
│ └── ui/ → shadcn/ui primitives
├── hooks/ → [[Hooks]] (10 hook files)
├── lib/ → Utilities
│ ├── api.ts → Axios instance
│ ├── media-utils.ts → [[Media Utilities]]
│ ├── normalizers.ts → [[Normalizers]]
│ └── utils.ts → cn() helper
├── pages/ → [[Pages]] (17 route pages)
├── stores/ → [[Stores]] (2 Zustand stores)
└── types/ → [[Types]] (TypeScript interfaces)
```
## Vite Configuration
- React plugin + Tailwind CSS plugin
- Path alias: `@/` → `src/`
- Dev proxy: `/api` → `http://showyback.coolguy.space`
## Key Patterns
- **State Management**: `useLibraryStore` (Zustand) holds all entries; TanStack Query for server data
- **Forms**: react-hook-form + zod for validation
- **Routing**: React Router v6 with nested routes
- **Styling**: Tailwind CSS + shadcn/ui components
### Library-First Architecture
## Important Pages
The entire entry library is loaded into a Zustand `Map<number, Entry>` on startup. This enables:
- **Dashboard** — [[Statistics]] charts (CouchDayChart, LibraryGrowthChart)
- **Entry Details** — Entry info, seasons list, watch history
- **[[SeasonPage]]** — Season episodes with watch progress
- **[[EpisodePage]]** — Episode details with prev/next navigation
- **[[Settings Page]]** — App config + maintenance cleanup
- O(1) entry lookup by ID
- TMDB entries checked against library by TMDB ID → if present, local version displayed
- Optimistic UI updates
## Navigation
### Lazy Page Loading
See [[Navigation]] for breadcrumb patterns.
All 17 pages use `React.lazy()` with custom skeleton fallbacks via `<Suspense>`. See [[Routing]].
## API Clients
### Form Pattern
Located in `react_frontend/src/api/`:
- `settings.ts` — Settings CRUD
- `maintenance.ts` — Orphan file/record scan and cleanup
- `seasons.ts` — Season and episode data
- `entries.ts` — Entry CRUD
Forms use `react-hook-form` with `zodResolver`:
```
useForm({ resolver: zodResolver(schema), values }) → handleSubmit → mutation.mutate
```
### Toast Notifications
All mutation success/error feedback via Sonner toasts.
## See Also
- [[Routing]] — All 17 routes
- [[Pages]] — Every page component
- [[Components]] — UI components by category
- [[Hooks]] — Custom hooks
- [[Stores]] — State management
- [[API Clients]] — Backend communication
- [[Types]] — TypeScript types
- [[Navigation]] — Breadcrumbs