Files
Showy/react_frontend/src/hooks/useEpisodeSeen.ts
T
Mohammed Abad 63fdc00ac2 feat: entry details overhaul, navigation, rating half-stars, library growth "all", accuracy field
- SeasonPage: add back navigation link to entry details page
- EpisodePage: add breadcrumb navigation back to entry and season pages
- EntryCard: non-library entries now open a details dialog on click with overview, rating, and add-to-library button
- EntryDetailsPage: move favorite and mark-watched buttons into grouped dropdown menu with separators
- EntryDetailsPage: add favorite badge (heart icon) on top-left of poster
- EntryDetailsPage: add "mark as watched" clickable text next to runtime for unwatched movies
- EntryDetailsPage: genre pills are now clickable links that navigate to library page with genre filter
- EntryDetailsPage: hide status pill for movies; show status as text next to release date for TV series
- EntryDetailsPage: add delete entry option in dropdown menu with confirmation dialog and redirect to library
- EntryDetailsPage: add TMDB and IMDb external links under poster using entry.entryIds
- EntryDetailsPage: group all dropdown actions by relevance (Watch/Rate, Organize, Manage, Danger) with separators
- RatingDialog: support half-star ratings (0.5 increments) with left/right click zones per star
- RatingDialog: fix clear rating button by syncing state on dialog open and using dedicated handleClear function
- LibraryGrowthChart: add "All" option to year selector (default) showing cumulative growth across all years
- Frontend: add SeenAccuracy type to types/index.ts, update API layers and hooks to support accuracy
- EntrySeenDialog: add Date Accuracy selector (Exact/Estimated/Unknown) with EXACT default
- EpisodeSeenEditDialog: add Date Accuracy selector, updated overrideSubmit signature
- SeasonPage: pass accuracy through bulk mark-all-watched flow
2026-04-20 01:24:55 +01:00

118 lines
3.3 KiB
TypeScript

import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { toast } from 'sonner';
import { episodeSeenApi } from '@/api/episode-seen';
import { entryKeys } from './useEntries';
import { seasonKeys } from './useSeasons';
export const episodeSeenKeys = {
all: ['episode-seen'] as const,
byEpisode: (episodeId: number) =>
['episode-seen', 'by-episode', episodeId] as const,
};
export function useEpisodeSeenByEpisode(episodeId: number) {
return useQuery({
queryKey: episodeSeenKeys.byEpisode(episodeId),
queryFn: () => episodeSeenApi.getByEpisode(episodeId),
enabled: !!episodeId,
});
}
export function useCreateEpisodeSeen() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: {
entry_id: number;
episode_id: number;
date_seen: string;
seen_with?: string;
accuracy?: string;
season_id?: number;
}) => episodeSeenApi.create(data),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({
queryKey: episodeSeenKeys.byEpisode(variables.episode_id),
});
queryClient.invalidateQueries({
queryKey: entryKeys.detail(variables.entry_id),
});
queryClient.invalidateQueries({
queryKey: entryKeys.seasons(variables.entry_id),
});
if (variables.season_id) {
queryClient.invalidateQueries({
queryKey: seasonKeys.episodes(variables.season_id),
});
}
toast.success('Episode marked as watched');
},
onError: () => {
toast.error('Failed to mark episode as watched');
},
});
}
export function useUpdateEpisodeSeen() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
id,
data,
}: {
id: number;
data: { episode_id: number; entry_id: number; date_seen?: string; seen_with?: string | null; accuracy?: 'EXACT' | 'ESTIMATED' | 'UNKNOWN' };
}) => episodeSeenApi.update(id, data),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({
queryKey: episodeSeenKeys.byEpisode(variables.data.episode_id),
});
queryClient.invalidateQueries({
queryKey: entryKeys.detail(variables.data.entry_id),
});
toast.success('Episode watch record updated');
},
onError: () => {
toast.error('Failed to update episode watch record');
},
});
}
export function useDeleteEpisodeSeen() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
id,
entryId,
episodeId,
}: {
id: number;
entryId: number;
episodeId: number;
seasonId?: number;
}) => episodeSeenApi.delete(id),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({
queryKey: episodeSeenKeys.byEpisode(variables.episodeId),
});
queryClient.invalidateQueries({
queryKey: entryKeys.detail(variables.entryId),
});
queryClient.invalidateQueries({
queryKey: entryKeys.seasons(variables.entryId),
});
if (variables.seasonId) {
queryClient.invalidateQueries({
queryKey: seasonKeys.episodes(variables.seasonId),
});
}
toast.success('Episode watch record removed');
},
onError: () => {
toast.error('Failed to remove episode watch record');
},
});
}