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

@@ -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 &amp; 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>
);
}