- 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>
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
import { Button } from '@/components/ui/button';
|
|
import { StarRating } from '@/components/ui/star-rating';
|
|
import { useUpdateEntryRatings } from '@/hooks/useEntries';
|
|
import type { Entry } from '@/types';
|
|
|
|
interface RatingDialogProps {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
entry: Entry;
|
|
}
|
|
|
|
export function RatingDialog({ open, onOpenChange, entry }: RatingDialogProps) {
|
|
const currentRating = entry.entryRatings?.user_rating ?? 0;
|
|
const [selected, setSelected] = useState<number>(currentRating);
|
|
const updateRatings = useUpdateEntryRatings();
|
|
|
|
useEffect(() => {
|
|
if (open) setSelected(entry.entryRatings?.user_rating ?? 0);
|
|
}, [open, entry.entryRatings?.user_rating]);
|
|
|
|
const handleRate = (rating: number) => {
|
|
setSelected(rating);
|
|
updateRatings.mutate({
|
|
id: entry.id,
|
|
ratings: { id: entry.entryRatings?.id, user_rating: rating || null },
|
|
});
|
|
onOpenChange(false);
|
|
};
|
|
|
|
const handleClear = () => {
|
|
setSelected(0);
|
|
updateRatings.mutate({
|
|
id: entry.id,
|
|
ratings: { id: entry.entryRatings?.id, user_rating: null },
|
|
});
|
|
onOpenChange(false);
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="w-auto sm:max-w-none">
|
|
<DialogHeader>
|
|
<DialogTitle>Rate</DialogTitle>
|
|
<p className="text-sm text-muted-foreground line-clamp-1">{entry.title}</p>
|
|
</DialogHeader>
|
|
|
|
<div className="flex flex-col items-center gap-4 py-2">
|
|
<StarRating value={selected} onChange={handleRate} size="lg" />
|
|
|
|
<p className="text-xl font-semibold tabular-nums">
|
|
{selected > 0 ? `${selected} / 10` : '—'}
|
|
</p>
|
|
|
|
{(selected > 0 || currentRating > 0) && (
|
|
<Button variant="ghost" size="sm" onClick={handleClear}>
|
|
Clear rating
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|