Implemented the new react version of the frontend
This commit is contained in:
1 parent
236e6e06fb
commit
ffe7e52527
65 files changed
+5228
-177
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
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),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
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),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user