unlike message
This commit is contained in:
parent
ba682fc50d
commit
3e68448f36
|
|
@ -6,10 +6,10 @@ import { toastError, toastSuccess } from '@controllers/Toasts';
|
||||||
const Like = ({ messageId, isLiked }: { messageId: string; isLiked: boolean }) => {
|
const Like = ({ messageId, isLiked }: { messageId: string; isLiked: boolean }) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const mutateLike = useMutation(likePost, {
|
const mutateLike = useMutation(isLiked ? unlikePost : likePost, {
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
queryClient.invalidateQueries(['messages']);
|
queryClient.invalidateQueries(['messages']);
|
||||||
toastSuccess('Message aimé');
|
isLiked ? toastSuccess('Message aimé') : null;
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
toastError(error as string);
|
toastError(error as string);
|
||||||
|
|
@ -17,15 +17,14 @@ const Like = ({ messageId, isLiked }: { messageId: string; isLiked: boolean }) =
|
||||||
});
|
});
|
||||||
|
|
||||||
const like = () => {
|
const like = () => {
|
||||||
if (!isLiked) {
|
|
||||||
console.log('like');
|
|
||||||
|
|
||||||
mutateLike.mutate(messageId);
|
mutateLike.mutate(messageId);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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' : '')} />
|
<FaThumbsUp className={'fill-red-light text-xl w-10 h-10 p-2.5' + (isLiked ? ' fill-red' : '')} />
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue