Add season refresh, rating display, and actions dropdown to SeasonPage
Backend: Added PUT /seasons/:id/refresh endpoint that fetches updated TMDB data for a single season. Frontend: - New SeasonRatingDialog for rating seasons via StarRating - useRefreshSeason and useUpdateSeason hooks with query invalidation - SeasonPage now shows inline season rating (user + TMDB) - Mark Watched, Rate, and Refresh actions moved under a dropdown menu
This commit is contained in:
1 parent
1aa0a84f4d
commit
4d88747649
6 files changed
+247
-13
No files matched your search
@@ -0,0 +1,76 @@
|
||||
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 { useUpdateSeason } from "@/hooks/useSeasons";
|
||||
import type { Season } from "@/types";
|
||||
|
||||
interface SeasonRatingDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
season: Season;
|
||||
}
|
||||
|
||||
export function SeasonRatingDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
season,
|
||||
}: SeasonRatingDialogProps) {
|
||||
const currentRating = season.user_rating ?? 0;
|
||||
const [selected, setSelected] = useState<number>(currentRating);
|
||||
const updateSeason = useUpdateSeason();
|
||||
|
||||
useEffect(() => {
|
||||
if (open) setSelected(season.user_rating ?? 0);
|
||||
}, [open, season.user_rating]);
|
||||
|
||||
const handleRate = (rating: number) => {
|
||||
setSelected(rating);
|
||||
updateSeason.mutate({
|
||||
id: season.id,
|
||||
data: { user_rating: rating || null },
|
||||
});
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const handleClear = () => {
|
||||
setSelected(0);
|
||||
updateSeason.mutate({
|
||||
id: season.id,
|
||||
data: { user_rating: null },
|
||||
});
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="w-auto sm:max-w-none">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Rate Season</DialogTitle>
|
||||
<p className="text-sm text-muted-foreground line-clamp-1">
|
||||
{season.name}
|
||||
</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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user