diff --git a/react_frontend/package-lock.json b/react_frontend/package-lock.json index 508b7fb..cc75f64 100644 --- a/react_frontend/package-lock.json +++ b/react_frontend/package-lock.json @@ -1829,6 +1829,70 @@ "node": ">=14.0.0" } }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/core": { + "version": "1.8.1", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.1.0", + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/runtime": { + "version": "1.8.1", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/wasi-threads": { + "version": "1.1.0", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": { + "version": "1.1.1", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "^1.7.1", + "@emnapi/runtime": "^1.7.1", + "@tybys/wasm-util": "^0.10.1" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@tybys/wasm-util": { + "version": "0.10.1", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/tslib": { + "version": "2.8.1", + "dev": true, + "inBundle": true, + "license": "0BSD", + "optional": true + }, "node_modules/@tailwindcss/oxide-win32-arm64-msvc": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.2.2.tgz", diff --git a/react_frontend/public/images/default-backdrop.png b/react_frontend/public/images/default-backdrop.png new file mode 100644 index 0000000..40aecba Binary files /dev/null and b/react_frontend/public/images/default-backdrop.png differ diff --git a/react_frontend/public/images/default-logo.png b/react_frontend/public/images/default-logo.png new file mode 100644 index 0000000..aebb1a8 Binary files /dev/null and b/react_frontend/public/images/default-logo.png differ diff --git a/react_frontend/public/images/default-poster.png b/react_frontend/public/images/default-poster.png new file mode 100644 index 0000000..cbf4965 Binary files /dev/null and b/react_frontend/public/images/default-poster.png differ diff --git a/react_frontend/public/images/default-profile.png b/react_frontend/public/images/default-profile.png new file mode 100644 index 0000000..eacb96e Binary files /dev/null and b/react_frontend/public/images/default-profile.png differ diff --git a/react_frontend/public/images/default-still.png b/react_frontend/public/images/default-still.png new file mode 100644 index 0000000..40aecba Binary files /dev/null and b/react_frontend/public/images/default-still.png differ diff --git a/react_frontend/public/images/logo.png b/react_frontend/public/images/logo.png new file mode 100644 index 0000000..8ae2e69 Binary files /dev/null and b/react_frontend/public/images/logo.png differ diff --git a/react_frontend/src/App.tsx b/react_frontend/src/App.tsx index 46a5992..440609d 100644 --- a/react_frontend/src/App.tsx +++ b/react_frontend/src/App.tsx @@ -1,121 +1,24 @@ -import { useState } from 'react' -import reactLogo from './assets/react.svg' -import viteLogo from './assets/vite.svg' -import heroImg from './assets/hero.png' -import './App.css' +import { RouterProvider } from 'react-router-dom'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { TooltipProvider } from '@/components/ui/tooltip'; +import { router } from './router'; -function App() { - const [count, setCount] = useState(0) +const queryClient = new QueryClient({ + defaultOptions: { + queries: { + retry: 1, + refetchOnWindowFocus: false, + staleTime: 2 * 60 * 1000, + }, + }, +}); +export function App() { return ( - <> -
-
- - React logo - Vite logo -
-
-

Get started

-

- Edit src/App.tsx and save to test HMR -

-
- -
- -
- -
-
- -

Documentation

-

Your questions, answered

- -
-
- -

Connect with us

-

Join the Vite community

- -
-
- -
-
- - ) + + + + + + ); } - -export default App diff --git a/react_frontend/src/api/collections.ts b/react_frontend/src/api/collections.ts new file mode 100644 index 0000000..5f67c18 --- /dev/null +++ b/react_frontend/src/api/collections.ts @@ -0,0 +1,41 @@ +import { api } from '@/lib/api'; +import { normalizeCollection } from '@/lib/normalizers'; +import type { Collection } from '@/types'; + +export const collectionsApi = { + getAll: () => + api + .get('/collections') + .then((r) => r.data.map(normalizeCollection)), + + getById: (id: number) => + api + .get(`/collections/${id}`) + .then((r) => normalizeCollection(r.data)), + + create: (data: Partial) => + api.post('/collections', data).then((r) => r.data), + + update: (id: number, data: Partial) => + api.put(`/collections/${id}`, data).then((r) => normalizeCollection(r.data)), + + updateWithMedia: (id: number, formData: FormData) => + api + .put(`/collections/${id}`, formData, { + headers: { 'Content-Type': 'multipart/form-data' }, + }) + .then((r) => normalizeCollection(r.data)), + + delete: (id: number) => + api.delete(`/collections/${id}`).then((r) => r.data), + + addEntry: (collectionId: number, entryId: number) => + api + .post(`/collections/${collectionId}/entries`, { entry_id: entryId }) + .then((r) => r.data), + + removeEntry: (collectionId: number, entryId: number) => + api + .delete(`/collections/${collectionId}/entries/${entryId}`) + .then((r) => r.data), +}; diff --git a/react_frontend/src/api/entries.ts b/react_frontend/src/api/entries.ts new file mode 100644 index 0000000..0324077 --- /dev/null +++ b/react_frontend/src/api/entries.ts @@ -0,0 +1,58 @@ +import { api } from '@/lib/api'; +import { normalizeEntry } from '@/lib/normalizers'; +import type { Entry } from '@/types'; + +export const entriesApi = { + getAll: () => + api.get('/entries').then((r) => r.data.map(normalizeEntry)), + + getById: (id: number) => + api.get(`/entries/${id}`).then((r) => normalizeEntry(r.data)), + + create: (tmdb_id: number, is_tvserie: boolean) => + api.post('/entries', { tmdb_id, is_tvserie }).then((r) => normalizeEntry(r.data)), + + update: (id: number, data: Partial) => + api.put(`/entries/${id}`, data).then((r) => normalizeEntry(r.data)), + + updateRatings: ( + id: number, + ratings: { + user_rating?: number | null; + tmdb_rating?: number | null; + imdb_rating?: number | null; + rotten_tomatoes_rating?: number | null; + } + ) => api.put(`/entries/${id}/ratings`, ratings).then((r) => r.data), + + updateIds: ( + id: number, + ids: { tmdb_id?: number; imdb_id?: string; tvdb_id?: number } + ) => api.put(`/entries/${id}/ids`, ids).then((r) => r.data), + + delete: (id: number) => api.delete(`/entries/${id}`).then((r) => r.data), + + refresh: (id: number) => + api.put(`/entries/${id}/refresh`).then((r) => normalizeEntry(r.data)), + + fetchCollection: (id: number) => + api.put(`/entries/${id}/fetch-collection`).then((r) => r.data), + + getSeasons: (id: number) => + api.get(`/entries/${id}/seasons`).then((r) => Array.isArray(r.data) ? r.data : []), + + syncSeries: () => api.get('/entries/sync-series').then((r) => r.data), + + uploadMedia: (id: number, formData: FormData) => + api + .post(`/entries/${id}/media`, formData, { + headers: { 'Content-Type': 'multipart/form-data' }, + }) + .then((r) => r.data), + + setMediaSelected: (entryId: number, mediaId: number) => + api.put(`/entries/${entryId}/media/${mediaId}`).then((r) => r.data), + + deleteMedia: (entryId: number, mediaId: number) => + api.delete(`/entries/${entryId}/media/${mediaId}`).then((r) => r.data), +}; diff --git a/react_frontend/src/api/entry-seen.ts b/react_frontend/src/api/entry-seen.ts new file mode 100644 index 0000000..28f86ec --- /dev/null +++ b/react_frontend/src/api/entry-seen.ts @@ -0,0 +1,20 @@ +import { api } from '@/lib/api'; +import type { EntrySeen } from '@/types'; + +export const entrySeenApi = { + getAll: () => api.get('/entry-seen').then((r) => r.data), + + getById: (id: number) => + api.get(`/entry-seen/${id}`).then((r) => r.data), + + getByEntry: (entryId: number) => + api.get(`/entry-seen/by-entry/${entryId}`).then((r) => r.data), + + create: (data: { entry_id: number; date_seen: string; seen_with?: string }) => + api.post('/entry-seen', data).then((r) => r.data), + + update: (id: number, data: Partial) => + api.put(`/entry-seen/${id}`, data).then((r) => r.data), + + delete: (id: number) => api.delete(`/entry-seen/${id}`).then((r) => r.data), +}; diff --git a/react_frontend/src/api/episode-seen.ts b/react_frontend/src/api/episode-seen.ts new file mode 100644 index 0000000..3e5645e --- /dev/null +++ b/react_frontend/src/api/episode-seen.ts @@ -0,0 +1,27 @@ +import { api } from '@/lib/api'; +import type { EpisodeSeen } from '@/types'; + +export const episodeSeenApi = { + getAll: () => api.get('/episode-seen').then((r) => r.data), + + getById: (id: number) => + api.get(`/episode-seen/${id}`).then((r) => r.data), + + getByEpisode: (episodeId: number) => + api + .get(`/episode-seen/by-episode/${episodeId}`) + .then((r) => r.data), + + create: (data: { + entry_id: number; + episode_id: number; + date_seen: string; + seen_with?: string; + }) => api.post('/episode-seen', data).then((r) => r.data), + + update: (id: number, data: Partial) => + api.put(`/episode-seen/${id}`, data).then((r) => r.data), + + delete: (id: number) => + api.delete(`/episode-seen/${id}`).then((r) => r.data), +}; diff --git a/react_frontend/src/api/episodes.ts b/react_frontend/src/api/episodes.ts new file mode 100644 index 0000000..832fdce --- /dev/null +++ b/react_frontend/src/api/episodes.ts @@ -0,0 +1,9 @@ +import { api } from '@/lib/api'; +import type { Episode } from '@/types'; + +export const episodesApi = { + getByMonth: (startDate: string, endDate: string) => + api + .get(`/episodes/month/${startDate}/${endDate}`) + .then((r) => r.data), +}; diff --git a/react_frontend/src/api/people.ts b/react_frontend/src/api/people.ts new file mode 100644 index 0000000..4c809cf --- /dev/null +++ b/react_frontend/src/api/people.ts @@ -0,0 +1,9 @@ +import { api } from '@/lib/api'; +import type { People } from '@/types'; + +export const peopleApi = { + getAll: () => api.get('/people').then((r) => r.data), + + getById: (id: number) => + api.get(`/people/${id}`).then((r) => r.data), +}; diff --git a/react_frontend/src/api/seasons.ts b/react_frontend/src/api/seasons.ts new file mode 100644 index 0000000..231c1b2 --- /dev/null +++ b/react_frontend/src/api/seasons.ts @@ -0,0 +1,20 @@ +import { api } from '@/lib/api'; +import type { Season } from '@/types'; + +export const seasonsApi = { + getAll: () => api.get('/seasons').then((r) => r.data), + + getById: (id: number) => + api.get(`/seasons/${id}`).then((r) => r.data), + + getEpisodes: (id: number) => + api.get(`/seasons/${id}/episodes`).then((r) => r.data), + + create: (data: Partial) => + api.post('/seasons', data).then((r) => r.data), + + update: (id: number, data: Partial) => + api.put(`/seasons/${id}`, data).then((r) => r.data), + + delete: (id: number) => api.delete(`/seasons/${id}`).then((r) => r.data), +}; diff --git a/react_frontend/src/api/settings.ts b/react_frontend/src/api/settings.ts new file mode 100644 index 0000000..345119b --- /dev/null +++ b/react_frontend/src/api/settings.ts @@ -0,0 +1,9 @@ +import { api } from '@/lib/api'; +import type { Settings } from '@/types'; + +export const settingsApi = { + get: () => api.get('/settings').then((r) => r.data), + + update: (data: Partial) => + api.put('/settings', data).then((r) => r.data), +}; diff --git a/react_frontend/src/api/statistics.ts b/react_frontend/src/api/statistics.ts new file mode 100644 index 0000000..c11af02 --- /dev/null +++ b/react_frontend/src/api/statistics.ts @@ -0,0 +1,5 @@ +import { api } from '@/lib/api'; + +export const statisticsApi = { + get: () => api.get('/statistics').then((r) => r.data), +}; diff --git a/react_frontend/src/api/tmdb.ts b/react_frontend/src/api/tmdb.ts new file mode 100644 index 0000000..5ab428b --- /dev/null +++ b/react_frontend/src/api/tmdb.ts @@ -0,0 +1,53 @@ +import { api } from '@/lib/api'; +import type { TmdbEntry, TmdbPaginatedResponse, TmdbPerson } from '@/types'; + +export const tmdbApi = { + getPopularMovies: (page = 1) => + api + .get>('/entries/tmdb/popular/movie', { + params: { page }, + }) + .then((r) => r.data), + + getPopularTv: (page = 1) => + api + .get>('/entries/tmdb/popular/tv', { + params: { page }, + }) + .then((r) => r.data), + + getTrendingMovies: (page = 1) => + api + .get>('/entries/tmdb/trending/movie', { + params: { page }, + }) + .then((r) => r.data), + + getTrendingTv: (page = 1) => + api + .get>('/entries/tmdb/trending/tv', { + params: { page }, + }) + .then((r) => r.data), + + search: (query: string, page = 1) => + api + .get>('/entries/tmdb/search', { + params: { query, page }, + }) + .then((r) => r.data), + + getPopularPeople: (page = 1) => + api + .get>('/people/tmdb/popular', { + params: { page }, + }) + .then((r) => r.data), + + searchPeople: (query: string, page = 1) => + api + .get>('/people/tmdb/search', { + params: { query, page }, + }) + .then((r) => r.data), +}; diff --git a/react_frontend/src/components/collections/CollectionsGrid.tsx b/react_frontend/src/components/collections/CollectionsGrid.tsx new file mode 100644 index 0000000..5aab80c --- /dev/null +++ b/react_frontend/src/components/collections/CollectionsGrid.tsx @@ -0,0 +1,71 @@ +import { Link } from 'react-router-dom'; +import { getCollectionPosterUrl } from '@/lib/media-utils'; +import { Skeleton } from '@/components/ui/skeleton'; +import type { Collection } from '@/types'; + +interface CollectionCardProps { + collection: Collection; +} + +export function CollectionCard({ collection }: CollectionCardProps) { + return ( + +
+ {collection.name} +
+

+ {collection.name} +

+
+
+ + ); +} + +export function CollectionCardSkeleton() { + return ; +} + +interface CollectionsGridProps { + collections: Collection[]; + isLoading?: boolean; +} + +export function CollectionsGrid({ + collections, + isLoading, +}: CollectionsGridProps) { + if (isLoading) { + return ( +
+ {Array.from({ length: 12 }).map((_, i) => ( + + ))} +
+ ); + } + + if (collections.length === 0) { + return ( +
+ No collections found. +
+ ); + } + + return ( +
+ {collections.map((collection) => ( + + ))} +
+ ); +} diff --git a/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx b/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx new file mode 100644 index 0000000..fcf595f --- /dev/null +++ b/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx @@ -0,0 +1,81 @@ +import { useState } from 'react'; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Input } from '@/components/ui/input'; +import { Checkbox } from '@/components/ui/checkbox'; +import { ScrollArea } from '@/components/ui/scroll-area'; +import { useCollections } from '@/hooks/useCollections'; +import { collectionsApi } from '@/api/collections'; +import type { Collection } from '@/types'; + +interface AddEntryToCollectionDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + entryId: number; + entryCollections?: Collection[]; +} + +export function AddEntryToCollectionDialog({ + open, + onOpenChange, + entryId, + entryCollections = [], +}: AddEntryToCollectionDialogProps) { + const [search, setSearch] = useState(''); + const { data: allCollections = [] } = useCollections(); + const entryCollectionIds = new Set(entryCollections.map((c) => c.id)); + + const filtered = allCollections.filter((c) => + c.name.toLowerCase().includes(search.toLowerCase()) + ); + + const handleToggle = async (collectionId: number, checked: boolean) => { + if (checked) { + await collectionsApi.addEntry(collectionId, entryId); + } else { + await collectionsApi.removeEntry(collectionId, entryId); + } + }; + + return ( + + + + Add to Collection + + setSearch(e.target.value)} + /> + +
+ {filtered.map((collection) => ( + + ))} + {filtered.length === 0 && ( +

+ No collections found. +

+ )} +
+
+
+
+ ); +} diff --git a/react_frontend/src/components/dialogs/CollectionEditDialog.tsx b/react_frontend/src/components/dialogs/CollectionEditDialog.tsx new file mode 100644 index 0000000..328067a --- /dev/null +++ b/react_frontend/src/components/dialogs/CollectionEditDialog.tsx @@ -0,0 +1,203 @@ +import { useState, useRef } from 'react'; +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Textarea } from '@/components/ui/textarea'; +import { ImageIcon } from 'lucide-react'; +import { useUpdateCollection } from '@/hooks/useCollections'; +import type { Collection } from '@/types'; + +interface CollectionEditDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + collection: Collection; +} + +export function CollectionEditDialog({ + open, + onOpenChange, + collection, +}: CollectionEditDialogProps) { + const [name, setName] = useState(collection.name); + const [description, setDescription] = useState(collection.description || ''); + const [userRating, setUserRating] = useState( + collection.user_rating?.toString() || '' + ); + const [posterFile, setPosterFile] = useState(null); + const [backdropFile, setBackdropFile] = useState(null); + const [posterPreview, setPosterPreview] = useState(null); + const [backdropPreview, setBackdropPreview] = useState(null); + + const posterInputRef = useRef(null); + const backdropInputRef = useRef(null); + + const updateCollection = useUpdateCollection(); + + const handlePosterChange = (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (file) { + setPosterFile(file); + setPosterPreview(URL.createObjectURL(file)); + } + }; + + const handleBackdropChange = (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (file) { + setBackdropFile(file); + setBackdropPreview(URL.createObjectURL(file)); + } + }; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + const formData = new FormData(); + formData.append('name', name); + formData.append('description', description); + formData.append('userRating', userRating || '0'); + + if (posterFile) { + formData.append('poster', posterFile); + } + if (backdropFile) { + formData.append('backdrop', backdropFile); + } + + updateCollection.mutate( + { id: collection.id, data: formData }, + { onSuccess: () => onOpenChange(false) } + ); + }; + + return ( + + + + Edit Collection + +
+
+ + setName(e.target.value)} + required + /> +
+ +
+ +