feat(frontend): navigate non-library entries to TMDB preview page
- Add TmdbPreviewPage showing TMDB details without adding to library - Display backdrop, poster, title, tagline, genres, rating, storyline - Show season/episode count for TV series - Add "Add to Library" button that creates entry then redirects to details page - Show "Already in Library — View" if entry exists in DB - Add /entry/tmdb/:type/:tmdbId route in router.tsx - Add TmdbPreview type, entriesApi.previewTmdb(), and useTmdbPreview() hook - Update EntryCard to navigate to preview page instead of auto-adding Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
1 parent
25b645a16f
commit
02cdcf733d
18 files changed
+949
-204
No files matched your search
@@ -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<CollectionSortField>('order');
|
||||
const [sortDir, setSortDir] = useState<SortDir>('asc');
|
||||
const deleteCollection = useDeleteCollection();
|
||||
const getCollectionParts = useGetCollectionParts();
|
||||
const removeEntryFromCollection = useRemoveEntryFromCollection();
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -33,7 +40,7 @@ export function CollectionDetailsPage() {
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="aspect-[2/3] w-full rounded-lg" />
|
||||
<Skeleton key={i} className="aspect-2/3 w-full rounded-lg" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
@@ -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() {
|
||||
) : (
|
||||
<div className="h-48 w-full bg-muted sm:h-64" />
|
||||
)}
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-background via-background/60 to-transparent" />
|
||||
<div className="absolute inset-0 bg-linear-to-t from-background via-background/60 to-transparent" />
|
||||
|
||||
{/* Quick action menu - top right */}
|
||||
<div className="absolute top-3 right-3">
|
||||
@@ -142,8 +189,38 @@ export function CollectionDetailsPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sort toolbar */}
|
||||
{entries.length > 1 && (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<ArrowUpDown className="h-4 w-4 text-muted-foreground shrink-0" />
|
||||
{(['order', 'year', 'title', 'rating'] as const).map((field) => (
|
||||
<Button
|
||||
key={field}
|
||||
variant={sortField === field ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
className="h-7 text-xs capitalize gap-1"
|
||||
onClick={() => handleSort(field)}
|
||||
>
|
||||
{field}
|
||||
{sortField === field && (
|
||||
sortDir === 'asc'
|
||||
? <ArrowUp className="h-3 w-3" />
|
||||
: <ArrowDown className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Entries grid */}
|
||||
<EntryLibraryGrid entries={entries} isLoading={false} />
|
||||
<EntryLibraryGrid
|
||||
entries={sortedEntries}
|
||||
isLoading={false}
|
||||
collectionId={collection.id}
|
||||
onRemoveFromCollection={(entryId) =>
|
||||
removeEntryFromCollection.mutate({ collectionId: collection.id, entryId })
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Edit dialog */}
|
||||
{showEditDialog && (
|
||||
|
||||
@@ -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<SortField, string> = {
|
||||
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<FilterTab>('all');
|
||||
const [search, setSearch] = useState('');
|
||||
const [debouncedSearch, setDebouncedSearch] = useState('');
|
||||
const [sortField, setSortField] = useState<SortField>('date_last_seen');
|
||||
const [sortDir, setSortDir] = useState<SortDir>('desc');
|
||||
const [filters, setFilters] = useState<Filters>(defaultFilters);
|
||||
const [debouncedFilters, setDebouncedFilters] = useState<Filters>(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>(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 (
|
||||
<div className="space-y-6 animate-page-enter">
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
@@ -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<PeopleFilter>('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<IntersectionObserver | null>(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 (
|
||||
<div className="space-y-6 animate-page-enter">
|
||||
<h1 className="text-2xl font-bold">People</h1>
|
||||
|
||||
<div className="relative max-w-xs">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search people..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
{/* Controls row */}
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<div className="relative flex-1 max-w-xs">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search people..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Filter: All / Favorite (only in local mode) */}
|
||||
{localOnly && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant={filter === 'all' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
className="h-8 text-xs"
|
||||
onClick={() => setFilter('all')}
|
||||
>
|
||||
All
|
||||
</Button>
|
||||
<Button
|
||||
variant={filter === 'favorite' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
className="h-8 text-xs gap-1"
|
||||
onClick={() => setFilter('favorite')}
|
||||
>
|
||||
<Heart className="h-3 w-3" />
|
||||
Favorite
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Local DB toggle */}
|
||||
<div className="flex items-center gap-2 ml-auto">
|
||||
<Switch
|
||||
id="local-toggle"
|
||||
checked={localOnly}
|
||||
onCheckedChange={setLocalOnly}
|
||||
/>
|
||||
<Label htmlFor="local-toggle" className="text-sm cursor-pointer">
|
||||
Local DB
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{activeQuery.isLoading ? (
|
||||
{isLoading ? (
|
||||
<div className="grid grid-cols-3 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8">
|
||||
{Array.from({ length: 24 }).map((_, i) => (
|
||||
<div key={i} className="flex flex-col items-center gap-2">
|
||||
@@ -59,31 +139,40 @@ export function PeoplePage() {
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : displayPeople.length === 0 ? (
|
||||
<div className="flex h-40 items-center justify-center text-muted-foreground">
|
||||
No people found.
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-3 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8">
|
||||
{people.map((person, index) => (
|
||||
{displayPeople.map((person: any, index: number) => (
|
||||
<div
|
||||
key={person.id}
|
||||
ref={index === people.length - 1 ? lastRef : undefined}
|
||||
ref={!localOnly && index === displayPeople.length - 1 ? lastRef : undefined}
|
||||
className="animate-card-enter"
|
||||
style={{ animationDelay: `${Math.min(index * 20, 300)}ms` }}
|
||||
>
|
||||
<Link
|
||||
to={`/people/tmdb/${person.id}`}
|
||||
to={localOnly ? `/people/${person.id}` : `/people/tmdb/${person.id}`}
|
||||
className="group flex flex-col items-center gap-2 text-center"
|
||||
>
|
||||
<Avatar className="h-24 w-24 transition-transform group-hover:scale-105">
|
||||
<AvatarImage
|
||||
src={getProfileUrl(person.profile_path)}
|
||||
alt={person.name}
|
||||
/>
|
||||
<AvatarFallback>
|
||||
{person.name
|
||||
.split(' ')
|
||||
.map((n) => n[0])
|
||||
.join('')}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="relative">
|
||||
<Avatar className="h-24 w-24 transition-transform group-hover:scale-105">
|
||||
<AvatarImage
|
||||
src={getProfileUrl(person.profile_path)}
|
||||
alt={person.name}
|
||||
/>
|
||||
<AvatarFallback>
|
||||
{person.name
|
||||
.split(' ')
|
||||
.map((n: string) => n[0])
|
||||
.join('')}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
{person.favorite && (
|
||||
<Heart className="absolute -top-1 -right-1 h-4 w-4 fill-red-500 text-red-500" />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm font-medium line-clamp-2">
|
||||
{person.name}
|
||||
</p>
|
||||
|
||||
@@ -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 (
|
||||
<div className="flex flex-col items-center justify-center gap-3 py-20">
|
||||
<p className="text-lg font-semibold">Person not found</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This person could not be loaded. They may not exist in the database.
|
||||
</p>
|
||||
<Button variant="outline" onClick={() => navigate('/people')}>
|
||||
Back to People
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading || !person) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -47,7 +63,18 @@ export function PersonDetailsPage() {
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="space-y-2 text-center sm:text-left sm:space-y-3">
|
||||
<h1 className="text-2xl font-bold sm:text-3xl">{person.name}</h1>
|
||||
<div className="flex items-center gap-2 justify-center sm:justify-start">
|
||||
<h1 className="text-2xl font-bold sm:text-3xl">{person.name}</h1>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 shrink-0"
|
||||
onClick={() => updatePerson.mutate({ id: person.id, data: { favorite: !person.favorite } })}
|
||||
disabled={updatePerson.isPending}
|
||||
>
|
||||
<Heart className={`h-5 w-5 ${person.favorite ? 'fill-red-500 text-red-500' : 'text-muted-foreground'}`} />
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground sm:justify-start sm:gap-3">
|
||||
{person.known_for_department && <span>{person.known_for_department}</span>}
|
||||
{person.birthday && (<><span>•</span><span>Born: {formatDate(person.birthday)}</span></>)}
|
||||
|
||||
@@ -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() {
|
||||
</div>
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex gap-6">
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:gap-6">
|
||||
<img
|
||||
src={getTmdbPosterUrl(season.poster_path, 'w185')}
|
||||
alt={season.name}
|
||||
className="h-56 w-36 shrink-0 rounded-lg object-cover shadow-lg"
|
||||
className="h-40 w-28 shrink-0 rounded-lg object-cover shadow-lg self-center sm:self-start sm:h-56 sm:w-36"
|
||||
/>
|
||||
<div className="flex-1 flex flex-col justify-center space-y-3">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">{season.name}</h1>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4">
|
||||
<h1 className="text-xl font-bold sm:text-2xl">{season.name}</h1>
|
||||
{/* Mark Season as Watched — top right */}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="shrink-0"
|
||||
className="shrink-0 w-full sm:w-auto"
|
||||
onClick={() => setShowMarkAllDialog(true)}
|
||||
>
|
||||
<ListChecks className="mr-1.5 h-4 w-4" />
|
||||
@@ -113,19 +114,20 @@ export function SeasonPage() {
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-semibold">Episodes</h3>
|
||||
<div className="space-y-2">
|
||||
{episodes.map((episode) => {
|
||||
{episodes.map((episode: Episode) => {
|
||||
const isWatched =
|
||||
!!episode.date_first_seen ||
|
||||
(episode.episodeSeens && episode.episodeSeens.length > 0);
|
||||
const seenDates = (episode.episodeSeens ?? []).map((s: EpisodeSeen) => s.date_seen);
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={episode.id}
|
||||
to={`/entry/${entryId}/season/${seasonId}/episode/${episode.id}`}
|
||||
className="flex gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
|
||||
className="flex gap-3 rounded-lg border border-border p-2 transition-colors hover:bg-accent/50 sm:gap-4 sm:p-3"
|
||||
>
|
||||
{/* Thumbnail */}
|
||||
<div className="h-16 w-28 shrink-0 overflow-hidden rounded bg-muted">
|
||||
<div className="h-14 w-24 shrink-0 overflow-hidden rounded bg-muted sm:h-16 sm:w-28">
|
||||
{episode.still_path ? (
|
||||
<img
|
||||
src={getTmdbPosterUrl(episode.still_path, 'w300')}
|
||||
@@ -153,11 +155,40 @@ export function SeasonPage() {
|
||||
<CheckCircle2 className="h-4 w-4 shrink-0 text-green-500" />
|
||||
)}
|
||||
</div>
|
||||
{episode.air_date && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{formatDate(episode.air_date)}
|
||||
</p>
|
||||
)}
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
{episode.air_date && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{formatDate(episode.air_date)}
|
||||
</p>
|
||||
)}
|
||||
{seenDates.length > 0 && (
|
||||
<>
|
||||
<span className="text-xs text-muted-foreground">•</span>
|
||||
{seenDates.length === 1 ? (
|
||||
<span className="text-xs text-green-600 dark:text-green-400">
|
||||
Seen {formatDate(seenDates[0])}
|
||||
</span>
|
||||
) : (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<span className="text-xs text-green-600 dark:text-green-400 cursor-default underline decoration-dotted">
|
||||
Seen {seenDates.length} times
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<div className="space-y-0.5 text-xs">
|
||||
{seenDates.map((d: string, i: number) => (
|
||||
<p key={i}>{formatDate(d)}</p>
|
||||
))}
|
||||
</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{episode.overview && (
|
||||
<p className="mt-1 text-xs text-muted-foreground line-clamp-2">
|
||||
{episode.overview}
|
||||
@@ -165,7 +196,7 @@ export function SeasonPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Watch button */}
|
||||
{/* Watch button — always clickable to add another seen record */}
|
||||
<Button
|
||||
size="icon"
|
||||
variant={isWatched ? 'secondary' : 'outline'}
|
||||
@@ -173,11 +204,8 @@ export function SeasonPage() {
|
||||
onClick={(ev) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
if (!isWatched) {
|
||||
setDialogEpisode(episode);
|
||||
}
|
||||
setDialogEpisode(episode);
|
||||
}}
|
||||
disabled={isWatched}
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
@@ -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 <EntryDetailsSkeleton />;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center gap-4 py-20">
|
||||
<p className="text-muted-foreground">Could not load entry from TMDB.</p>
|
||||
<Button variant="outline" onClick={() => navigate(-1)}>Go back</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
{/* Backdrop banner */}
|
||||
<div className="relative -mx-6 -mt-6 h-52 overflow-hidden">
|
||||
{backdrop ? (
|
||||
<img
|
||||
src={backdrop}
|
||||
alt=""
|
||||
className="h-full w-full object-cover opacity-25 blur-sm scale-105"
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full w-full bg-linear-to-br from-primary/15 to-primary/5" />
|
||||
)}
|
||||
<div className="absolute inset-0 bg-linear-to-t from-background via-background/60 to-transparent" />
|
||||
</div>
|
||||
|
||||
{/* Main content */}
|
||||
<div className="mx-auto max-w-4xl">
|
||||
{/* Add to Library button — top right */}
|
||||
<div className="flex justify-end gap-2 -mt-10 relative z-10 mb-2">
|
||||
{libraryEntry ? (
|
||||
<Button variant="outline" onClick={() => navigate(`/entry/${libraryEntry.id}`)}>
|
||||
Already in Library — View
|
||||
</Button>
|
||||
) : (
|
||||
<Button onClick={handleAddToLibrary} disabled={createEntry.isPending}>
|
||||
{createEntry.isPending ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Two-column header: poster | info */}
|
||||
<div className="flex flex-col gap-6 relative items-start sm:flex-row sm:gap-8 sm:-mt-8">
|
||||
{/* LEFT: Poster */}
|
||||
<div className="w-32 sm:w-44 shrink-0 self-start mx-auto sm:mx-0">
|
||||
<img
|
||||
src={poster}
|
||||
alt={preview.title}
|
||||
className="w-full aspect-2/3 rounded-xl object-cover shadow-2xl ring-1 ring-border/50"
|
||||
/>
|
||||
{/* External links */}
|
||||
<div className="flex items-center justify-center gap-3 mt-3">
|
||||
{preview.tmdb_id && (
|
||||
<a
|
||||
href={`https://www.themoviedb.org/${preview.is_tvseries ? 'tv' : 'movie'}/${preview.tmdb_id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
TMDB
|
||||
</a>
|
||||
)}
|
||||
{preview.imdb_id && (
|
||||
<a
|
||||
href={`https://www.imdb.com/title/${preview.imdb_id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
IMDb
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* RIGHT: Info */}
|
||||
<div className="flex-1 min-w-0 space-y-4">
|
||||
{/* Title */}
|
||||
<div className="space-y-1">
|
||||
<h1 className="text-3xl font-bold leading-tight">{preview.title}</h1>
|
||||
{preview.tagline && (
|
||||
<p className="text-sm text-muted-foreground italic">{preview.tagline}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Meta */}
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
||||
<span className="inline-flex items-center gap-1">
|
||||
{preview.is_tvseries ? <Tv className="h-3.5 w-3.5" /> : <Film className="h-3.5 w-3.5" />}
|
||||
{preview.is_tvseries ? 'TV Series' : 'Movie'}
|
||||
</span>
|
||||
{preview.release_date && (
|
||||
<>
|
||||
<span>•</span>
|
||||
<span>{getYear(preview.release_date)}</span>
|
||||
</>
|
||||
)}
|
||||
{preview.is_tvseries && preview.status && (
|
||||
<>
|
||||
<span>•</span>
|
||||
<span>{preview.status}</span>
|
||||
</>
|
||||
)}
|
||||
{preview.runtime && !preview.is_tvseries && (
|
||||
<>
|
||||
<span>•</span>
|
||||
<span>{formatRuntime(preview.runtime)}</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* TV series season count */}
|
||||
{preview.is_tvseries && preview.number_of_seasons != null && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Badge variant="secondary">
|
||||
{preview.number_of_seasons} {preview.number_of_seasons === 1 ? 'Season' : 'Seasons'}
|
||||
</Badge>
|
||||
{preview.number_of_episodes != null && (
|
||||
<span className="text-muted-foreground">
|
||||
({preview.number_of_episodes} episodes)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Genres */}
|
||||
{preview.genres.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{preview.genres.map((g) => (
|
||||
<Badge key={g.id} variant="outline" className="text-xs">
|
||||
{g.name}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Rating */}
|
||||
{preview.vote_average != null && preview.vote_average > 0 && (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-blue-500/10 border border-blue-500/20 px-3 py-1 text-sm text-blue-600 dark:text-blue-400 font-medium">
|
||||
<Star className="h-3.5 w-3.5 fill-current" />
|
||||
<span className="font-bold">TMDB:</span>
|
||||
{preview.vote_average.toFixed(1)}/10
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Storyline */}
|
||||
{preview.storyline && (
|
||||
<>
|
||||
<Separator />
|
||||
<p className="text-sm text-muted-foreground leading-relaxed max-w-prose">
|
||||
{preview.storyline}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user