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:
1 parent
b3002a329d
commit
e460290b9b
11 files changed
+392
-146
No files matched your search
@@ -78,6 +78,24 @@ See [[Statistics]] for data details.
|
||||
|
||||
Base components from shadcn/ui in `components/ui/`:
|
||||
|
||||
`badge`, `avatar`, `button`, `calendar`, `card`, `checkbox`, `dialog`, `dropdown-menu`, `input`, `label`, `popover`, `progress`, `scroll-area`, `select`, `separator`, `sheet`, `skeleton`, `sonner`, `switch`, `tabs`, `textarea`, `tooltip`
|
||||
`badge`, `avatar`, `button`, `calendar`, `card`, `checkbox`, `dialog`, `dropdown-menu`, `input`, `label`, `popover`, `progress`, `scroll-area`, `select`, `separator`, `sheet`, `skeleton`, `sonner`, `star-rating`, `switch`, `tabs`, `textarea`, `tooltip`
|
||||
|
||||
### StarRating
|
||||
|
||||
> [!important] Centralized Rating Component
|
||||
> All user rating inputs across the application MUST use `StarRating` from `components/ui/star-rating.tsx`.
|
||||
|
||||
| Prop | Type | Default | Description |
|
||||
|---|---|---|---|
|
||||
| `value` | `number` | — | Current rating value (0–10, supports halves like 7.5) |
|
||||
| `onChange` | `(rating: number) => void` | — | Callback when user clicks a star. Clicking same value resets to 0 |
|
||||
| `max` | `number` | `10` | Number of stars |
|
||||
| `size` | `'sm' \| 'md' \| 'lg'` | `'lg'` | Star icon size (`h-4`, `h-6`, `h-8`) |
|
||||
| `readOnly` | `boolean` | `false` | Disables interaction |
|
||||
|
||||
Used in:
|
||||
- [[Components#Dialogs|RatingDialog]] — Entry rating dialog (size `lg`)
|
||||
- [[Components#Dialogs|EntrySettingsDialog]] — Inline entry rating (size `sm`)
|
||||
- [[Components#Dialogs|CollectionEditDialog]] — Collection rating (size `md`)
|
||||
|
||||
Theme: **base-nova** style.
|
||||
+12
-1
@@ -66,9 +66,20 @@ Sections:
|
||||
- Actions: watchlist, favorite, refresh, settings, rating
|
||||
- Watch history (movies) → [[Watch Tracking]]
|
||||
- Seasons list (TV) → links to SeasonPage
|
||||
- Cast list → links to PersonDetailsPage
|
||||
- Cast list → links to PersonDetailsPage; shows episode count for TV; "All Cast & Crew" link → EntryCastsPage
|
||||
- Media gallery → [[Media System]]
|
||||
|
||||
## EntryCastsPage
|
||||
|
||||
Full cast & crew grid for an entry. Route: `/entry/:id/cast`. Width: `max-w-4xl`.
|
||||
|
||||
- Breadcrumb: `Entry Title / Cast & Crew` (Title links back to EntryDetailsPage)
|
||||
- Filter: All / Cast / Crew
|
||||
- Sort: Credit Order, Popularity, Name, Birthday, Gender, Episode Count (TV only)
|
||||
- Sort direction toggle (asc/desc)
|
||||
- Shows role/job label and episode count for TV series
|
||||
- Links to [[Pages#PersonDetailsPage|PersonDetailsPage]]
|
||||
|
||||
## SeasonPage
|
||||
|
||||
Season detail with episode list. Width: `max-w-4xl`.
|
||||
|
||||
@@ -10,7 +10,8 @@ import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ImageIcon, Star } from 'lucide-react';
|
||||
import { ImageIcon } from 'lucide-react';
|
||||
import { StarRating } from '@/components/ui/star-rating';
|
||||
import { useUpdateCollection } from '@/hooks/useCollections';
|
||||
import type { Collection } from '@/types';
|
||||
|
||||
@@ -30,7 +31,6 @@ export function CollectionEditDialog({
|
||||
const [userRating, setUserRating] = useState(
|
||||
collection.user_rating ?? 0
|
||||
);
|
||||
const [hoveredStar, setHoveredStar] = useState<number | null>(null);
|
||||
const [posterFile, setPosterFile] = useState<File | null>(null);
|
||||
const [backdropFile, setBackdropFile] = useState<File | null>(null);
|
||||
const [posterPreview, setPosterPreview] = useState<string | null>(null);
|
||||
@@ -107,30 +107,8 @@ export function CollectionEditDialog({
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>User Rating</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex gap-1">
|
||||
{Array.from({ length: 10 }, (_, i) => i + 1).map((star) => {
|
||||
const displayRating = hoveredStar ?? userRating;
|
||||
return (
|
||||
<button
|
||||
key={star}
|
||||
type="button"
|
||||
className="transition-transform hover:scale-125 focus:outline-none"
|
||||
onMouseEnter={() => setHoveredStar(star)}
|
||||
onMouseLeave={() => setHoveredStar(null)}
|
||||
onClick={() => setUserRating(star === userRating ? 0 : star)}
|
||||
>
|
||||
<Star
|
||||
className={`h-5 w-5 transition-colors ${
|
||||
star <= displayRating
|
||||
? 'fill-yellow-400 text-yellow-400'
|
||||
: 'text-muted-foreground/30'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<StarRating value={userRating} onChange={setUserRating} size="md" />
|
||||
<span className="text-sm text-muted-foreground tabular-nums">
|
||||
{userRating > 0 ? `${userRating}/10` : '—'}
|
||||
</span>
|
||||
|
||||
@@ -7,10 +7,8 @@ import {
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { useUpdateEntry } from '@/hooks/useEntries';
|
||||
import { RatingDialog } from '@/components/dialogs/RatingDialog';
|
||||
import { useState } from 'react';
|
||||
import { Star } from 'lucide-react';
|
||||
import { useUpdateEntry, useUpdateEntryRatings } from '@/hooks/useEntries';
|
||||
import { StarRating } from '@/components/ui/star-rating';
|
||||
import type { Entry } from '@/types';
|
||||
|
||||
interface EntrySettingsDialogProps {
|
||||
@@ -25,7 +23,7 @@ export function EntrySettingsDialog({
|
||||
entry,
|
||||
}: EntrySettingsDialogProps) {
|
||||
const updateEntry = useUpdateEntry();
|
||||
const [showRating, setShowRating] = useState(false);
|
||||
const updateRatings = useUpdateEntryRatings();
|
||||
|
||||
const handleToggle = (field: keyof Entry, value: boolean) => {
|
||||
updateEntry.mutate({ id: entry.id, data: { [field]: value } });
|
||||
@@ -39,62 +37,47 @@ export function EntrySettingsDialog({
|
||||
{ field: 'auto_sync' as const, label: 'Auto Sync' },
|
||||
];
|
||||
|
||||
const userRating = entry.entryRatings?.user_rating;
|
||||
const userRating = entry.entryRatings?.user_rating ?? 0;
|
||||
|
||||
const handleRatingChange = (rating: number) => {
|
||||
updateRatings.mutate({
|
||||
id: entry.id,
|
||||
ratings: { id: entry.entryRatings?.id, user_rating: rating || null },
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Entry Settings</DialogTitle>
|
||||
<p className="text-sm text-muted-foreground line-clamp-1">{entry.title}</p>
|
||||
</DialogHeader>
|
||||
<div className="space-y-1 py-2">
|
||||
{boolSettings.map(({ field, label }) => (
|
||||
<div key={field} className="flex items-center justify-between rounded-lg px-1 py-2.5">
|
||||
<Label htmlFor={field} className="cursor-pointer">
|
||||
{label}
|
||||
</Label>
|
||||
<Switch
|
||||
id={field}
|
||||
checked={!!entry[field]}
|
||||
onCheckedChange={(checked) => handleToggle(field, checked)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<Separator className="my-2" />
|
||||
<div className="flex items-center justify-between rounded-lg px-1 py-2.5">
|
||||
<Label className="cursor-pointer">Your Rating</Label>
|
||||
<button
|
||||
className="flex items-center gap-1.5 text-sm font-medium hover:text-primary transition-colors"
|
||||
onClick={() => setShowRating(true)}
|
||||
>
|
||||
{userRating && userRating > 0 ? (
|
||||
<>
|
||||
<div className="flex">
|
||||
{Array.from({ length: 10 }).map((_, i) => (
|
||||
<Star
|
||||
key={i}
|
||||
className={`h-3 w-3 ${i < userRating ? 'fill-yellow-400 text-yellow-400' : 'text-muted-foreground/30'}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<span className="tabular-nums">{userRating}/10</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-muted-foreground">Not rated — click to rate</span>
|
||||
)}
|
||||
</button>
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Entry Settings</DialogTitle>
|
||||
<p className="text-sm text-muted-foreground line-clamp-1">{entry.title}</p>
|
||||
</DialogHeader>
|
||||
<div className="space-y-1 py-2">
|
||||
{boolSettings.map(({ field, label }) => (
|
||||
<div key={field} className="flex items-center justify-between rounded-lg px-1 py-2.5">
|
||||
<Label htmlFor={field} className="cursor-pointer">
|
||||
{label}
|
||||
</Label>
|
||||
<Switch
|
||||
id={field}
|
||||
checked={!!entry[field]}
|
||||
onCheckedChange={(checked) => handleToggle(field, checked)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<Separator className="my-2" />
|
||||
<div className="space-y-2 rounded-lg px-1 py-2.5">
|
||||
<Label>Your Rating</Label>
|
||||
<div className="flex items-center gap-3">
|
||||
<StarRating value={userRating} onChange={handleRatingChange} size="sm" />
|
||||
<span className="text-sm text-muted-foreground tabular-nums">
|
||||
{userRating > 0 ? `${userRating}/10` : '—'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<RatingDialog
|
||||
open={showRating}
|
||||
onOpenChange={setShowRating}
|
||||
entry={entry}
|
||||
/>
|
||||
</>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Star } from 'lucide-react';
|
||||
import { StarRating } from '@/components/ui/star-rating';
|
||||
import { useUpdateEntryRatings } from '@/hooks/useEntries';
|
||||
import type { Entry } from '@/types';
|
||||
|
||||
@@ -18,27 +18,18 @@ interface RatingDialogProps {
|
||||
|
||||
export function RatingDialog({ open, onOpenChange, entry }: RatingDialogProps) {
|
||||
const currentRating = entry.entryRatings?.user_rating ?? 0;
|
||||
const [hovered, setHovered] = useState<number | null>(null);
|
||||
const [selected, setSelected] = useState<number>(currentRating);
|
||||
const updateRatings = useUpdateEntryRatings();
|
||||
|
||||
// Sync selected when dialog opens or entry rating changes
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setSelected(entry.entryRatings?.user_rating ?? 0);
|
||||
}
|
||||
if (open) setSelected(entry.entryRatings?.user_rating ?? 0);
|
||||
}, [open, entry.entryRatings?.user_rating]);
|
||||
|
||||
const displayRating = hovered ?? selected;
|
||||
|
||||
const handleRate = (rating: number) => {
|
||||
setSelected(rating);
|
||||
updateRatings.mutate({
|
||||
id: entry.id,
|
||||
ratings: {
|
||||
id: entry.entryRatings?.id,
|
||||
user_rating: rating || null,
|
||||
},
|
||||
ratings: { id: entry.entryRatings?.id, user_rating: rating || null },
|
||||
});
|
||||
onOpenChange(false);
|
||||
};
|
||||
@@ -47,10 +38,7 @@ export function RatingDialog({ open, onOpenChange, entry }: RatingDialogProps) {
|
||||
setSelected(0);
|
||||
updateRatings.mutate({
|
||||
id: entry.id,
|
||||
ratings: {
|
||||
id: entry.entryRatings?.id,
|
||||
user_rating: null,
|
||||
},
|
||||
ratings: { id: entry.entryRatings?.id, user_rating: null },
|
||||
});
|
||||
onOpenChange(false);
|
||||
};
|
||||
@@ -64,47 +52,10 @@ export function RatingDialog({ open, onOpenChange, entry }: RatingDialogProps) {
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex flex-col items-center gap-4 py-2">
|
||||
<div className="flex gap-0.5">
|
||||
{Array.from({ length: 10 }, (_, i) => i + 1).map((star) => {
|
||||
const halfValue = star - 0.5;
|
||||
return (
|
||||
<div key={star} className="relative h-8 w-8">
|
||||
{/* Left half — half star */}
|
||||
<button
|
||||
className="absolute inset-y-0 left-0 w-1/2 z-10 focus:outline-none"
|
||||
onMouseEnter={() => setHovered(halfValue)}
|
||||
onMouseLeave={() => setHovered(null)}
|
||||
onClick={() => handleRate(halfValue)}
|
||||
/>
|
||||
{/* Right half — full star */}
|
||||
<button
|
||||
className="absolute inset-y-0 right-0 w-1/2 z-10 focus:outline-none"
|
||||
onMouseEnter={() => setHovered(star)}
|
||||
onMouseLeave={() => setHovered(null)}
|
||||
onClick={() => handleRate(star)}
|
||||
/>
|
||||
{/* Star icon */}
|
||||
<div className="pointer-events-none transition-transform hover:scale-125">
|
||||
{displayRating >= star ? (
|
||||
<Star className="h-8 w-8 fill-yellow-400 text-yellow-400 transition-colors" />
|
||||
) : displayRating >= halfValue ? (
|
||||
<div className="relative h-8 w-8">
|
||||
<Star className="absolute h-8 w-8 text-muted-foreground/30 transition-colors" />
|
||||
<div className="absolute inset-0 overflow-hidden w-1/2">
|
||||
<Star className="h-8 w-8 fill-yellow-400 text-yellow-400 transition-colors" />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<Star className="h-8 w-8 text-muted-foreground/30 transition-colors" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<StarRating value={selected} onChange={handleRate} size="lg" />
|
||||
|
||||
<p className="text-xl font-semibold tabular-nums">
|
||||
{displayRating > 0 ? `${displayRating} / 10` : '—'}
|
||||
{selected > 0 ? `${selected} / 10` : '—'}
|
||||
</p>
|
||||
|
||||
{(selected > 0 || currentRating > 0) && (
|
||||
|
||||
@@ -2,24 +2,38 @@ import { Link } from 'react-router-dom';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||
import { getProfileUrl } from '@/lib/media-utils';
|
||||
import { ChevronRight } from 'lucide-react';
|
||||
import type { Credit } from '@/types';
|
||||
|
||||
interface CastListProps {
|
||||
credits: Credit[];
|
||||
entryId?: number;
|
||||
isTvSeries?: boolean;
|
||||
}
|
||||
|
||||
export function CastList({ credits }: CastListProps) {
|
||||
export function CastList({ credits, entryId, isTvSeries }: CastListProps) {
|
||||
const castCredits = credits.filter((c) => c.cast_type === 'cast');
|
||||
|
||||
if (castCredits.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-semibold">Cast</h3>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-lg font-semibold">Cast</h3>
|
||||
{entryId != null && (
|
||||
<Link
|
||||
to={`/entry/${entryId}/cast`}
|
||||
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
All Cast & Crew
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
<ScrollArea className="w-full">
|
||||
<div className="flex gap-4 pb-4">
|
||||
{castCredits.map((credit) => (
|
||||
<CastCard key={credit.id} credit={credit} />
|
||||
<CastCard key={credit.id} credit={credit} isTvSeries={isTvSeries} />
|
||||
))}
|
||||
</div>
|
||||
<ScrollBar orientation="horizontal" />
|
||||
@@ -28,7 +42,7 @@ export function CastList({ credits }: CastListProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function CastCard({ credit }: { credit: Credit }) {
|
||||
function CastCard({ credit, isTvSeries }: { credit: Credit; isTvSeries?: boolean }) {
|
||||
const profileUrl = credit.people?.profile_path
|
||||
? getProfileUrl(credit.people.profile_path)
|
||||
: undefined;
|
||||
@@ -59,6 +73,11 @@ function CastCard({ credit }: { credit: Credit }) {
|
||||
<p className="text-[10px] text-muted-foreground leading-tight line-clamp-1">
|
||||
{credit.character}
|
||||
</p>
|
||||
{isTvSeries && credit.episode_count != null && credit.episode_count > 0 && (
|
||||
<p className="text-[10px] text-muted-foreground/70 leading-tight">
|
||||
{credit.episode_count} ep.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { useState } from 'react';
|
||||
import { Star } from 'lucide-react';
|
||||
|
||||
interface StarRatingProps {
|
||||
value: number;
|
||||
onChange?: (rating: number) => void;
|
||||
max?: number;
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
const sizeMap = {
|
||||
sm: 'h-4 w-4',
|
||||
md: 'h-6 w-6',
|
||||
lg: 'h-8 w-8',
|
||||
};
|
||||
|
||||
export function StarRating({
|
||||
value,
|
||||
onChange,
|
||||
max = 10,
|
||||
size = 'lg',
|
||||
readOnly = false,
|
||||
}: StarRatingProps) {
|
||||
const [hovered, setHovered] = useState<number | null>(null);
|
||||
const displayRating = hovered ?? value;
|
||||
const iconClass = sizeMap[size];
|
||||
|
||||
return (
|
||||
<div className="flex gap-0.5">
|
||||
{Array.from({ length: max }, (_, i) => i + 1).map((star) => {
|
||||
const halfValue = star - 0.5;
|
||||
return (
|
||||
<div key={star} className={`relative ${iconClass}`}>
|
||||
{!readOnly && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute inset-y-0 left-0 w-1/2 z-10 focus:outline-none"
|
||||
onMouseEnter={() => setHovered(halfValue)}
|
||||
onMouseLeave={() => setHovered(null)}
|
||||
onClick={() => onChange?.(halfValue === value ? 0 : halfValue)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute inset-y-0 right-0 w-1/2 z-10 focus:outline-none"
|
||||
onMouseEnter={() => setHovered(star)}
|
||||
onMouseLeave={() => setHovered(null)}
|
||||
onClick={() => onChange?.(star === value ? 0 : star)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<div className="pointer-events-none">
|
||||
{displayRating >= star ? (
|
||||
<Star className={`${iconClass} fill-yellow-400 text-yellow-400 transition-colors`} />
|
||||
) : displayRating >= halfValue ? (
|
||||
<div className={`relative ${iconClass}`}>
|
||||
<Star className={`absolute ${iconClass} text-muted-foreground/30 transition-colors`} />
|
||||
<div className="absolute inset-0 overflow-hidden w-1/2">
|
||||
<Star className={`${iconClass} fill-yellow-400 text-yellow-400 transition-colors`} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<Star className={`${iconClass} text-muted-foreground/30 transition-colors`} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 & 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} />
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
@@ -63,6 +63,11 @@ const SeasonPage = lazy(() =>
|
||||
const EpisodePage = lazy(() =>
|
||||
import('@/pages/EpisodePage').then((m) => ({ default: m.EpisodePage }))
|
||||
);
|
||||
const EntryCastsPage = lazy(() =>
|
||||
import('@/pages/EntryCastsPage').then((m) => ({
|
||||
default: m.EntryCastsPage,
|
||||
}))
|
||||
);
|
||||
const PeoplePage = lazy(() =>
|
||||
import('@/pages/PeoplePage').then((m) => ({ default: m.PeoplePage }))
|
||||
);
|
||||
@@ -185,6 +190,14 @@ export const router = createBrowserRouter([
|
||||
</SuspensePage>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/entry/:id/cast',
|
||||
element: (
|
||||
<SuspensePage fallback={<PeopleSkeleton />}>
|
||||
<EntryCastsPage />
|
||||
</SuspensePage>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/entry/:entryId/season/:seasonId',
|
||||
element: (
|
||||
|
||||
@@ -151,6 +151,7 @@ export interface People {
|
||||
biography: string | null;
|
||||
place_of_birth: string | null;
|
||||
known_for_department: string | null;
|
||||
popularity: number | null;
|
||||
fully_fetched: boolean;
|
||||
favorite: boolean;
|
||||
pinned: boolean;
|
||||
|
||||
Reference in new issue
Block a user