Skip to content

Commit

Permalink
fix: votes
Browse files Browse the repository at this point in the history
  • Loading branch information
nunocaseiro committed Jan 5, 2023
1 parent 71143e5 commit 5a61f45
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions frontend/src/components/Board/Card/CardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const CardFooter = React.memo<FooterProps>(
const [maxVotesReached, setMaxVotesReached] = useRecoilState(maxVotesReachedAtom);

const {
handleVote: { mutate },
handleVote: { mutate, status },
toastInfoMessage,
} = useVotes();

Expand Down Expand Up @@ -143,7 +143,7 @@ const CardFooter = React.memo<FooterProps>(

useEffect(() => {
const timer = setTimeout(() => {
if (votesData.countVotes === 0) return;
if (votesData.countVotes === 0 || status === 'loading') return;

mutate({
boardId,
Expand All @@ -157,14 +157,13 @@ const CardFooter = React.memo<FooterProps>(
...prev,
countVotes: 0,
}));
}, 200);
}, 300);

return () => clearTimeout(timer);
}, [boardId, card._id, cardItemId, mutate, socketId, votesData.countVotes]);
}, [boardId, card._id, cardItemId, mutate, socketId, status, votesData.countVotes]);

const handleDeleteVote = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
event.stopPropagation();
if (hideCards && createdBy?._id !== userId) return;
const handleDeleteVote = () => {
if ((hideCards && createdBy?._id !== userId) || status === 'loading') return;
setVotesData((prev) => ({
...prev,
countVotes: prev.countVotes - 1,
Expand All @@ -179,8 +178,8 @@ const CardFooter = React.memo<FooterProps>(
}
};

const handleAddVote = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
event.stopPropagation();
const handleAddVote = () => {
if (status === 'loading') return;
setVotesData((prev) => ({
...prev,
countVotes: prev.countVotes + 1,
Expand Down

0 comments on commit 5a61f45

Please sign in to comment.