- CalendarPage: restore poster/still thumbnail (h-8 w-5) in episode items; add getTmdbPosterUrl import; extend EpisodeWithEntry type with poster_path - EpisodeSeenEditDialog: add mode 'create'|'edit' support; record prop is now optional; create mode uses useCreateEpisodeSeen with today as default date - EpisodePage: Mark as Watched button now opens EpisodeSeenEditDialog (create mode) instead of firing mutation directly; delete shows ConfirmDialog before deleting; remove unused useCreateEpisodeSeen import
248 lines
9.4 KiB
TypeScript
248 lines
9.4 KiB
TypeScript
import { useParams } from 'react-router-dom';
|
||
import { useState } from 'react';
|
||
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 { 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 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 { data: tmdbFilmography, isLoading: tmdbLoading } = usePersonTmdbFilmography(personId);
|
||
useLibrary();
|
||
const libraryMap = useLibraryStore((s) => s.entries);
|
||
const libraryLoaded = useLibraryStore((s) => s.isLoaded);
|
||
|
||
if (isLoading || !person) {
|
||
return (
|
||
<div className="space-y-6">
|
||
<div className="flex gap-6">
|
||
<Skeleton className="h-48 w-48 rounded-full" />
|
||
<div className="flex-1 space-y-3">
|
||
<Skeleton className="h-8 w-48" />
|
||
<Skeleton className="h-4 w-32" />
|
||
<Skeleton className="h-20 w-full" />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<div className="space-y-8">
|
||
<div className="flex gap-8">
|
||
<Avatar className="h-48 w-48 shrink-0">
|
||
<AvatarImage src={getProfileUrl(person.profile_path)} alt={person.name} />
|
||
<AvatarFallback className="text-3xl">
|
||
{person.name.split(' ').map((n: string) => n[0]).join('')}
|
||
</AvatarFallback>
|
||
</Avatar>
|
||
<div className="space-y-3">
|
||
<h1 className="text-3xl font-bold">{person.name}</h1>
|
||
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
|
||
{person.known_for_department && <span>{person.known_for_department}</span>}
|
||
{person.birthday && (<><span>•</span><span>Born: {formatDate(person.birthday)}</span></>)}
|
||
{person.deathday && (<><span>•</span><span>Died: {formatDate(person.deathday)}</span></>)}
|
||
{person.place_of_birth && (<><span>•</span><span>{person.place_of_birth}</span></>)}
|
||
</div>
|
||
{person.biography && (
|
||
<p className="text-sm text-muted-foreground leading-relaxed max-w-2xl line-clamp-6">
|
||
{person.biography}
|
||
</p>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
<Separator />
|
||
|
||
<FilmographySection
|
||
libraryMap={libraryMap}
|
||
libraryLoaded={libraryLoaded}
|
||
tmdbFilmography={tmdbFilmography}
|
||
tmdbLoading={tmdbLoading}
|
||
/>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
interface FilmographySectionProps {
|
||
libraryMap: Map<number, import('@/types').Entry>;
|
||
libraryLoaded: boolean;
|
||
tmdbFilmography?: { cast: TmdbFilmographyItem[]; crew: TmdbFilmographyItem[] };
|
||
tmdbLoading: boolean;
|
||
}
|
||
|
||
function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLoading }: FilmographySectionProps) {
|
||
const [libraryPage, setLibraryPage] = useState(0);
|
||
const [otherPage, setOtherPage] = useState(0);
|
||
const PAGE_SIZE = 6; // 6 cols × 1 row
|
||
const GRID = 'grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6';
|
||
|
||
if (tmdbLoading || !libraryLoaded) {
|
||
return (
|
||
<div className="space-y-4">
|
||
<h2 className="text-xl font-semibold">Filmography</h2>
|
||
<div className={GRID}>
|
||
{Array.from({ length: 6 }).map((_, i) => (
|
||
<Skeleton key={i} className="aspect-2/3 rounded-lg" />
|
||
))}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const allTmdbCredits = [
|
||
...(tmdbFilmography?.cast ?? []),
|
||
...(tmdbFilmography?.crew?.filter((c) => c.job === 'Director' || c.department === 'Directing') ?? []),
|
||
];
|
||
const seenTmdbIds = new Set<number>();
|
||
const dedupedCredits = allTmdbCredits.filter((c) => {
|
||
if (seenTmdbIds.has(c.id)) return false;
|
||
seenTmdbIds.add(c.id);
|
||
return true;
|
||
});
|
||
|
||
const tmdbIdToLibraryEntry = new Map<number, import('@/types').Entry>();
|
||
for (const entry of libraryMap.values()) {
|
||
if (entry.entryIds?.tmdb_id != null) {
|
||
tmdbIdToLibraryEntry.set(Number(entry.entryIds.tmdb_id), entry);
|
||
}
|
||
}
|
||
|
||
// Sort by popularity descending
|
||
const sorted = [...dedupedCredits].sort((a, b) => (b.popularity ?? 0) - (a.popularity ?? 0));
|
||
const libraryCredits = sorted.filter((c) => tmdbIdToLibraryEntry.has(c.id));
|
||
const otherCredits = sorted.filter((c) => !tmdbIdToLibraryEntry.has(c.id));
|
||
|
||
if (sorted.length === 0) {
|
||
return (
|
||
<div className="space-y-4">
|
||
<h2 className="text-xl font-semibold">Filmography</h2>
|
||
<p className="text-sm text-muted-foreground">No filmography found.</p>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const librarySlice = libraryCredits.slice(libraryPage * PAGE_SIZE, (libraryPage + 1) * PAGE_SIZE);
|
||
const otherSlice = otherCredits.slice(otherPage * PAGE_SIZE, (otherPage + 1) * PAGE_SIZE);
|
||
const libraryTotalPages = Math.ceil(libraryCredits.length / PAGE_SIZE);
|
||
const otherTotalPages = Math.ceil(otherCredits.length / PAGE_SIZE);
|
||
|
||
return (
|
||
<div className="space-y-8">
|
||
<h2 className="text-xl font-semibold">Filmography</h2>
|
||
|
||
{libraryCredits.length > 0 && (
|
||
<div className="space-y-3">
|
||
<div className="flex items-center justify-between">
|
||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
||
In Your Library ({libraryCredits.length})
|
||
</h3>
|
||
{libraryTotalPages > 1 && (
|
||
<div className="flex items-center gap-1">
|
||
<Button
|
||
variant="ghost" size="icon" className="h-7 w-7"
|
||
disabled={libraryPage === 0}
|
||
onClick={() => setLibraryPage((p) => p - 1)}
|
||
>
|
||
<ChevronLeft className="h-4 w-4" />
|
||
</Button>
|
||
<span className="text-xs text-muted-foreground tabular-nums">
|
||
{libraryPage + 1}/{libraryTotalPages}
|
||
</span>
|
||
<Button
|
||
variant="ghost" size="icon" className="h-7 w-7"
|
||
disabled={libraryPage === libraryTotalPages - 1}
|
||
onClick={() => setLibraryPage((p) => p + 1)}
|
||
>
|
||
<ChevronRight className="h-4 w-4" />
|
||
</Button>
|
||
</div>
|
||
)}
|
||
</div>
|
||
<div className={GRID}>
|
||
{librarySlice.map((credit) => {
|
||
const entry = tmdbIdToLibraryEntry.get(credit.id)!;
|
||
return (
|
||
<div key={credit.id} className="space-y-1">
|
||
<EntryCard entry={entry} />
|
||
{credit.character && (
|
||
<p className="text-xs text-muted-foreground text-center line-clamp-1 px-1">{credit.character}</p>
|
||
)}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{otherCredits.length > 0 && (
|
||
<div className="space-y-3">
|
||
<div className="flex items-center justify-between">
|
||
<h3 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
|
||
Not in Library ({otherCredits.length})
|
||
</h3>
|
||
{otherTotalPages > 1 && (
|
||
<div className="flex items-center gap-1">
|
||
<Button
|
||
variant="ghost" size="icon" className="h-7 w-7"
|
||
disabled={otherPage === 0}
|
||
onClick={() => setOtherPage((p) => p - 1)}
|
||
>
|
||
<ChevronLeft className="h-4 w-4" />
|
||
</Button>
|
||
<span className="text-xs text-muted-foreground tabular-nums">
|
||
{otherPage + 1}/{otherTotalPages}
|
||
</span>
|
||
<Button
|
||
variant="ghost" size="icon" className="h-7 w-7"
|
||
disabled={otherPage === otherTotalPages - 1}
|
||
onClick={() => setOtherPage((p) => p + 1)}
|
||
>
|
||
<ChevronRight className="h-4 w-4" />
|
||
</Button>
|
||
</div>
|
||
)}
|
||
</div>
|
||
<div className={GRID}>
|
||
{otherSlice.map((credit) => {
|
||
const tmdbEntry: TmdbEntry = {
|
||
id: credit.id,
|
||
title: credit.title,
|
||
name: credit.name,
|
||
poster_path: credit.poster_path,
|
||
backdrop_path: null,
|
||
release_date: credit.release_date,
|
||
first_air_date: credit.first_air_date,
|
||
media_type: credit.media_type,
|
||
overview: '',
|
||
vote_average: 0,
|
||
vote_count: 0,
|
||
genre_ids: [],
|
||
popularity: credit.popularity ?? 0,
|
||
};
|
||
return (
|
||
<div key={credit.id} className="space-y-1">
|
||
<EntryCard tmdbEntry={tmdbEntry} />
|
||
{credit.character && (
|
||
<p className="text-xs text-muted-foreground text-center line-clamp-1 px-1">{credit.character}</p>
|
||
)}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|