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:
Mohammed AbadandCopilot committed 2026-04-27 04:03:21 +01:00
1 parent 25b645a16f
commit 02cdcf733d
18 files changed
+949 -204

No files matched your search

+121 -32
View File
@@ -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>