Skip to content

Commit

Permalink
refactor(useAddWatch): clean redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed May 6, 2024
1 parent d385a71 commit 93b9a4b
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions services/hooks/watch/useAddWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';

import addWatch from '@/services/api/watch/addWatch';

const useAddWatch = ({ slug }: { slug: string }) => {
const useAddWatch = () => {
const queryClient = useQueryClient();

return useMutation({
mutationKey: ['addToList', slug],
mutationFn: (mutationParams: {
status: API.WatchStatus;
score: number;
episodes: number;
rewatches?: number;
}) =>
addWatch({
params: {
slug: slug,
...mutationParams,
},
}),
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ['watch'] });
mutationKey: ['addToList'],
mutationFn: addWatch,
onSettled: async () => {
await queryClient.invalidateQueries({ queryKey: ['watch'], exact: false });
await queryClient.invalidateQueries({ queryKey: ['watchList'], exact: false });
},
});
};
Expand Down

0 comments on commit 93b9a4b

Please sign in to comment.