unlike message

This commit is contained in:
Guillaume Dorce 2022-10-07 14:27:36 +02:00
parent ba682fc50d
commit 3e68448f36
1 changed files with 7 additions and 8 deletions

View File

@ -6,10 +6,10 @@ import { toastError, toastSuccess } from '@controllers/Toasts';
const Like = ({ messageId, isLiked }: { messageId: string; isLiked: boolean }) => {
const queryClient = useQueryClient();
const mutateLike = useMutation(likePost, {
const mutateLike = useMutation(isLiked ? unlikePost : likePost, {
onSuccess: (data) => {
queryClient.invalidateQueries(['messages']);
toastSuccess('Message aimé');
isLiked ? toastSuccess('Message aimé') : null;
},
onError: (error) => {
toastError(error as string);
@ -17,15 +17,14 @@ const Like = ({ messageId, isLiked }: { messageId: string; isLiked: boolean }) =
});
const like = () => {
if (!isLiked) {
console.log('like');
mutateLike.mutate(messageId);
}
mutateLike.mutate(messageId);
};
return (
<button className="absolute -bottom-10 right-0 mb-2 rounded-full bg-grey-dark shadow-lg shadow-slate-900 cursor-pointer" onClick={like}>
<button
className="absolute -bottom-10 right-0 mb-2 rounded-full bg-grey-dark shadow-lg shadow-slate-900 cursor-pointer"
onClick={like}
>
<FaThumbsUp className={'fill-red-light text-xl w-10 h-10 p-2.5' + (isLiked ? ' fill-red' : '')} />
</button>
);