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
+243
-9
No files matched your search
@@ -1,6 +1,9 @@
|
|||||||
const Episode = require("../models/Episode");
|
const Episode = require("../models/Episode");
|
||||||
const EpisodeSeen = require("../models/EpisodeSeen");
|
const EpisodeSeen = require("../models/EpisodeSeen");
|
||||||
const Season = require("../models/Season");
|
const Season = require("../models/Season");
|
||||||
|
const Entry = require("../models/Entry");
|
||||||
|
const EntryId = require("../models/EntryId");
|
||||||
|
const { fetchSeasonData } = require("../services/tmdbService");
|
||||||
|
|
||||||
class SeasonController {
|
class SeasonController {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -88,6 +91,48 @@ class SeasonController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async refreshSeason(req, res) {
|
||||||
|
try {
|
||||||
|
const season = await Season.findByPk(req.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: Entry,
|
||||||
|
as: "entry",
|
||||||
|
include: [{ model: EntryId, as: "entryId" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!season) {
|
||||||
|
return res.status(404).send("Season not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const tmdbTvId = season.entry?.entryId?.tmdb_id;
|
||||||
|
if (!tmdbTvId) {
|
||||||
|
return res.status(400).send("Entry has no TMDB ID");
|
||||||
|
}
|
||||||
|
|
||||||
|
const seasonData = await fetchSeasonData(tmdbTvId, season.season_number);
|
||||||
|
if (!seasonData) {
|
||||||
|
return res.status(500).send("Couldn't fetch data from TMDB");
|
||||||
|
}
|
||||||
|
|
||||||
|
await season.update({
|
||||||
|
name: seasonData.name,
|
||||||
|
overview: seasonData.overview,
|
||||||
|
episode_count: seasonData.episodes?.length ?? season.episode_count,
|
||||||
|
air_date: seasonData.air_date,
|
||||||
|
tmdb_rating: seasonData.vote_average,
|
||||||
|
poster_path: seasonData.poster_path,
|
||||||
|
});
|
||||||
|
|
||||||
|
const refreshedSeason = await Season.findByPk(req.params.id);
|
||||||
|
res.send(refreshedSeason);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).send(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async deleteSeason(req, res) {
|
async deleteSeason(req, res) {
|
||||||
try {
|
try {
|
||||||
const deleted = await Season.destroy({
|
const deleted = await Season.destroy({
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ seasonRouter.get("/:id/episodes", seasonController.getSeasonEpisodes);
|
|||||||
// * PUT - Update a season
|
// * PUT - Update a season
|
||||||
seasonRouter.put("/:id", seasonController.updateSeason);
|
seasonRouter.put("/:id", seasonController.updateSeason);
|
||||||
|
|
||||||
|
// * PUT - Refresh a season from TMDB
|
||||||
|
seasonRouter.put("/:id/refresh", seasonController.refreshSeason);
|
||||||
|
|
||||||
// * DELETE - Delete a season
|
// * DELETE - Delete a season
|
||||||
seasonRouter.delete("/:id", seasonController.deleteSeason);
|
seasonRouter.delete("/:id", seasonController.deleteSeason);
|
||||||
|
|
||||||
|
|||||||
@@ -17,4 +17,7 @@ export const seasonsApi = {
|
|||||||
api.put<Season>(`/seasons/${id}`, data).then((r) => r.data),
|
api.put<Season>(`/seasons/${id}`, data).then((r) => r.data),
|
||||||
|
|
||||||
delete: (id: number) => api.delete(`/seasons/${id}`).then((r) => r.data),
|
delete: (id: number) => api.delete(`/seasons/${id}`).then((r) => r.data),
|
||||||
|
|
||||||
|
refresh: (id: number) =>
|
||||||
|
api.put<Season>(`/seasons/${id}/refresh`).then((r) => r.data),
|
||||||
};
|
};
|
||||||
@@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { seasonsApi } from "@/api/seasons";
|
import { seasonsApi } from "@/api/seasons";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export const seasonKeys = {
|
export const seasonKeys = {
|
||||||
all: ["seasons"] as const,
|
all: ["seasons"] as const,
|
||||||
@@ -22,3 +23,42 @@ export function useSeasonEpisodes(id: number) {
|
|||||||
enabled: !!id,
|
enabled: !!id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useRefreshSeason() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: number) => seasonsApi.refresh(id),
|
||||||
|
onSuccess: (season) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: seasonKeys.detail(season.id) });
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: seasonKeys.episodes(season.id),
|
||||||
|
});
|
||||||
|
toast.success("Season refreshed");
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error("Failed to refresh season");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUpdateSeason() {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
id,
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
id: number;
|
||||||
|
data: Partial<Parameters<typeof seasonsApi.update>[1]>;
|
||||||
|
}) => seasonsApi.update(id, data),
|
||||||
|
onSuccess: (season) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: seasonKeys.detail(season.id) });
|
||||||
|
toast.success("Season updated");
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error("Failed to update season");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,16 +1,36 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useParams, Link } from "react-router-dom";
|
import { useParams, Link } from "react-router-dom";
|
||||||
import { useSeason, useSeasonEpisodes } from "@/hooks/useSeasons";
|
import {
|
||||||
|
useSeason,
|
||||||
|
useSeasonEpisodes,
|
||||||
|
useRefreshSeason,
|
||||||
|
} from "@/hooks/useSeasons";
|
||||||
import { useEntry, useEntrySeasons } from "@/hooks/useEntries";
|
import { useEntry, useEntrySeasons } from "@/hooks/useEntries";
|
||||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||||
import { EpisodeSeenEditDialog } from "@/components/dialogs/EpisodeSeenEditDialog";
|
import { EpisodeSeenEditDialog } from "@/components/dialogs/EpisodeSeenEditDialog";
|
||||||
import { MarkSeasonWatchedDialog } from "@/components/dialogs/MarkSeasonWatchedDialog";
|
import { MarkSeasonWatchedDialog } from "@/components/dialogs/MarkSeasonWatchedDialog";
|
||||||
|
import { SeasonRatingDialog } from "@/components/dialogs/SeasonRatingDialog";
|
||||||
import { StreamingDialog } from "@/components/streaming/StreamingDialog";
|
import { StreamingDialog } from "@/components/streaming/StreamingDialog";
|
||||||
import { useStreamingStore } from "@/stores/useStreamingStore";
|
import { useStreamingStore } from "@/stores/useStreamingStore";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Progress } from "@/components/ui/progress";
|
import { Progress } from "@/components/ui/progress";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Eye, CheckCircle2, ListChecks, PlayCircle } from "lucide-react";
|
import { StarRating } from "@/components/ui/star-rating";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import {
|
||||||
|
Eye,
|
||||||
|
CheckCircle2,
|
||||||
|
ListChecks,
|
||||||
|
PlayCircle,
|
||||||
|
Ellipsis,
|
||||||
|
RefreshCw,
|
||||||
|
Star,
|
||||||
|
} from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
@@ -33,8 +53,10 @@ export function SeasonPage() {
|
|||||||
entry?.title ??
|
entry?.title ??
|
||||||
useLibraryStore.getState().entries.get(parseInt(entryId!, 10))?.title;
|
useLibraryStore.getState().entries.get(parseInt(entryId!, 10))?.title;
|
||||||
const { initialize, play } = useStreamingStore();
|
const { initialize, play } = useStreamingStore();
|
||||||
|
const refreshSeason = useRefreshSeason();
|
||||||
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
|
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
|
||||||
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
|
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
|
||||||
|
const [showRatingDialog, setShowRatingDialog] = useState(false);
|
||||||
const [streamingOpen, setStreamingOpen] = useState(false);
|
const [streamingOpen, setStreamingOpen] = useState(false);
|
||||||
|
|
||||||
const handleWatchEpisode = (season: number, episodeNumber: number) => {
|
const handleWatchEpisode = (season: number, episodeNumber: number) => {
|
||||||
@@ -98,16 +120,37 @@ export function SeasonPage() {
|
|||||||
<div className="flex-1 flex flex-col justify-center space-y-3">
|
<div className="flex-1 flex flex-col justify-center space-y-3">
|
||||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4">
|
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4">
|
||||||
<h1 className="text-xl font-bold sm:text-2xl">{season.name}</h1>
|
<h1 className="text-xl font-bold sm:text-2xl">{season.name}</h1>
|
||||||
{/* Mark Season as Watched — top right */}
|
{/* Actions dropdown — top right */}
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="icon"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="shrink-0 w-full sm:w-auto"
|
className="shrink-0 self-end sm:self-start"
|
||||||
onClick={() => setShowMarkAllDialog(true)}
|
|
||||||
>
|
>
|
||||||
<ListChecks className="mr-1.5 h-4 w-4" />
|
<Ellipsis className="h-4 w-4" />
|
||||||
Mark Season Watched
|
|
||||||
</Button>
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-48">
|
||||||
|
<DropdownMenuItem onClick={() => setShowMarkAllDialog(true)}>
|
||||||
|
<ListChecks className="mr-2 h-4 w-4" />
|
||||||
|
Mark Season Watched
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setShowRatingDialog(true)}>
|
||||||
|
<Star className="mr-2 h-4 w-4" />
|
||||||
|
Rate Season
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => refreshSeason.mutate(season.id)}
|
||||||
|
disabled={refreshSeason.isPending}
|
||||||
|
>
|
||||||
|
<RefreshCw
|
||||||
|
className={`mr-2 h-4 w-4 ${refreshSeason.isPending ? "animate-spin" : ""}`}
|
||||||
|
/>
|
||||||
|
Refresh Season
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
<span>Season {season.season_number}</span>
|
<span>Season {season.season_number}</span>
|
||||||
@@ -121,6 +164,21 @@ export function SeasonPage() {
|
|||||||
<span>{totalEpisodes} episodes</span>
|
<span>{totalEpisodes} episodes</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Season rating */}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<StarRating value={season.user_rating ?? 0} readOnly size="sm" />
|
||||||
|
{season.user_rating != null && season.user_rating > 0 && (
|
||||||
|
<span className="text-sm font-medium tabular-nums">
|
||||||
|
{season.user_rating}/10
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{season.tmdb_rating != null && season.tmdb_rating > 0 && (
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
TMDB {season.tmdb_rating}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Watch progress */}
|
{/* Watch progress */}
|
||||||
<div className="flex items-center gap-3 max-w-xs">
|
<div className="flex items-center gap-3 max-w-xs">
|
||||||
<Progress value={progress} className="flex-1 h-2" />
|
<Progress value={progress} className="flex-1 h-2" />
|
||||||
@@ -281,6 +339,15 @@ export function SeasonPage() {
|
|||||||
episodes={episodes}
|
episodes={episodes}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Season Rating dialog */}
|
||||||
|
{season && (
|
||||||
|
<SeasonRatingDialog
|
||||||
|
open={showRatingDialog}
|
||||||
|
onOpenChange={setShowRatingDialog}
|
||||||
|
season={season}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Streaming dialog */}
|
{/* Streaming dialog */}
|
||||||
{entry && streamingOpen && (
|
{entry && streamingOpen && (
|
||||||
<StreamingDialog
|
<StreamingDialog
|
||||||
|
|||||||
Reference in new issue
Block a user