diff --git a/react_frontend/src/api/collections.ts b/react_frontend/src/api/collections.ts index 5f67c18..f295d8d 100644 --- a/react_frontend/src/api/collections.ts +++ b/react_frontend/src/api/collections.ts @@ -31,7 +31,7 @@ export const collectionsApi = { addEntry: (collectionId: number, entryId: number) => api - .post(`/collections/${collectionId}/entries`, { entry_id: entryId }) + .post(`/collections/${collectionId}/entries/${entryId}`, {}) .then((r) => r.data), removeEntry: (collectionId: number, entryId: number) => diff --git a/react_frontend/src/api/entries.ts b/react_frontend/src/api/entries.ts index 0324077..ce2a99e 100644 --- a/react_frontend/src/api/entries.ts +++ b/react_frontend/src/api/entries.ts @@ -13,17 +13,18 @@ export const entriesApi = { 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)), + api.put(`/entries/${id}`, { entryData: data }).then((r) => normalizeEntry(r.data)), updateRatings: ( id: number, ratings: { + id?: number; 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), + ) => api.put(`/entries/${id}/ratings`, { entryRatings: ratings }).then((r) => r.data), updateIds: ( id: number, diff --git a/react_frontend/src/api/people.ts b/react_frontend/src/api/people.ts index 4c809cf..6ed1d8d 100644 --- a/react_frontend/src/api/people.ts +++ b/react_frontend/src/api/people.ts @@ -1,9 +1,37 @@ import { api } from '@/lib/api'; -import type { People } from '@/types'; +import type { People, Credit } from '@/types'; + +export interface TmdbFilmographyItem { + id: number; + title?: string; + name?: string; + poster_path: string | null; + release_date?: string; + first_air_date?: string; + media_type: 'movie' | 'tv'; + character?: string; + job?: string; + department?: string; + credit_id?: string; +} + +export interface TmdbFilmographyResponse { + cast: TmdbFilmographyItem[]; + crew: TmdbFilmographyItem[]; +} export const peopleApi = { getAll: () => api.get('/people').then((r) => r.data), getById: (id: number) => api.get(`/people/${id}`).then((r) => r.data), + + getCredits: (id: number) => + api.get(`/people/${id}/credits`).then((r) => r.data), + + getTmdbFilmography: (id: number) => + api.get(`/people/${id}/tmdb-filmography`).then((r) => r.data), + + fetchByTmdbId: (tmdb_id: number) => + api.post('/people/fetch', { tmdb_id }).then((r) => r.data), }; diff --git a/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx b/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx index fcf595f..a0b5d9c 100644 --- a/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx +++ b/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx @@ -9,35 +9,69 @@ 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 { useQueryClient } from '@tanstack/react-query'; import { collectionsApi } from '@/api/collections'; +import { collectionKeys } from '@/hooks/useCollections'; 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 [pending, setPending] = useState>(new Set()); const { data: allCollections = [] } = useCollections(); - const entryCollectionIds = new Set(entryCollections.map((c) => c.id)); + const queryClient = useQueryClient(); const filtered = allCollections.filter((c) => c.name.toLowerCase().includes(search.toLowerCase()) ); + const isInCollection = (collectionId: number) => + allCollections + .find((c) => c.id === collectionId) + ?.entries?.some((e) => e.id === entryId) ?? false; + const handleToggle = async (collectionId: number, checked: boolean) => { - if (checked) { - await collectionsApi.addEntry(collectionId, entryId); - } else { - await collectionsApi.removeEntry(collectionId, entryId); + setPending((prev) => new Set(prev).add(collectionId)); + + // Optimistically update the cache so the checkbox reflects immediately + queryClient.setQueryData(collectionKeys.all, (old) => + old?.map((col) => { + if (col.id !== collectionId) return col; + if (checked) { + // Add a stub entry so isInCollection() returns true right away + const entries = col.entries ?? []; + const already = entries.some((e) => e.id === entryId); + if (already) return col; + return { ...col, entries: [...entries, { id: entryId } as Collection['entries'][0]] }; + } else { + return { ...col, entries: (col.entries ?? []).filter((e) => e.id !== entryId) }; + } + }) + ); + + try { + if (checked) { + await collectionsApi.addEntry(collectionId, entryId); + } else { + await collectionsApi.removeEntry(collectionId, entryId); + } + } finally { + setPending((prev) => { + const next = new Set(prev); + next.delete(collectionId); + return next; + }); + // Refetch to get authoritative data (also refreshes CollectionsSection in EntryDetailsPage) + queryClient.invalidateQueries({ queryKey: collectionKeys.all }); } }; @@ -54,20 +88,25 @@ export function AddEntryToCollectionDialog({ />
- {filtered.map((collection) => ( - - ))} + {filtered.map((collection) => { + const checked = isInCollection(collection.id); + const loading = pending.has(collection.id); + return ( + + ); + })} {filtered.length === 0 && (

No collections found. diff --git a/react_frontend/src/components/dialogs/EntrySettingsDialog.tsx b/react_frontend/src/components/dialogs/EntrySettingsDialog.tsx index d9e9f45..adcb339 100644 --- a/react_frontend/src/components/dialogs/EntrySettingsDialog.tsx +++ b/react_frontend/src/components/dialogs/EntrySettingsDialog.tsx @@ -6,7 +6,11 @@ import { } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; import { Switch } from '@/components/ui/switch'; +import { Separator } from '@/components/ui/separator'; import { useUpdateEntry } from '@/hooks/useEntries'; +import { RatingDialog } from '@/components/dialogs/RatingDialog'; +import { useState } from 'react'; +import { Star } from 'lucide-react'; import type { Entry } from '@/types'; interface EntrySettingsDialogProps { @@ -21,36 +25,76 @@ export function EntrySettingsDialog({ entry, }: EntrySettingsDialogProps) { const updateEntry = useUpdateEntry(); + const [showRating, setShowRating] = useState(false); const handleToggle = (field: keyof Entry, value: boolean) => { updateEntry.mutate({ id: entry.id, data: { [field]: value } }); }; - const settings = [ + const boolSettings = [ { field: 'favorit' as const, label: 'Favorite' }, { field: 'hidden' as const, label: 'Hidden' }, { field: 'watchlist' as const, label: 'Watchlist' }, + { field: 'show_in_calendar' as const, label: 'Show in Calendar' }, + { field: 'auto_sync' as const, label: 'Auto Sync' }, ]; + const userRating = entry.entryRatings?.user_rating; + return ( -

- - - Entry Settings - -
- {settings.map(({ field, label }) => ( -
- - handleToggle(field, checked)} - /> + <> + + + + Entry Settings +

{entry.title}

+
+
+ {boolSettings.map(({ field, label }) => ( +
+ + handleToggle(field, checked)} + /> +
+ ))} + +
+ +
- ))} -
-
-
+
+ +
+ + + ); } diff --git a/react_frontend/src/components/dialogs/RatingDialog.tsx b/react_frontend/src/components/dialogs/RatingDialog.tsx new file mode 100644 index 0000000..a2a7a42 --- /dev/null +++ b/react_frontend/src/components/dialogs/RatingDialog.tsx @@ -0,0 +1,81 @@ +import { useState } from 'react'; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Star } from 'lucide-react'; +import { useUpdateEntryRatings } from '@/hooks/useEntries'; +import type { Entry } from '@/types'; + +interface RatingDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + entry: Entry; +} + +export function RatingDialog({ open, onOpenChange, entry }: RatingDialogProps) { + const currentRating = entry.entryRatings?.user_rating ?? 0; + const [hovered, setHovered] = useState(null); + const [selected, setSelected] = useState(currentRating); + const updateRatings = useUpdateEntryRatings(); + + const displayRating = hovered ?? selected; + + const handleRate = (rating: number) => { + setSelected(rating); + updateRatings.mutate({ + id: entry.id, + ratings: { + id: entry.entryRatings?.id, + user_rating: rating || null, + }, + }); + onOpenChange(false); + }; + + return ( + + + + Rate +

{entry.title}

+
+ +
+
+ {Array.from({ length: 10 }, (_, i) => i + 1).map((star) => ( + + ))} +
+ +

+ {displayRating > 0 ? `${displayRating} / 10` : '—'} +

+ + {selected > 0 && ( + + )} +
+
+
+ ); +} diff --git a/react_frontend/src/hooks/useEntries.ts b/react_frontend/src/hooks/useEntries.ts index 11c0845..b03e2f6 100644 --- a/react_frontend/src/hooks/useEntries.ts +++ b/react_frontend/src/hooks/useEntries.ts @@ -66,8 +66,11 @@ export function useUpdateEntry() { mutationFn: ({ id, data }: { id: number; data: Partial }) => entriesApi.update(id, data), onSuccess: (entry) => { + // Update library store immediately so the UI reflects the change updateEntry(entry.id, entry); + // Invalidate both the detail query and the library list queryClient.invalidateQueries({ queryKey: entryKeys.detail(entry.id) }); + queryClient.invalidateQueries({ queryKey: entryKeys.all }); }, }); } @@ -98,6 +101,24 @@ export function useRefreshEntry() { }); } +export function useUpdateEntryRatings() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ + id, + ratings, + }: { + id: number; + ratings: Parameters[1]; + }) => entriesApi.updateRatings(id, ratings), + onSuccess: (_data, { id }) => { + queryClient.invalidateQueries({ queryKey: entryKeys.detail(id) }); + queryClient.invalidateQueries({ queryKey: entryKeys.all }); + }, + }); +} + export function useUploadMedia() { const queryClient = useQueryClient(); diff --git a/react_frontend/src/hooks/usePeople.ts b/react_frontend/src/hooks/usePeople.ts index 99a854f..69d6e0f 100644 --- a/react_frontend/src/hooks/usePeople.ts +++ b/react_frontend/src/hooks/usePeople.ts @@ -1,9 +1,11 @@ -import { useQuery } from '@tanstack/react-query'; +import { useQuery, useMutation } from '@tanstack/react-query'; import { peopleApi } from '@/api/people'; export const peopleKeys = { all: ['people'] as const, detail: (id: number) => ['people', id] as const, + credits: (id: number) => ['people', id, 'credits'] as const, + tmdbFilmography: (id: number) => ['people', id, 'tmdb-filmography'] as const, }; export function usePerson(id: number) { @@ -13,3 +15,26 @@ export function usePerson(id: number) { enabled: !!id, }); } + +export function usePersonCredits(id: number) { + return useQuery({ + queryKey: peopleKeys.credits(id), + queryFn: () => peopleApi.getCredits(id), + enabled: !!id, + }); +} + +export function usePersonTmdbFilmography(id: number) { + return useQuery({ + queryKey: peopleKeys.tmdbFilmography(id), + queryFn: () => peopleApi.getTmdbFilmography(id), + enabled: !!id, + staleTime: 10 * 60 * 1000, + }); +} + +export function useFetchPersonByTmdbId() { + return useMutation({ + mutationFn: (tmdb_id: number) => peopleApi.fetchByTmdbId(tmdb_id), + }); +} diff --git a/react_frontend/src/lib/media-utils.ts b/react_frontend/src/lib/media-utils.ts index d95f567..275e9fb 100644 --- a/react_frontend/src/lib/media-utils.ts +++ b/react_frontend/src/lib/media-utils.ts @@ -59,6 +59,21 @@ export function getTmdbPosterUrl( return getTmdbImageUrl(posterPath, size); } +export function getCollectionBackdropUrl(collection: Collection): string { + if (collection.medias) { + const selectedBackdrop = collection.medias.find( + (m: Media) => m.type === 'backdrop' && m.is_selected + ); + if (selectedBackdrop?.path) { + return getMediaUrl('collections', 'backdrops', 'full', selectedBackdrop.path); + } + } + if (collection.backdrop_path) { + return getTmdbImageUrl(collection.backdrop_path, 'w780'); + } + return getCollectionPosterUrl(collection); +} + export function getCollectionPosterUrl(collection: Collection): string { if (collection.medias) { const selectedPoster = collection.medias.find( diff --git a/react_frontend/src/pages/CalendarPage.tsx b/react_frontend/src/pages/CalendarPage.tsx index 465e6a9..6d3fdd7 100644 --- a/react_frontend/src/pages/CalendarPage.tsx +++ b/react_frontend/src/pages/CalendarPage.tsx @@ -1,10 +1,12 @@ import { useState, useMemo } from 'react'; +import { Link } from 'react-router-dom'; import { format, startOfMonth, endOfMonth, eachDayOfInterval, getDay, addMonths, subMonths, isSameDay } from 'date-fns'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { useEpisodesByMonth } from '@/hooks/useEpisodes'; -import { getTmdbPosterUrl } from '@/lib/media-utils'; -import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; +import { getTmdbPosterUrl, getPosterUrl } from '@/lib/media-utils'; +import { Tooltip, TooltipContent, TooltipTrigger, TooltipProvider } from '@/components/ui/tooltip'; +import type { Episode } from '@/types'; const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; @@ -35,8 +37,8 @@ export function CalendarPage() { }, [episodes]); return ( -
-
+
+

Calendar

- + {format(currentDate, 'MMMM yyyy')}
- {/* Calendar Grid */} -
- {/* Day headers */} -
- {DAYS.map((day) => ( -
- {day} -
- ))} -
+ {/* Calendar Grid — fills remaining height */} + +
+ {/* Day headers */} +
+ {DAYS.map((day) => ( +
+ {day} +
+ ))} +
- {/* Day cells */} -
- {/* Empty cells for offset */} - {Array.from({ length: startDayOfWeek }).map((_, i) => ( -
- ))} + {/* Day cells */} +
+ {/* Empty cells for offset */} + {Array.from({ length: startDayOfWeek }).map((_, i) => ( +
+ ))} - {days.map((day) => { - const key = format(day, 'yyyy-MM-dd'); - const dayEpisodes = episodesByDate.get(key) || []; - const isToday = isSameDay(day, new Date()); + {days.map((day) => { + const key = format(day, 'yyyy-MM-dd'); + const dayEpisodes = episodesByDate.get(key) || []; + const isToday = isSameDay(day, new Date()); - return ( -
- - {format(day, 'd')} - -
- {dayEpisodes.slice(0, 3).map((ep) => ( - - -
- {ep.still_path && ( - - )} - - S{ep.season_id} E{ep.episode_number} - -
-
- -

{ep.name}

-

- Episode {ep.episode_number} -

-
-
- ))} - {dayEpisodes.length > 3 && ( - - +{dayEpisodes.length - 3} more - - )} + + {format(day, 'd')} + +
+ {dayEpisodes.slice(0, 4).map((ep) => ( + + ))} + {dayEpisodes.length > 4 && ( + + +{dayEpisodes.length - 4} more + + )} +
-
- ); - })} + ); + })} +
-
+
); } + +function EpisodeCalendarItem({ episode }: { episode: Episode }) { + type EpisodeWithEntry = Episode & { + entry?: { + id: number; + title?: string; + poster_path?: string | null; + medias?: unknown[]; + isInLibrary?: boolean; + }; + }; + const ep = episode as EpisodeWithEntry; + const entry = ep.entry; + const entryId = entry?.id; + const entryTitle = entry?.title ?? ''; + const seasonId = episode.season_id; + + const posterSrc = episode.still_path + ? getTmdbPosterUrl(episode.still_path, 'w92') + : entry + ? getPosterUrl({ ...(entry as Parameters[0]), isInLibrary: false }) + : undefined; + + const seasonLabel = `S${String(seasonId).padStart(2, '0')}`; + const episodeLabel = `E${String(episode.episode_number).padStart(2, '0')}`; + + const content = ( +
+ {posterSrc && ( + + )} +
+

+ {entryTitle} +

+

+ {seasonLabel} {episodeLabel} +

+
+
+ ); + + return ( + + + {entryId ? ( + + {content} + + ) : ( +
{content}
+ )} +
+ +

{entryTitle}

+ {episode.name && ( +

{episode.name}

+ )} +

+ {seasonLabel} {episodeLabel} +

+
+
+ ); +} diff --git a/react_frontend/src/pages/EntryDetailsPage.tsx b/react_frontend/src/pages/EntryDetailsPage.tsx index 208039d..7fd1317 100644 --- a/react_frontend/src/pages/EntryDetailsPage.tsx +++ b/react_frontend/src/pages/EntryDetailsPage.tsx @@ -1,12 +1,14 @@ import { useState } from 'react'; -import { useParams } from 'react-router-dom'; +import { useParams, Link } from 'react-router-dom'; import { useEntry, useEntrySeasons, useRefreshEntry } from '@/hooks/useEntries'; import { useEntrySeenByEntry, useDeleteEntrySeen } from '@/hooks/useEntrySeen'; +import { useCollections } from '@/hooks/useCollections'; import { useLibraryStore } from '@/stores/useLibraryStore'; import { Skeleton } from '@/components/ui/skeleton'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Separator } from '@/components/ui/separator'; +import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'; import { DropdownMenu, DropdownMenuContent, @@ -33,20 +35,21 @@ import { import { CastList } from '@/components/entries/CastList'; import { SeasonsContainer } from '@/components/entries/SeasonsContainer'; import { EpisodeWatchHistory } from '@/components/entries/EpisodeWatchHistory'; -import { CollectionsGrid } from '@/components/collections/CollectionsGrid'; import { EntrySettingsDialog } from '@/components/dialogs/EntrySettingsDialog'; import { EntrySeenDialog } from '@/components/dialogs/EntrySeenDialog'; import { EntryMediaDialog } from '@/components/dialogs/EntryMediaDialog'; import { AddEntryToCollectionDialog } from '@/components/dialogs/AddEntryToCollectionDialog'; +import { RatingDialog } from '@/components/dialogs/RatingDialog'; import { getPosterUrl, getBackdropUrl, + getCollectionBackdropUrl, getYear, formatRuntime, formatDate, } from '@/lib/media-utils'; import { useUpdateEntry } from '@/hooks/useEntries'; -import type { Entry } from '@/types'; +import type { Collection, Entry } from '@/types'; export function EntryDetailsPage() { const { id } = useParams<{ id: string }>(); @@ -64,11 +67,11 @@ export function EntryDetailsPage() { ? { ...libraryEntry, ...entry, isInLibrary: true } : entry || libraryEntry; - // Dialog states const [showSettings, setShowSettings] = useState(false); const [showSeenDialog, setShowSeenDialog] = useState(false); const [showMediaDialog, setShowMediaDialog] = useState(false); const [showCollectionDialog, setShowCollectionDialog] = useState(false); + const [showRatingDialog, setShowRatingDialog] = useState(false); if (isLoading || !displayEntry) { return ; @@ -86,37 +89,120 @@ export function EntryDetailsPage() { }; return ( -
- {/* Hero Section */} -
- {backdrop && ( +
+ {/* Backdrop banner */} +
+ {backdrop ? ( + ) : ( +
)} -
+
+
-
- {/* Poster */} -
+ {/* Main content */} +
+ {/* Two-column header: sticky poster | info */} +
+ {/* LEFT: Sticky poster + actions */} +
{e.title} +
+ + + + + + + + + + setShowRatingDialog(true)}> + + Rate this + + + updateEntry.mutate({ id: e.id, data: { hidden: !e.hidden } }) + } + > + + {e.hidden ? 'Unhide' : 'Hide'} + + refreshEntry.mutate(e.id)}> + + Refresh details + + setShowCollectionDialog(true)}> + + Add to collection + + setShowMediaDialog(true)}> + + Manage media + + setShowSettings(true)}> + + Settings + + + +
- {/* Info */} -
-
-

{e.title}

- {e.status && ( - {e.status} + {/* RIGHT: Entry info */} +
+ {/* Title + status + director */} +
+
+

{e.title}

+ {e.status && ( + + {e.status} + + )} +
+ {director && ( +

+ by{' '} + + {director.people?.name} + +

)}
+ {/* Meta */}
{e.release_date && ( @@ -138,12 +224,6 @@ export function EntryDetailsPage() { {formatRuntime(e.runtime)} )} - {director && ( - <> - • - Dir. {director.people?.name} - - )}
{/* Genres */} @@ -158,145 +238,83 @@ export function EntryDetailsPage() { )} {/* Ratings */} -
- {e.entryRatings?.user_rating != null && - e.entryRatings.user_rating > 0 && ( -
- - - {e.entryRatings.user_rating}/10 - - You -
+
+ {e.entryRatings?.imdb_rating != null && + e.entryRatings.imdb_rating > 0 && ( + + IMDb: + {e.entryRatings.imdb_rating}/10 + )} {e.entryRatings?.tmdb_rating != null && e.entryRatings.tmdb_rating > 0 && ( -
- - {e.entryRatings.tmdb_rating.toFixed(1)} - - TMDB -
- )} - {e.entryRatings?.imdb_rating != null && - e.entryRatings.imdb_rating > 0 && ( -
- - {e.entryRatings.imdb_rating} - - IMDb -
+ + TMDB: + {e.entryRatings.tmdb_rating.toFixed(1)}/10 + )} + {e.entryRatings?.user_rating != null && + e.entryRatings.user_rating > 0 ? ( + + ) : ( + + )}
- {/* Actions */} -
- - - - - - - - - - - updateEntry.mutate({ - id: e.id, - data: { hidden: !e.hidden }, - }) - } - > - - {e.hidden ? 'Unhide' : 'Hide'} - - refreshEntry.mutate(e.id)} - > - - Refresh Details - - setShowCollectionDialog(true)} - > - - Add to Collection - - setShowMediaDialog(true)} - > - - Media - - setShowSettings(true)} - > - - Settings - - - -
+ {/* Storyline */} + {e.storyline && ( +

+ {e.storyline} +

+ )}
-
- {/* Storyline */} - {e.storyline && ( -
-

Overview

-

- {e.storyline} -

+ {/* Sections */} +
+ {e.credits && e.credits.length > 0 && ( + <> + + + + )} + + + + {e.is_tvseries && seasons && seasons.length > 0 && ( + <> + + + + )} + + {watchHistory.length > 0 && ( + <> + + + deleteEntrySeen.mutate({ id: seenId, entryId: e.id }) + } + /> + + )}
- )} - - - - {/* Cast */} - {e.credits && e.credits.length > 0 && } - - {/* Seasons (TV only) */} - {e.is_tvseries && seasons && seasons.length > 0 && ( - <> - - - - )} - - {/* Watch History */} - {watchHistory.length > 0 && ( - <> - - - deleteEntrySeen.mutate({ id: seenId, entryId: e.id }) - } - /> - - )} +
{/* Dialogs */} {showSettings && ( @@ -330,22 +348,81 @@ export function EntryDetailsPage() { entryId={e.id} /> )} + {showRatingDialog && ( + + )}
); } +/* ---------- Collections section ---------- */ +function EntryCollectionsSection({ entryId }: { entryId: number }) { + const { data: allCollections = [], isLoading } = useCollections(); + + const collections = allCollections.filter((col: Collection) => + col.entries?.some((e: Entry) => e.id === entryId) + ); + + if (isLoading || collections.length === 0) return null; + + return ( + <> + +
+

In Collections

+ +
+ {collections.map((col: Collection) => ( + +
+ {col.name} +
+
+
+

+ {col.name} +

+ {col.entries && ( +

+ {col.entries.length} {col.entries.length === 1 ? 'title' : 'titles'} +

+ )} +
+ + ))} +
+ + +
+ + ); +} + function EntryDetailsSkeleton() { return ( -
-
- -
+
+
+
+ +
- +
- - + +
diff --git a/react_frontend/src/pages/PeoplePage.tsx b/react_frontend/src/pages/PeoplePage.tsx index bb36e97..2f9ff86 100644 --- a/react_frontend/src/pages/PeoplePage.tsx +++ b/react_frontend/src/pages/PeoplePage.tsx @@ -67,7 +67,7 @@ export function PeoplePage() { ref={index === people.length - 1 ? lastRef : undefined} > diff --git a/react_frontend/src/pages/PersonDetailsPage.tsx b/react_frontend/src/pages/PersonDetailsPage.tsx index f403a73..8a86508 100644 --- a/react_frontend/src/pages/PersonDetailsPage.tsx +++ b/react_frontend/src/pages/PersonDetailsPage.tsx @@ -1,18 +1,24 @@ -import { useParams } from 'react-router-dom'; -import { usePerson } from '@/hooks/usePeople'; -import { useQuery } from '@tanstack/react-query'; -import { peopleApi } from '@/api/people'; +import { useParams } from 'react-router-dom'; +import { usePerson, usePersonTmdbFilmography } from '@/hooks/usePeople'; +import { useLibrary } from '@/hooks/useEntries'; +import { useLibraryStore } from '@/stores/useLibraryStore'; import { Skeleton } from '@/components/ui/skeleton'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Separator } from '@/components/ui/separator'; -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; +import { Badge } from '@/components/ui/badge'; import { EntryCard } from '@/components/entries/EntryCard'; import { getProfileUrl, formatDate } from '@/lib/media-utils'; +import { getTmdbImageUrl } from '@/lib/api'; +import type { TmdbFilmographyItem } from '@/api/people'; export function PersonDetailsPage() { const { id } = useParams<{ id: string }>(); const personId = parseInt(id!, 10); const { data: person, isLoading } = usePerson(personId); + const { data: tmdbFilmography, isLoading: tmdbLoading } = usePersonTmdbFilmography(personId); + useLibrary(); + const libraryMap = useLibraryStore((s) => s.entries); + const libraryLoaded = useLibraryStore((s) => s.isLoaded); if (isLoading || !person) { return ( @@ -31,47 +37,21 @@ export function PersonDetailsPage() { return (
- {/* Profile header */}
- + - {person.name - .split(' ') - .map((n: string) => n[0]) - .join('')} + {person.name.split(' ').map((n: string) => n[0]).join('')} -

{person.name}

- {person.known_for_department && ( - {person.known_for_department} - )} - {person.birthday && ( - <> - • - Born: {formatDate(person.birthday)} - - )} - {person.deathday && ( - <> - • - Died: {formatDate(person.deathday)} - - )} - {person.place_of_birth && ( - <> - • - {person.place_of_birth} - - )} + {person.known_for_department && {person.known_for_department}} + {person.birthday && (<>•Born: {formatDate(person.birthday)})} + {person.deathday && (<>•Died: {formatDate(person.deathday)})} + {person.place_of_birth && (<>•{person.place_of_birth})}
- {person.biography && (

{person.biography} @@ -82,13 +62,118 @@ export function PersonDetailsPage() { - {/* Filmography placeholder */} + +

+ ); +} + +interface FilmographySectionProps { + libraryMap: Map; + libraryLoaded: boolean; + tmdbFilmography?: { cast: TmdbFilmographyItem[]; crew: TmdbFilmographyItem[] }; + tmdbLoading: boolean; +} + +function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLoading }: FilmographySectionProps) { + if (tmdbLoading || !libraryLoaded) { + return (

Filmography

-

- Filmography details will be loaded from credits associated with this person. -

+
+ {Array.from({ length: 10 }).map((_, i) => ( + + ))} +
+ ); + } + + const allTmdbCredits = [ + ...(tmdbFilmography?.cast ?? []), + ...(tmdbFilmography?.crew?.filter((c) => c.job === 'Director' || c.department === 'Directing') ?? []), + ]; + const seenTmdbIds = new Set(); + const dedupedCredits = allTmdbCredits.filter((c) => { + if (seenTmdbIds.has(c.id)) return false; + seenTmdbIds.add(c.id); + return true; + }); + + const tmdbIdToLibraryEntry = new Map(); + for (const entry of libraryMap.values()) { + if (entry.entryIds?.tmdb_id != null) { + tmdbIdToLibraryEntry.set(Number(entry.entryIds.tmdb_id), entry); + } + } + + const libraryCredits = dedupedCredits.filter((c) => tmdbIdToLibraryEntry.has(c.id)); + const otherCredits = dedupedCredits.filter((c) => !tmdbIdToLibraryEntry.has(c.id)); + + if (dedupedCredits.length === 0) { + return ( +
+

Filmography

+

No filmography found.

+
+ ); + } + + return ( +
+

Filmography

+ + {libraryCredits.length > 0 && ( +
+

In Your Library

+
+ {libraryCredits.map((credit) => { + const entry = tmdbIdToLibraryEntry.get(credit.id)!; + return ( +
+ + {credit.character && ( +

{credit.character}

+ )} +
+ ); + })} +
+
+ )} + + {otherCredits.length > 0 && ( +
+

Not in Library

+
+ {otherCredits.map((credit) => { + const title = credit.title ?? credit.name ?? 'Unknown'; + const posterSrc = credit.poster_path + ? getTmdbImageUrl(credit.poster_path, 'w342') + : '/images/default-poster.png'; + return ( +
+
+ {title} +
+

{title}

+ + {credit.media_type === 'tv' ? 'TV' : 'Movie'} + +
+ {credit.character && ( +

{credit.character}

+ )} +
+ ); + })} +
+
+ )}
); } diff --git a/react_frontend/src/pages/PersonTmdbRedirectPage.tsx b/react_frontend/src/pages/PersonTmdbRedirectPage.tsx new file mode 100644 index 0000000..abc8237 --- /dev/null +++ b/react_frontend/src/pages/PersonTmdbRedirectPage.tsx @@ -0,0 +1,44 @@ +import { useEffect } from 'react'; +import { useParams, useNavigate } from 'react-router-dom'; +import { useFetchPersonByTmdbId } from '@/hooks/usePeople'; +import { Skeleton } from '@/components/ui/skeleton'; + +export function PersonTmdbRedirectPage() { + const { tmdbId } = useParams<{ tmdbId: string }>(); + const navigate = useNavigate(); + const fetchPerson = useFetchPersonByTmdbId(); + + useEffect(() => { + if (!tmdbId) return; + fetchPerson.mutate(parseInt(tmdbId, 10), { + onSuccess: (person) => { + navigate(`/people/${person.id}`, { replace: true }); + }, + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [tmdbId]); + + if (fetchPerson.isError) { + return ( +
+

Person not found

+

+ Could not load person data from TMDB. +

+
+ ); + } + + return ( +
+
+ +
+ + + +
+
+
+ ); +} diff --git a/react_frontend/src/router.tsx b/react_frontend/src/router.tsx index 3710220..4b0242b 100644 --- a/react_frontend/src/router.tsx +++ b/react_frontend/src/router.tsx @@ -51,6 +51,11 @@ const PersonDetailsPage = lazy(() => default: m.PersonDetailsPage, })) ); +const PersonTmdbRedirectPage = lazy(() => + import('@/pages/PersonTmdbRedirectPage').then((m) => ({ + default: m.PersonTmdbRedirectPage, + })) +); const SettingsPage = lazy(() => import('@/pages/SettingsPage').then((m) => ({ default: m.SettingsPage })) ); @@ -168,6 +173,14 @@ export const router = createBrowserRouter([ ), }, + { + path: '/people/tmdb/:tmdbId', + element: ( + + + + ), + }, { path: '/people/:id', element: ( diff --git a/react_frontend/src/types/index.ts b/react_frontend/src/types/index.ts index fe25f68..e623b79 100644 --- a/react_frontend/src/types/index.ts +++ b/react_frontend/src/types/index.ts @@ -6,6 +6,7 @@ export interface EntryIds { } export interface EntryRatings { + id?: number; user_rating: number | null; tmdb_rating: number | null; imdb_rating: number | null; @@ -40,6 +41,8 @@ export interface Entry { favorit: boolean; hidden: boolean; note: string | null; + show_in_calendar?: boolean; + auto_sync?: boolean; date_first_seen: string | null; date_last_seen: string | null; createdAt: string; @@ -95,6 +98,8 @@ export interface Episode { updatedAt: string; episodeSeens?: EpisodeSeen[]; guest_stars?: Credit[]; + entry?: Entry; + season?: Season; } export interface EntrySeen { @@ -146,6 +151,7 @@ export interface People { profile_path: string | null; createdAt: string; updatedAt: string; + roles?: Credit[]; } export interface Credit { @@ -158,6 +164,7 @@ export interface Credit { job: string | null; order: number | null; people?: People; + entry?: Entry; } export interface Genre {