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
@@ -1,5 +1,6 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { seasonsApi } from "@/api/seasons";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export const seasonKeys = {
|
||||
all: ["seasons"] as const,
|
||||
@@ -22,3 +23,42 @@ export function useSeasonEpisodes(id: number) {
|
||||
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");
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user