- Toast notifications (sonner): success/error toasts on all mutations - Loading spinners: EntryCard add/remove, ConfirmDialog, EntrySeenDialog, favorite/refresh buttons - Page skeletons: 13 page-specific Suspense fallbacks replacing generic skeleton - CSS animations: card-enter (staggered), page-enter, slide-up-fade keyframes - Mobile layout: hamburger menu with sheet sidebar, responsive entry details - Mobile controls: separate compact filter/sort popovers for Library and Watchlist - Desktop sort: popover menu replacing Select dropdown on Library and Watchlist - Filter ranges: year 1950-2100, rating 0-10
101 lines
2.7 KiB
TypeScript
101 lines
2.7 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { toast } from 'sonner';
|
|
import { episodeSeenApi } from '@/api/episode-seen';
|
|
import { entryKeys } from './useEntries';
|
|
|
|
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;
|
|
}) => 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),
|
|
});
|
|
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 };
|
|
}) => 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;
|
|
}) => episodeSeenApi.delete(id),
|
|
onSuccess: (_data, variables) => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: episodeSeenKeys.byEpisode(variables.episodeId),
|
|
});
|
|
queryClient.invalidateQueries({
|
|
queryKey: entryKeys.detail(variables.entryId),
|
|
});
|
|
toast.success('Episode watch record removed');
|
|
},
|
|
onError: () => {
|
|
toast.error('Failed to remove episode watch record');
|
|
},
|
|
});
|
|
}
|