This commit is contained in:
Clément Le Bihan
2023-12-27 21:49:59 +01:00
parent af0531bb0c
commit 495380ec43
10 changed files with 53 additions and 26 deletions
+9 -9
View File
@@ -1,5 +1,5 @@
import { useMutation, useQueryClient } from "react-query"
import API from "../API";
import { useMutation, useQueryClient } from 'react-query';
import API from '../API';
/**
* Mutation to like/unlike a song
@@ -7,13 +7,13 @@ import API from "../API";
export const useLikeSongMutation = () => {
const queryClient = useQueryClient();
return useMutation(({ songId, like }: {songId: number, like: boolean}) => {
const apiCall = like ? API.addLikedSong : API.removeLikedSong
return useMutation(({ songId, like }: { songId: number; like: boolean }) => {
const apiCall = like ? API.addLikedSong : API.removeLikedSong;
return apiCall(songId).then(() => {
queryClient.invalidateQueries({ queryKey: ['liked songs'] })
queryClient.invalidateQueries({ queryKey: ['songs'] })
queryClient.invalidateQueries({ queryKey: [songId] })
queryClient.invalidateQueries({ queryKey: ['liked songs'] });
queryClient.invalidateQueries({ queryKey: ['songs'] });
queryClient.invalidateQueries({ queryKey: [songId] });
});
});
}
};