diff --git a/react_frontend/src/api/entries.ts b/react_frontend/src/api/entries.ts index ce2a99e..73a5c62 100644 --- a/react_frontend/src/api/entries.ts +++ b/react_frontend/src/api/entries.ts @@ -1,6 +1,6 @@ import { api } from '@/lib/api'; import { normalizeEntry } from '@/lib/normalizers'; -import type { Entry } from '@/types'; +import type { Entry, TmdbPreview } from '@/types'; export const entriesApi = { getAll: () => @@ -44,6 +44,9 @@ export const entriesApi = { syncSeries: () => api.get('/entries/sync-series').then((r) => r.data), + previewTmdb: (tmdbId: number, type: 'movie' | 'tv') => + api.get(`/entries/tmdb/preview/${type}/${tmdbId}`).then((r) => r.data), + uploadMedia: (id: number, formData: FormData) => api .post(`/entries/${id}/media`, formData, { diff --git a/react_frontend/src/api/maintenance.ts b/react_frontend/src/api/maintenance.ts index a269925..05e84c1 100644 --- a/react_frontend/src/api/maintenance.ts +++ b/react_frontend/src/api/maintenance.ts @@ -7,6 +7,10 @@ export interface OrphanResult { stills: number; } +export interface OrphanPeopleResult { + count: number; +} + export const maintenanceApi = { scanOrphanFiles: () => api.get('/maintenance/orphan-files').then((r) => r.data), @@ -19,4 +23,10 @@ export const maintenanceApi = { deleteOrphanMediaRecords: () => api.delete('/maintenance/orphan-media-records').then((r) => r.data), + + scanOrphanPeople: () => + api.get('/maintenance/orphan-people').then((r) => r.data), + + deleteOrphanPeople: () => + api.delete('/maintenance/orphan-people').then((r) => r.data), }; diff --git a/react_frontend/src/api/people.ts b/react_frontend/src/api/people.ts index 5f33bf2..b23f84a 100644 --- a/react_frontend/src/api/people.ts +++ b/react_frontend/src/api/people.ts @@ -33,6 +33,12 @@ export const peopleApi = { 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), + fetchByTmdbId: (tmdb_id: number, pinned = false) => + api.post('/people/fetch', { tmdb_id, pinned }).then((r) => r.data), + + update: (id: number, data: Partial) => + api.put(`/people/${id}`, data).then((r) => r.data), + + search: (query: string) => + api.get('/people/search', { params: { query } }).then((r) => r.data), }; diff --git a/react_frontend/src/api/seasons.ts b/react_frontend/src/api/seasons.ts index 231c1b2..287520e 100644 --- a/react_frontend/src/api/seasons.ts +++ b/react_frontend/src/api/seasons.ts @@ -1,5 +1,5 @@ import { api } from '@/lib/api'; -import type { Season } from '@/types'; +import type { Season, Episode } from '@/types'; export const seasonsApi = { getAll: () => api.get('/seasons').then((r) => r.data), @@ -8,7 +8,7 @@ export const seasonsApi = { api.get(`/seasons/${id}`).then((r) => r.data), getEpisodes: (id: number) => - api.get(`/seasons/${id}/episodes`).then((r) => r.data), + api.get(`/seasons/${id}/episodes`).then((r) => r.data), create: (data: Partial) => api.post('/seasons', data).then((r) => r.data), diff --git a/react_frontend/src/components/entries/EntryCard.tsx b/react_frontend/src/components/entries/EntryCard.tsx index d9c63db..6b1d814 100644 --- a/react_frontend/src/components/entries/EntryCard.tsx +++ b/react_frontend/src/components/entries/EntryCard.tsx @@ -1,32 +1,56 @@ import { useState } from 'react'; -import { Link } from 'react-router-dom'; -import { Plus, Trash2, Star, Loader2, Calendar, Clock } from 'lucide-react'; +import { Link, useNavigate } from 'react-router-dom'; +import { + Plus, Star, Loader2, Heart, EyeOff, Trash2, MoreHorizontal, X, + Eye, History, FolderPlus, RefreshCw, ImageIcon, Settings, +} from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, -} from '@/components/ui/dialog'; + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from '@/components/ui/dropdown-menu'; import { getPosterUrl, getYear, formatRuntime } from '@/lib/media-utils'; -import { useCreateEntry, useDeleteEntry } from '@/hooks/useEntries'; +import { useCreateEntry, useDeleteEntry, useUpdateEntry, useRefreshEntry, useEntrySeasons } from '@/hooks/useEntries'; +import { useEntrySeenByEntry, useDeleteEntrySeen } from '@/hooks/useEntrySeen'; import { useLibraryStore } from '@/stores/useLibraryStore'; import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog'; +import { EntrySeenDialog } from '@/components/dialogs/EntrySeenDialog'; +import { RatingDialog } from '@/components/dialogs/RatingDialog'; +import { MovieWatchHistoryDialog } from '@/components/dialogs/MovieWatchHistoryDialog'; +import { AddEntryToCollectionDialog } from '@/components/dialogs/AddEntryToCollectionDialog'; +import { EntryMediaDialog } from '@/components/dialogs/EntryMediaDialog'; +import { EntrySettingsDialog } from '@/components/dialogs/EntrySettingsDialog'; import type { Entry, TmdbEntry } from '@/types'; interface EntryCardProps { entry?: Entry; tmdbEntry?: TmdbEntry; showTypeBadge?: boolean; + /** When inside a collection, provide the collection ID to show "Remove from collection" action */ + collectionId?: number; + /** Callback to remove entry from collection */ + onRemoveFromCollection?: (entryId: number) => void; } -export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) { +export function EntryCard({ entry, tmdbEntry, showTypeBadge, collectionId, onRemoveFromCollection }: EntryCardProps) { const [showConfirm, setShowConfirm] = useState(false); - const [showDetailDialog, setShowDetailDialog] = useState(false); + const [showRemoveCollectionConfirm, setShowRemoveCollectionConfirm] = useState(false); + const [showSeenDialog, setShowSeenDialog] = useState(false); + const [showRatingDialog, setShowRatingDialog] = useState(false); + const [showWatchHistoryDialog, setShowWatchHistoryDialog] = useState(false); + const [showCollectionDialog, setShowCollectionDialog] = useState(false); + const [showMediaDialog, setShowMediaDialog] = useState(false); + const [showSettingsDialog, setShowSettingsDialog] = useState(false); + const navigate = useNavigate(); const createEntry = useCreateEntry(); const deleteEntry = useDeleteEntry(); + const updateEntry = useUpdateEntry(); + const refreshEntry = useRefreshEntry(); const libraryEntry = useLibraryStore((s) => { if (entry?.isInLibrary) return entry; if (tmdbEntry) { @@ -67,19 +91,18 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) { const entryLink = displayEntry ? `/entry/${displayEntry.id}` - : undefined; + : tmdbEntry + ? `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${tmdbEntry.id}` + : undefined; const handleAdd = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); if (!tmdbEntry) return; - createEntry.mutate({ tmdb_id: tmdbEntry.id, is_tvserie: isTv }); - }; - - const handleRemove = (e: React.MouseEvent) => { - e.preventDefault(); - e.stopPropagation(); - setShowConfirm(true); + createEntry.mutate( + { tmdb_id: tmdbEntry.id, is_tvserie: isTv }, + { onSuccess: (newEntry) => navigate(`/entry/${newEntry.id}`) } + ); }; const confirmRemove = () => { @@ -90,10 +113,22 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) { } }; + const toggleFavorite = () => { + if (libraryEntry) { + updateEntry.mutate({ id: libraryEntry.id, data: { favorit: !libraryEntry.favorit } }); + } + }; + + const toggleHidden = () => { + if (libraryEntry) { + updateEntry.mutate({ id: libraryEntry.id, data: { hidden: !libraryEntry.hidden } }); + } + }; + const card = (
{/* Poster */} -
+
{title} )} - {/* Favorite indicator */} + {/* Favorite indicator – hidden on hover when actions button shows */} {libraryEntry?.favorit && ( - + + )} + + {/* Quick actions button – top right, shown on hover */} + {isInLibrary && ( +
+ + + + + e.stopPropagation()}> + {/* Watch & Rate */} + { e.stopPropagation(); setShowSeenDialog(true); }}> + + Mark as watched + + { e.stopPropagation(); setShowRatingDialog(true); }}> + + Rate this + + {!isTv && ( + { e.stopPropagation(); setShowWatchHistoryDialog(true); }}> + + Watch History + + )} + + {/* Organize */} + { e.stopPropagation(); toggleFavorite(); }}> + + {libraryEntry?.favorit ? 'Unfavorite' : 'Favorite'} + + { e.stopPropagation(); setShowCollectionDialog(true); }}> + + Add to collection + + { e.stopPropagation(); toggleHidden(); }}> + + {libraryEntry?.hidden ? 'Unhide' : 'Hide'} + + + {/* Manage */} + { e.stopPropagation(); refreshEntry.mutate(libraryEntry!.id); }} + disabled={refreshEntry.isPending} + > + + {refreshEntry.isPending ? 'Refreshing...' : 'Refresh details'} + + { e.stopPropagation(); setShowMediaDialog(true); }}> + + Manage media + + { e.stopPropagation(); setShowSettingsDialog(true); }}> + + Settings + + {/* Collection removal */} + {collectionId && onRemoveFromCollection && ( + <> + + { e.stopPropagation(); setShowRemoveCollectionConfirm(true); }} + className="text-destructive focus:text-destructive" + > + + Remove from collection + + + )} + + {/* Danger */} + { e.stopPropagation(); setShowConfirm(true); }} + className="text-destructive focus:text-destructive" + > + + Delete entry + + + +
)} {/* Entry type pill */} @@ -124,7 +247,7 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) { )} {/* Hover overlay */} -
+

{title} @@ -140,24 +263,9 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) { {runtime && {runtime}}

- {/* Actions */} -
- {isInLibrary ? ( - - ) : tmdbEntry ? ( + {/* Add to Library – only for non-library entries */} + {!isInLibrary && tmdbEntry && ( +
+
+ )} +
+
+
+
+ );
@@ -184,87 +297,119 @@ export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) { {entryLink ? ( {card} ) : ( -
setShowDetailDialog(true)}> - {card} -
+ card )} - {/* Details dialog for non-library entries */} - {!entryLink && tmdbEntry && ( - - - - {title} - -
- {title} -
-
- {year && ( - - - {year} - - )} - {isTv ? ( - TV Series - ) : ( - Movie - )} -
- {tmdbEntry.vote_average > 0 && ( -
- - {tmdbEntry.vote_average.toFixed(1)}/10 -
- )} - {tmdbEntry.overview && ( -

- {tmdbEntry.overview} -

- )} - -
-
-
-
+ {collectionId && onRemoveFromCollection && ( + { + if (libraryEntry) onRemoveFromCollection(libraryEntry.id); + setShowRemoveCollectionConfirm(false); + }} + variant="destructive" + /> + )} + {libraryEntry && showSeenDialog && ( + + )} + {libraryEntry && showRatingDialog && ( + + )} + {libraryEntry && showWatchHistoryDialog && ( + + )} + {libraryEntry && showCollectionDialog && ( + + )} + {libraryEntry && showMediaDialog && ( + + )} + {libraryEntry && showSettingsDialog && ( + )} ); } +/* Lazy wrappers – only mount when dialog is open so hooks fetch on demand */ + +function LazyEntrySeenDialog({ entry, open, onOpenChange }: { + entry: Entry; + open: boolean; + onOpenChange: (open: boolean) => void; +}) { + const { data: seasons = [] } = useEntrySeasons(entry.id); + return ( + + ); +} + +function LazyMovieWatchHistoryDialog({ entryId, open, onOpenChange }: { + entryId: number; + open: boolean; + onOpenChange: (open: boolean) => void; +}) { + const { data: watchHistory = [] } = useEntrySeenByEntry(entryId); + const deleteEntrySeen = useDeleteEntrySeen(); + return ( + deleteEntrySeen.mutate({ id: seenId, entryId })} + /> + ); +} + export function EntryCardSkeleton() { return (
- +
); } diff --git a/react_frontend/src/components/entries/EntryLibraryGrid.tsx b/react_frontend/src/components/entries/EntryLibraryGrid.tsx index dee1ff1..9ea3655 100644 --- a/react_frontend/src/components/entries/EntryLibraryGrid.tsx +++ b/react_frontend/src/components/entries/EntryLibraryGrid.tsx @@ -7,6 +7,8 @@ interface EntryLibraryGridProps { isLoading?: boolean; hasMore?: boolean; onLoadMore?: () => void; + collectionId?: number; + onRemoveFromCollection?: (entryId: number) => void; } export function EntryLibraryGrid({ @@ -14,6 +16,8 @@ export function EntryLibraryGrid({ isLoading, hasMore, onLoadMore, + collectionId, + onRemoveFromCollection, }: EntryLibraryGridProps) { const observerRef = useRef(null); @@ -62,7 +66,7 @@ export function EntryLibraryGrid({ className="animate-card-enter" style={{ animationDelay: `${Math.min(index * 30, 300)}ms` }} > - + ))} {isLoading && diff --git a/react_frontend/src/hooks/useCollections.ts b/react_frontend/src/hooks/useCollections.ts index 51cb177..cb22eeb 100644 --- a/react_frontend/src/hooks/useCollections.ts +++ b/react_frontend/src/hooks/useCollections.ts @@ -69,3 +69,20 @@ export function useGetCollectionParts() { }, }); } + +export function useRemoveEntryFromCollection() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ collectionId, entryId }: { collectionId: number; entryId: number }) => + collectionsApi.removeEntry(collectionId, entryId), + onSuccess: (_data, { collectionId }) => { + queryClient.invalidateQueries({ queryKey: collectionKeys.detail(collectionId) }); + queryClient.invalidateQueries({ queryKey: collectionKeys.all }); + toast.success('Entry removed from collection'); + }, + onError: () => { + toast.error('Failed to remove entry from collection'); + }, + }); +} diff --git a/react_frontend/src/hooks/useEntries.ts b/react_frontend/src/hooks/useEntries.ts index eee94b5..f4113d4 100644 --- a/react_frontend/src/hooks/useEntries.ts +++ b/react_frontend/src/hooks/useEntries.ts @@ -8,6 +8,7 @@ export const entryKeys = { all: ['entries'] as const, detail: (id: number) => ['entries', id] as const, seasons: (id: number) => ['entries', id, 'seasons'] as const, + tmdbPreview: (tmdbId: number, type: string) => ['entries', 'tmdb-preview', type, tmdbId] as const, }; export function useLibrary() { @@ -153,3 +154,12 @@ export function useUploadMedia() { }, }); } + +export function useTmdbPreview(tmdbId: number, type: 'movie' | 'tv') { + return useQuery({ + queryKey: entryKeys.tmdbPreview(tmdbId, type), + queryFn: () => entriesApi.previewTmdb(tmdbId, type), + enabled: !!tmdbId, + staleTime: 10 * 60 * 1000, + }); +} diff --git a/react_frontend/src/hooks/usePeople.ts b/react_frontend/src/hooks/usePeople.ts index 69d6e0f..b74c499 100644 --- a/react_frontend/src/hooks/usePeople.ts +++ b/react_frontend/src/hooks/usePeople.ts @@ -1,4 +1,5 @@ -import { useQuery, useMutation } from '@tanstack/react-query'; +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; +import { toast } from 'sonner'; import { peopleApi } from '@/api/people'; export const peopleKeys = { @@ -38,3 +39,27 @@ export function useFetchPersonByTmdbId() { mutationFn: (tmdb_id: number) => peopleApi.fetchByTmdbId(tmdb_id), }); } + +export function useUpdatePerson() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ id, data }: { id: number; data: Partial }) => + peopleApi.update(id, data), + onSuccess: (updatedPerson) => { + queryClient.invalidateQueries({ queryKey: peopleKeys.detail(updatedPerson.id) }); + toast.success('Person updated'); + }, + onError: () => { + toast.error('Failed to update person'); + }, + }); +} + +export function useSearchLocalPeople(query: string) { + return useQuery({ + queryKey: ['people', 'search', query], + queryFn: () => query === '*' ? peopleApi.getAll() : peopleApi.search(query), + enabled: query.length > 0, + }); +} diff --git a/react_frontend/src/pages/CollectionDetailsPage.tsx b/react_frontend/src/pages/CollectionDetailsPage.tsx index 2819088..62aedb3 100644 --- a/react_frontend/src/pages/CollectionDetailsPage.tsx +++ b/react_frontend/src/pages/CollectionDetailsPage.tsx @@ -1,6 +1,6 @@ -import { useState } from 'react'; +import { useState, useMemo } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; -import { useCollection, useDeleteCollection, useGetCollectionParts } from '@/hooks/useCollections'; +import { useCollection, useDeleteCollection, useGetCollectionParts, useRemoveEntryFromCollection } from '@/hooks/useCollections'; import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid'; import { getCollectionPosterUrl } from '@/lib/media-utils'; import { getTmdbImageUrl } from '@/lib/api'; @@ -12,10 +12,14 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; -import { Star, MoreVertical, Pencil, Download, Trash2 } from 'lucide-react'; +import { Star, MoreVertical, Pencil, Download, Trash2, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react'; import { CollectionEditDialog } from '@/components/dialogs/CollectionEditDialog'; import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog'; import { toast } from 'sonner'; +import type { Entry } from '@/types'; + +type CollectionSortField = 'order' | 'year' | 'title' | 'rating'; +type SortDir = 'asc' | 'desc'; export function CollectionDetailsPage() { const { id } = useParams<{ id: string }>(); @@ -23,8 +27,11 @@ export function CollectionDetailsPage() { const { data: collection, isLoading, isError } = useCollection(Number(id)); const [showEditDialog, setShowEditDialog] = useState(false); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); + const [sortField, setSortField] = useState('order'); + const [sortDir, setSortDir] = useState('asc'); const deleteCollection = useDeleteCollection(); const getCollectionParts = useGetCollectionParts(); + const removeEntryFromCollection = useRemoveEntryFromCollection(); if (isLoading) { return ( @@ -33,7 +40,7 @@ export function CollectionDetailsPage() {
{Array.from({ length: 6 }).map((_, i) => ( - + ))}
@@ -55,6 +62,46 @@ export function CollectionDetailsPage() { isInLibrary: true, })); + const sortedEntries = useMemo(() => { + const sorted = [...entries].sort((a, b) => { + let cmp = 0; + switch (sortField) { + case 'order': { + const oa = (a as Entry & { UserCollectionEntry?: { order: number } }).UserCollectionEntry?.order ?? 0; + const ob = (b as Entry & { UserCollectionEntry?: { order: number } }).UserCollectionEntry?.order ?? 0; + cmp = oa - ob; + break; + } + case 'year': { + const ya = a.release_date ? new Date(a.release_date).getFullYear() : 0; + const yb = b.release_date ? new Date(b.release_date).getFullYear() : 0; + cmp = ya - yb; + break; + } + case 'title': + cmp = (a.title || '').localeCompare(b.title || ''); + break; + case 'rating': { + const ra = a.entryRatings?.user_rating || a.entryRatings?.tmdb_rating || 0; + const rb = b.entryRatings?.user_rating || b.entryRatings?.tmdb_rating || 0; + cmp = ra - rb; + break; + } + } + return sortDir === 'asc' ? cmp : -cmp; + }); + return sorted; + }, [entries, sortField, sortDir]); + + const handleSort = (field: CollectionSortField) => { + if (field === sortField) { + setSortDir((d) => (d === 'asc' ? 'desc' : 'asc')); + } else { + setSortField(field); + setSortDir(field === 'rating' ? 'desc' : 'asc'); + } + }; + const handleDelete = () => { deleteCollection.mutate(collection.id, { onSuccess: () => navigate('/collections', { replace: true }), @@ -78,7 +125,7 @@ export function CollectionDetailsPage() { ) : (
)} -
+
{/* Quick action menu - top right */}
@@ -142,8 +189,38 @@ export function CollectionDetailsPage() {
+ {/* Sort toolbar */} + {entries.length > 1 && ( +
+ + {(['order', 'year', 'title', 'rating'] as const).map((field) => ( + + ))} +
+ )} + {/* Entries grid */} - + + removeEntryFromCollection.mutate({ collectionId: collection.id, entryId }) + } + /> {/* Edit dialog */} {showEditDialog && ( diff --git a/react_frontend/src/pages/LibraryPage.tsx b/react_frontend/src/pages/LibraryPage.tsx index 3dd0473..12703ff 100644 --- a/react_frontend/src/pages/LibraryPage.tsx +++ b/react_frontend/src/pages/LibraryPage.tsx @@ -2,6 +2,8 @@ import { useState, useMemo, useCallback, useEffect, useRef } from 'react'; import { useSearchParams } from 'react-router-dom'; import { useLibrary } from '@/hooks/useEntries'; import { useLibraryEntries } from '@/stores/useLibraryStore'; +import { useLibraryFiltersStore, defaultFilters } from '@/stores/useLibraryFiltersStore'; +import type { FilterTab, SortField, SortDir, Filters } from '@/stores/useLibraryFiltersStore'; import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Input } from '@/components/ui/input'; @@ -12,22 +14,6 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ import { Search, X, SlidersHorizontal, ArrowUpDown } from 'lucide-react'; import type { Entry } from '@/types'; -type FilterTab = 'all' | 'movies' | 'tv' | 'favorites' | 'hidden'; -type SortField = 'date_last_seen' | 'createdAt' | 'title' | 'release_date' | 'rating'; -type SortDir = 'asc' | 'desc'; - -interface Filters { - genre: string; - tmdbRatingMin: string; - tmdbRatingMax: string; - userRatingMin: string; - userRatingMax: string; - yearMin: string; - yearMax: string; -} - -const defaultFilters: Filters = { genre: '', tmdbRatingMin: '', tmdbRatingMax: '', userRatingMin: '', userRatingMax: '', yearMin: '', yearMax: '' }; - const sortLabels: Record = { date_last_seen: 'Last Watched', createdAt: 'Date Added', @@ -66,13 +52,22 @@ const PAGE_SIZE = 28; export function LibraryPage() { const { isLoading } = useLibrary(); const [searchParams, setSearchParams] = useSearchParams(); - const [activeTab, setActiveTab] = useState('all'); - const [search, setSearch] = useState(''); - const [debouncedSearch, setDebouncedSearch] = useState(''); - const [sortField, setSortField] = useState('date_last_seen'); - const [sortDir, setSortDir] = useState('desc'); - const [filters, setFilters] = useState(defaultFilters); - const [debouncedFilters, setDebouncedFilters] = useState(defaultFilters); + + // Persistent filter state from store + const activeTab = useLibraryFiltersStore((s) => s.activeTab); + const setActiveTab = useLibraryFiltersStore((s) => s.setActiveTab); + const search = useLibraryFiltersStore((s) => s.search); + const setSearch = useLibraryFiltersStore((s) => s.setSearch); + const sortField = useLibraryFiltersStore((s) => s.sortField); + const setSortField = useLibraryFiltersStore((s) => s.setSortField); + const sortDir = useLibraryFiltersStore((s) => s.sortDir); + const setSortDir = useLibraryFiltersStore((s) => s.setSortDir); + const filters = useLibraryFiltersStore((s) => s.filters); + const setFilters = useLibraryFiltersStore((s) => s.setFilters); + const clearFilters = useLibraryFiltersStore((s) => s.clearFilters); + + const [debouncedSearch, setDebouncedSearch] = useState(search); + const [debouncedFilters, setDebouncedFilters] = useState(filters); const [visibleCount, setVisibleCount] = useState(PAGE_SIZE); const filtersInitialized = useRef(false); @@ -92,7 +87,7 @@ export function LibraryPage() { // Clear URL params after applying setSearchParams({}, { replace: true }); } - }, [searchParams, setSearchParams]); + }, [searchParams, setSearchParams, setFilters]); // Debounce search useEffect(() => { @@ -181,8 +176,6 @@ export function LibraryPage() { const hasMore = visibleCount < filteredEntries.length; const loadMore = useCallback(() => setVisibleCount((c) => c + PAGE_SIZE), []); - const clearFilters = useCallback(() => setFilters(defaultFilters), []); - return (
diff --git a/react_frontend/src/pages/PeoplePage.tsx b/react_frontend/src/pages/PeoplePage.tsx index 3b14169..fe32ab1 100644 --- a/react_frontend/src/pages/PeoplePage.tsx +++ b/react_frontend/src/pages/PeoplePage.tsx @@ -1,26 +1,64 @@ -import { useState, useCallback, useRef, useEffect } from 'react'; +import { useState, useCallback, useRef, useEffect, useMemo } from 'react'; import { Link } from 'react-router-dom'; import { usePopularPeople, useTmdbSearchPeople } from '@/hooks/useTmdb'; +import { useSearchLocalPeople } from '@/hooks/usePeople'; import { Input } from '@/components/ui/input'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Skeleton } from '@/components/ui/skeleton'; -import { Search } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Switch } from '@/components/ui/switch'; +import { Label } from '@/components/ui/label'; +import { Search, Heart } from 'lucide-react'; import { getProfileUrl } from '@/lib/media-utils'; +type PeopleFilter = 'all' | 'favorite'; + export function PeoplePage() { const [search, setSearch] = useState(''); - const isSearching = search.length > 0; + const [debouncedSearch, setDebouncedSearch] = useState(''); + const [filter, setFilter] = useState('all'); + const [localOnly, setLocalOnly] = useState(false); + + // Debounce search input + useEffect(() => { + const timer = setTimeout(() => setDebouncedSearch(search), 400); + return () => clearTimeout(timer); + }, [search]); + + const isSearching = debouncedSearch.length > 0; const popularQuery = usePopularPeople(); - const searchQuery = useTmdbSearchPeople(search); + const tmdbSearchQuery = useTmdbSearchPeople(localOnly ? '' : debouncedSearch); + const { data: localSearchResults = [], isLoading: localSearchLoading } = useSearchLocalPeople( + localOnly ? debouncedSearch : '' + ); - const activeQuery = isSearching ? searchQuery : popularQuery; - const people = activeQuery.data?.pages.flatMap((p) => p.results) ?? []; + // For TMDB mode, use infinite scroll queries + const activeQuery = isSearching && !localOnly ? tmdbSearchQuery : !localOnly ? popularQuery : null; + const tmdbPeople = activeQuery?.data?.pages.flatMap((p) => p.results) ?? []; + + // For local mode with no search, fetch all local people + const { data: allLocalPeople = [], isLoading: allLocalLoading } = useSearchLocalPeople( + localOnly && !isSearching ? '*' : '' + ); + + // Determine displayed people + const displayPeople = useMemo(() => { + if (localOnly) { + const people = isSearching ? localSearchResults : allLocalPeople; + if (filter === 'favorite') { + return people.filter((p: any) => p.favorite); + } + return people; + } + // TMDB mode - filter not applicable for TMDB results + return tmdbPeople; + }, [localOnly, isSearching, localSearchResults, allLocalPeople, tmdbPeople, filter]); const observerRef = useRef(null); const lastRef = useCallback( (node: HTMLDivElement | null) => { - if (activeQuery.isFetchingNextPage) return; + if (!activeQuery || activeQuery.isFetchingNextPage) return; if (observerRef.current) observerRef.current.disconnect(); observerRef.current = new IntersectionObserver((entries) => { if (entries[0].isIntersecting && activeQuery.hasNextPage) { @@ -29,28 +67,70 @@ export function PeoplePage() { }); if (node) observerRef.current.observe(node); }, - [activeQuery.isFetchingNextPage, activeQuery.hasNextPage, activeQuery.fetchNextPage] + [activeQuery?.isFetchingNextPage, activeQuery?.hasNextPage, activeQuery?.fetchNextPage] ); useEffect(() => { return () => observerRef.current?.disconnect(); }, []); + const isLoading = localOnly + ? (isSearching ? localSearchLoading : allLocalLoading) + : activeQuery?.isLoading; + return (

People

-
- - setSearch(e.target.value)} - className="pl-10" - /> + {/* Controls row */} +
+
+ + setSearch(e.target.value)} + className="pl-10" + /> +
+ + {/* Filter: All / Favorite (only in local mode) */} + {localOnly && ( +
+ + +
+ )} + + {/* Local DB toggle */} +
+ + +
- {activeQuery.isLoading ? ( + {isLoading ? (
{Array.from({ length: 24 }).map((_, i) => (
@@ -59,31 +139,40 @@ export function PeoplePage() {
))}
+ ) : displayPeople.length === 0 ? ( +
+ No people found. +
) : (
- {people.map((person, index) => ( + {displayPeople.map((person: any, index: number) => (
- - - - {person.name - .split(' ') - .map((n) => n[0]) - .join('')} - - +
+ + + + {person.name + .split(' ') + .map((n: string) => n[0]) + .join('')} + + + {person.favorite && ( + + )} +

{person.name}

diff --git a/react_frontend/src/pages/PersonDetailsPage.tsx b/react_frontend/src/pages/PersonDetailsPage.tsx index 8e0d998..cf6306e 100644 --- a/react_frontend/src/pages/PersonDetailsPage.tsx +++ b/react_frontend/src/pages/PersonDetailsPage.tsx @@ -1,6 +1,6 @@ -import { useParams } from 'react-router-dom'; +import { useParams, useNavigate } from 'react-router-dom'; import { useState } from 'react'; -import { usePerson, usePersonTmdbFilmography } from '@/hooks/usePeople'; +import { usePerson, usePersonTmdbFilmography, useUpdatePerson } from '@/hooks/usePeople'; import { useLibrary } from '@/hooks/useEntries'; import { useLibraryStore } from '@/stores/useLibraryStore'; import { Skeleton } from '@/components/ui/skeleton'; @@ -9,19 +9,35 @@ import { Separator } from '@/components/ui/separator'; import { Button } from '@/components/ui/button'; import { EntryCard } from '@/components/entries/EntryCard'; import { getProfileUrl, formatDate } from '@/lib/media-utils'; -import { ChevronLeft, ChevronRight } from 'lucide-react'; +import { ChevronLeft, ChevronRight, Heart } from 'lucide-react'; import type { TmdbEntry } from '@/types'; 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 navigate = useNavigate(); + const { data: person, isLoading, isError } = usePerson(personId); const { data: tmdbFilmography, isLoading: tmdbLoading } = usePersonTmdbFilmography(personId); + const updatePerson = useUpdatePerson(); useLibrary(); const libraryMap = useLibraryStore((s) => s.entries); const libraryLoaded = useLibraryStore((s) => s.isLoaded); + if (isError) { + return ( +
+

Person not found

+

+ This person could not be loaded. They may not exist in the database. +

+ +
+ ); + } + if (isLoading || !person) { return (
@@ -47,7 +63,18 @@ export function PersonDetailsPage() {
-

{person.name}

+
+

{person.name}

+ +
{person.known_for_department && {person.known_for_department}} {person.birthday && (<>•Born: {formatDate(person.birthday)})} diff --git a/react_frontend/src/pages/SeasonPage.tsx b/react_frontend/src/pages/SeasonPage.tsx index 4f62b86..30d8d3f 100644 --- a/react_frontend/src/pages/SeasonPage.tsx +++ b/react_frontend/src/pages/SeasonPage.tsx @@ -9,8 +9,9 @@ import { Skeleton } from '@/components/ui/skeleton'; import { Progress } from '@/components/ui/progress'; import { Button } from '@/components/ui/button'; import { Eye, CheckCircle2, ListChecks } from 'lucide-react'; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; import { getTmdbPosterUrl, getYear, formatDate } from '@/lib/media-utils'; -import type { Episode } from '@/types'; +import type { Episode, EpisodeSeen } from '@/types'; export function SeasonPage() { const { entryId, seasonId } = useParams<{ @@ -39,7 +40,7 @@ export function SeasonPage() { } const watchedCount = episodes.filter( - (ep) => + (ep: Episode) => ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0) ).length; @@ -61,20 +62,20 @@ export function SeasonPage() {
{/* Header */} -
+
{season.name}
-
-

{season.name}

+
+

{season.name}

{/* Mark Season as Watched — top right */} diff --git a/react_frontend/src/pages/TmdbPreviewPage.tsx b/react_frontend/src/pages/TmdbPreviewPage.tsx new file mode 100644 index 0000000..8eb9a04 --- /dev/null +++ b/react_frontend/src/pages/TmdbPreviewPage.tsx @@ -0,0 +1,213 @@ +import { useParams, useNavigate } from 'react-router-dom'; +import { useTmdbPreview, useCreateEntry } from '@/hooks/useEntries'; +import { useLibraryStore } from '@/stores/useLibraryStore'; +import { Badge } from '@/components/ui/badge'; +import { Button } from '@/components/ui/button'; +import { Separator } from '@/components/ui/separator'; +import { Star, Plus, Loader2, ExternalLink, Tv, Film } from 'lucide-react'; +import { EntryDetailsSkeleton } from '@/components/skeletons/PageSkeletons'; +import { getYear, formatRuntime } from '@/lib/media-utils'; + +const TMDB_IMG = 'https://image.tmdb.org/t/p'; + +export function TmdbPreviewPage() { + const { type, tmdbId } = useParams<{ type: string; tmdbId: string }>(); + const navigate = useNavigate(); + const tmdbIdNum = parseInt(tmdbId!, 10); + const mediaType = type as 'movie' | 'tv'; + + const { data: preview, isLoading, isError } = useTmdbPreview(tmdbIdNum, mediaType); + const createEntry = useCreateEntry(); + + // Check if already in library + const libraryEntry = useLibraryStore((s) => { + for (const e of s.entries.values()) { + if (e.entryIds?.tmdb_id === tmdbIdNum) return e; + } + return null; + }); + + if (isLoading || !preview) { + return ; + } + + if (isError) { + return ( +
+

Could not load entry from TMDB.

+ +
+ ); + } + + const backdrop = preview.backdrop_path ? `${TMDB_IMG}/w1280${preview.backdrop_path}` : null; + const poster = preview.poster_path + ? `${TMDB_IMG}/w500${preview.poster_path}` + : '/images/default-poster.png'; + + const handleAddToLibrary = () => { + createEntry.mutate( + { tmdb_id: preview.tmdb_id, is_tvserie: preview.is_tvseries }, + { onSuccess: (newEntry) => navigate(`/entry/${newEntry.id}`, { replace: true }) } + ); + }; + + return ( +
+ {/* Backdrop banner */} +
+ {backdrop ? ( + + ) : ( +
+ )} +
+
+ + {/* Main content */} +
+ {/* Add to Library button — top right */} +
+ {libraryEntry ? ( + + ) : ( + + )} +
+ + {/* Two-column header: poster | info */} +
+ {/* LEFT: Poster */} +
+ {preview.title} + {/* External links */} +
+ {preview.tmdb_id && ( + + + TMDB + + )} + {preview.imdb_id && ( + + + IMDb + + )} +
+
+ + {/* RIGHT: Info */} +
+ {/* Title */} +
+

{preview.title}

+ {preview.tagline && ( +

{preview.tagline}

+ )} +
+ + {/* Meta */} +
+ + {preview.is_tvseries ? : } + {preview.is_tvseries ? 'TV Series' : 'Movie'} + + {preview.release_date && ( + <> + • + {getYear(preview.release_date)} + + )} + {preview.is_tvseries && preview.status && ( + <> + • + {preview.status} + + )} + {preview.runtime && !preview.is_tvseries && ( + <> + • + {formatRuntime(preview.runtime)} + + )} +
+ + {/* TV series season count */} + {preview.is_tvseries && preview.number_of_seasons != null && ( +
+ + {preview.number_of_seasons} {preview.number_of_seasons === 1 ? 'Season' : 'Seasons'} + + {preview.number_of_episodes != null && ( + + ({preview.number_of_episodes} episodes) + + )} +
+ )} + + {/* Genres */} + {preview.genres.length > 0 && ( +
+ {preview.genres.map((g) => ( + + {g.name} + + ))} +
+ )} + + {/* Rating */} + {preview.vote_average != null && preview.vote_average > 0 && ( +
+ + + TMDB: + {preview.vote_average.toFixed(1)}/10 + +
+ )} + + {/* Storyline */} + {preview.storyline && ( + <> + +

+ {preview.storyline} +

+ + )} +
+
+
+
+ ); +} diff --git a/react_frontend/src/router.tsx b/react_frontend/src/router.tsx index 356f8f9..20c1ee9 100644 --- a/react_frontend/src/router.tsx +++ b/react_frontend/src/router.tsx @@ -52,6 +52,11 @@ const EntryDetailsPage = lazy(() => default: m.EntryDetailsPage, })) ); +const TmdbPreviewPage = lazy(() => + import('@/pages/TmdbPreviewPage').then((m) => ({ + default: m.TmdbPreviewPage, + })) +); const SeasonPage = lazy(() => import('@/pages/SeasonPage').then((m) => ({ default: m.SeasonPage })) ); @@ -169,6 +174,14 @@ export const router = createBrowserRouter([ ), }, + { + path: '/entry/tmdb/:type/:tmdbId', + element: ( + }> + + + ), + }, { path: '/entry/:id', element: ( diff --git a/react_frontend/src/stores/useLibraryFiltersStore.ts b/react_frontend/src/stores/useLibraryFiltersStore.ts new file mode 100644 index 0000000..31bca21 --- /dev/null +++ b/react_frontend/src/stores/useLibraryFiltersStore.ts @@ -0,0 +1,61 @@ +import { create } from 'zustand'; + +type FilterTab = 'all' | 'movies' | 'tv' | 'favorites' | 'hidden'; +type SortField = 'date_last_seen' | 'createdAt' | 'title' | 'release_date' | 'rating'; +type SortDir = 'asc' | 'desc'; + +interface Filters { + genre: string; + tmdbRatingMin: string; + tmdbRatingMax: string; + userRatingMin: string; + userRatingMax: string; + yearMin: string; + yearMax: string; +} + +interface LibraryFiltersState { + activeTab: FilterTab; + search: string; + sortField: SortField; + sortDir: SortDir; + filters: Filters; + + setActiveTab: (tab: FilterTab) => void; + setSearch: (search: string) => void; + setSortField: (field: SortField) => void; + setSortDir: (dir: SortDir) => void; + setFilters: (updater: Filters | ((prev: Filters) => Filters)) => void; + clearFilters: () => void; +} + +const defaultFilters: Filters = { + genre: '', + tmdbRatingMin: '', + tmdbRatingMax: '', + userRatingMin: '', + userRatingMax: '', + yearMin: '', + yearMax: '', +}; + +export const useLibraryFiltersStore = create((set) => ({ + activeTab: 'all', + search: '', + sortField: 'date_last_seen', + sortDir: 'desc', + filters: defaultFilters, + + setActiveTab: (tab) => set({ activeTab: tab }), + setSearch: (search) => set({ search }), + setSortField: (field) => set({ sortField: field }), + setSortDir: (dir) => set({ sortDir: dir }), + setFilters: (updater) => + set((state) => ({ + filters: typeof updater === 'function' ? updater(state.filters) : updater, + })), + clearFilters: () => set({ filters: defaultFilters }), +})); + +export { defaultFilters }; +export type { FilterTab, SortField, SortDir, Filters }; diff --git a/react_frontend/src/types/index.ts b/react_frontend/src/types/index.ts index 710cb53..c242ce0 100644 --- a/react_frontend/src/types/index.ts +++ b/react_frontend/src/types/index.ts @@ -152,6 +152,8 @@ export interface People { place_of_birth: string | null; known_for_department: string | null; fully_fetched: boolean; + favorite: boolean; + pinned: boolean; profile_path: string | null; createdAt: string; updatedAt: string; @@ -241,3 +243,25 @@ export interface TmdbPaginatedResponse { total_pages: number; total_results: number; } + +export interface TmdbPreview { + tmdb_id: number; + title: string; + original_title: string | null; + release_date: string | null; + runtime: number | null; + storyline: string | null; + country: string | null; + is_tvseries: boolean; + status: string | null; + poster_path: string | null; + backdrop_path: string | null; + vote_average: number | null; + genres: { id: number; name: string }[]; + tagline: string | null; + number_of_seasons: number | null; + number_of_episodes: number | null; + networks: { id: number; name: string; logo_path: string | null }[]; + homepage: string | null; + imdb_id: string | null; +}