From f8ab8a3a72b6b2984dd472b891f9eeebeb93f2c6 Mon Sep 17 00:00:00 2001 From: Francisco Morgado Date: Mon, 12 Sep 2022 10:13:45 +0100 Subject: [PATCH 1/2] feat: disable button with useeffect toggle --- frontend/src/components/Board/Card/CardFooter.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/src/components/Board/Card/CardFooter.tsx b/frontend/src/components/Board/Card/CardFooter.tsx index 422d49d58..aa248e2a8 100644 --- a/frontend/src/components/Board/Card/CardFooter.tsx +++ b/frontend/src/components/Board/Card/CardFooter.tsx @@ -110,6 +110,8 @@ const CardFooter = React.memo( const [countVotes, setCountVotes] = useState(0); + const [disableButton, setDisableButton] = useState(false); + const firstUpdate = useRef(true); useEffect(() => { if (firstUpdate.current) { @@ -139,6 +141,7 @@ const CardFooter = React.memo( event.stopPropagation(); if (hideCards && card.createdBy?._id !== userId) return; if (user && user.votesCount + countVotes <= 0) return; + setDisableButton(true); setCountVotes(countVotes - 1); }; @@ -148,9 +151,14 @@ const CardFooter = React.memo( if (maxVotes && user && user.votesCount >= maxVotes) return; if (maxVotes && user && user.votesCount + countVotes >= maxVotes) return; + setDisableButton(true); setCountVotes(countVotes + 1); }; + useEffect(() => { + setDisableButton(false); + }, [card]); + return ( {!anonymous && !teamName && ( @@ -189,6 +197,7 @@ const CardFooter = React.memo( > = maxVotes) @@ -218,6 +227,7 @@ const CardFooter = React.memo( > Date: Mon, 12 Sep 2022 10:53:06 +0100 Subject: [PATCH 2/2] fix: variable rename --- frontend/src/components/Board/Card/CardFooter.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/Board/Card/CardFooter.tsx b/frontend/src/components/Board/Card/CardFooter.tsx index aa248e2a8..d394c76de 100644 --- a/frontend/src/components/Board/Card/CardFooter.tsx +++ b/frontend/src/components/Board/Card/CardFooter.tsx @@ -110,7 +110,7 @@ const CardFooter = React.memo( const [countVotes, setCountVotes] = useState(0); - const [disableButton, setDisableButton] = useState(false); + const [disableVoteButton, setDisableVoteButton] = useState(false); const firstUpdate = useRef(true); useEffect(() => { @@ -141,7 +141,7 @@ const CardFooter = React.memo( event.stopPropagation(); if (hideCards && card.createdBy?._id !== userId) return; if (user && user.votesCount + countVotes <= 0) return; - setDisableButton(true); + setDisableVoteButton(true); setCountVotes(countVotes - 1); }; @@ -151,12 +151,12 @@ const CardFooter = React.memo( if (maxVotes && user && user.votesCount >= maxVotes) return; if (maxVotes && user && user.votesCount + countVotes >= maxVotes) return; - setDisableButton(true); + setDisableVoteButton(true); setCountVotes(countVotes + 1); }; useEffect(() => { - setDisableButton(false); + setDisableVoteButton(false); }, [card]); return ( @@ -197,7 +197,7 @@ const CardFooter = React.memo( > = maxVotes) @@ -227,7 +227,7 @@ const CardFooter = React.memo( >