From 5a61f45ca545aec23e713ce30c28aaddc3b245a3 Mon Sep 17 00:00:00 2001 From: Nuno Caseiro Date: Thu, 5 Jan 2023 20:54:41 +0000 Subject: [PATCH] fix: votes --- .../src/components/Board/Card/CardFooter.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/Board/Card/CardFooter.tsx b/frontend/src/components/Board/Card/CardFooter.tsx index 1a321a628..d303b18b6 100644 --- a/frontend/src/components/Board/Card/CardFooter.tsx +++ b/frontend/src/components/Board/Card/CardFooter.tsx @@ -92,7 +92,7 @@ const CardFooter = React.memo( const [maxVotesReached, setMaxVotesReached] = useRecoilState(maxVotesReachedAtom); const { - handleVote: { mutate }, + handleVote: { mutate, status }, toastInfoMessage, } = useVotes(); @@ -143,7 +143,7 @@ const CardFooter = React.memo( useEffect(() => { const timer = setTimeout(() => { - if (votesData.countVotes === 0) return; + if (votesData.countVotes === 0 || status === 'loading') return; mutate({ boardId, @@ -157,14 +157,13 @@ const CardFooter = React.memo( ...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) => { - 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, @@ -179,8 +178,8 @@ const CardFooter = React.memo( } }; - const handleAddVote = (event: React.MouseEvent) => { - event.stopPropagation(); + const handleAddVote = () => { + if (status === 'loading') return; setVotesData((prev) => ({ ...prev, countVotes: prev.countVotes + 1,