feat(frontend): unify person routing, cast page, and centralize ratings

- Add EntryCastsPage at /entry/:id/cast with sort/filter and breadcrumb nav
- Show episode count under character names for TV series in CastList
- Add "All Cast & Crew →" link to CastList section header
- Extract reusable StarRating component with half-star support and 3 sizes
- Replace all rating UIs (EntrySettingsDialog, CollectionEditDialog, RatingDialog)
- Document StarRating component as the single rating standard in Components.md

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Mohammed AbadandCopilot committed 2026-04-27 13:45:48 +01:00
1 parent b3002a329d
commit e460290b9b
11 files changed
+392 -146

No files matched your search

+200
View File
@@ -0,0 +1,200 @@
import { useState, useMemo } from 'react';
import { useParams, Link } from 'react-router-dom';
import { useEntry } from '@/hooks/useEntries';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Skeleton } from '@/components/ui/skeleton';
import { Button } from '@/components/ui/button';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { getProfileUrl } from '@/lib/media-utils';
import { ArrowUpDown } from 'lucide-react';
import type { Credit } from '@/types';
type SortField = 'order' | 'popularity' | 'name' | 'birthday' | 'gender' | 'episode_count';
type SortDir = 'asc' | 'desc';
type CastFilter = 'all' | 'cast' | 'crew';
function sortCredits(credits: Credit[], field: SortField, dir: SortDir): Credit[] {
return [...credits].sort((a, b) => {
let cmp = 0;
switch (field) {
case 'order':
cmp = (a.order ?? 9999) - (b.order ?? 9999);
break;
case 'popularity':
cmp = (b.people?.popularity ?? 0) - (a.people?.popularity ?? 0);
break;
case 'name':
cmp = (a.people?.name ?? '').localeCompare(b.people?.name ?? '');
break;
case 'birthday': {
const da = a.people?.birthday ? new Date(a.people.birthday).getTime() : 0;
const db = b.people?.birthday ? new Date(b.people.birthday).getTime() : 0;
cmp = da - db;
break;
}
case 'gender':
cmp = (a.people?.gender ?? 0) - (b.people?.gender ?? 0);
break;
case 'episode_count':
cmp = (b.episode_count ?? 0) - (a.episode_count ?? 0);
break;
}
return dir === 'asc' ? cmp : -cmp;
});
}
export function EntryCastsPage() {
const { id } = useParams<{ id: string }>();
const entryId = parseInt(id!, 10);
const { data: entry, isLoading } = useEntry(entryId);
const [sortField, setSortField] = useState<SortField>('order');
const [sortDir, setSortDir] = useState<SortDir>('asc');
const [filter, setFilter] = useState<CastFilter>('all');
const filtered = useMemo(() => {
if (!entry?.credits) return [];
if (filter === 'cast') return entry.credits.filter((c) => c.cast_type === 'cast');
if (filter === 'crew') return entry.credits.filter((c) => c.cast_type === 'crew');
return entry.credits;
}, [entry?.credits, filter]);
const sorted = useMemo(() => sortCredits(filtered, sortField, sortDir), [filtered, sortField, sortDir]);
if (isLoading || !entry) {
return (
<div className="space-y-6 mx-auto max-w-4xl">
<Skeleton className="h-5 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: 18 }).map((_, i) => (
<div key={i} className="flex flex-col items-center gap-2">
<Skeleton className="h-24 w-24 rounded-full" />
<Skeleton className="h-4 w-20" />
</div>
))}
</div>
</div>
);
}
const isTv = entry.is_tvseries;
return (
<div className="space-y-6 animate-page-enter mx-auto max-w-4xl">
{/* Breadcrumb */}
<div className="flex items-center gap-1.5 text-sm text-muted-foreground">
<Link
to={`/entry/${entryId}`}
className="hover:text-foreground transition-colors truncate max-w-60"
>
{entry.title}
</Link>
<span>/</span>
<span className="text-foreground font-medium">Cast &amp; Crew</span>
</div>
{/* Controls */}
<div className="flex flex-wrap items-center gap-3">
<Select value={filter} onValueChange={(v) => setFilter(v as CastFilter)}>
<SelectTrigger className="w-32">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All</SelectItem>
<SelectItem value="cast">Cast</SelectItem>
<SelectItem value="crew">Crew</SelectItem>
</SelectContent>
</Select>
<Select value={sortField} onValueChange={(v) => setSortField(v as SortField)}>
<SelectTrigger className="w-40">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="order">Credit Order</SelectItem>
<SelectItem value="popularity">Popularity</SelectItem>
<SelectItem value="name">Name</SelectItem>
<SelectItem value="birthday">Birthday</SelectItem>
<SelectItem value="gender">Gender</SelectItem>
{isTv && <SelectItem value="episode_count">Episodes</SelectItem>}
</SelectContent>
</Select>
<Button
variant="ghost"
size="icon"
className="h-9 w-9"
onClick={() => setSortDir((d) => (d === 'asc' ? 'desc' : 'asc'))}
>
<ArrowUpDown className="h-4 w-4" />
</Button>
<span className="text-sm text-muted-foreground ml-auto">
{sorted.length} {sorted.length === 1 ? 'credit' : 'credits'}
</span>
</div>
{/* Grid */}
{sorted.length === 0 ? (
<p className="text-center text-muted-foreground py-12">No credits found.</p>
) : (
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
{sorted.map((credit) => (
<CreditCard key={credit.id} credit={credit} isTv={isTv} />
))}
</div>
)}
</div>
);
}
function CreditCard({ credit, isTv }: { credit: Credit; isTv: boolean }) {
const profileUrl = credit.people?.profile_path
? getProfileUrl(credit.people.profile_path)
: undefined;
const personLink = credit.entry_id
? `/people/${credit.people_id}`
: `/people/tmdb/${credit.people?.tmdb_id ?? credit.people_id}`;
const roleLabel =
credit.cast_type === 'cast'
? credit.character
: credit.job || credit.department;
return (
<Link
to={personLink}
className="group flex flex-col items-center gap-2 text-center p-2 rounded-lg hover:bg-accent/50 transition-colors"
>
<Avatar className="h-20 w-20 transition-transform group-hover:scale-105">
<AvatarImage src={profileUrl} alt={credit.people?.name} />
<AvatarFallback className="text-xs">
{credit.people?.name
?.split(' ')
.map((n) => n[0])
.join('')}
</AvatarFallback>
</Avatar>
<div className="min-w-0 w-full">
<p className="text-xs font-medium leading-tight line-clamp-2">{credit.people?.name}</p>
{roleLabel && (
<p className="text-[10px] text-muted-foreground leading-tight line-clamp-1 mt-0.5">
{roleLabel}
</p>
)}
{isTv && credit.episode_count != null && credit.episode_count > 0 && (
<p className="text-[10px] text-muted-foreground/70 leading-tight mt-0.5">
{credit.episode_count} {credit.episode_count === 1 ? 'episode' : 'episodes'}
</p>
)}
</div>
</Link>
);
}
@@ -380,7 +380,7 @@ export function EntryDetailsPage() {
{e.credits && e.credits.length > 0 && (
<>
<Separator />
<CastList credits={e.credits} />
<CastList credits={e.credits} entryId={e.id} isTvSeries={e.is_tvseries} />
</>
)}