diff options
Diffstat (limited to 'src/components/PollCard')
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index 87d9fae..56f5dbd 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -51,26 +51,9 @@ const PollCard: React.FC<PropTypes> = React.memo(({ poll, setPoll }) => { const { enqueueSnackbar } = useSnackbar(); const { isAuthenticated } = useAuth(); const date: string = new Date(poll.createdAt).toLocaleString('default', DATE_FORMAT); - let timer: any; - let delay = 200; + let timer: ReturnType<typeof setTimeout>; let prevent = false; - const handleClick = (which: Which) => () => { - if(!prevent) { - prevent = true; - timer = setTimeout(() => { - console.log('single click', prevent); - prevent = false; - }, delay) - } - else { - clearTimeout(timer); - prevent = false; - console.log('double click', prevent); - handleVote(which); - } - }; - const handleVote = (which: Which) => { if (!isAuthenticated) { enqueueSnackbar('Unauthorized users can not vote in polls', { @@ -96,6 +79,19 @@ const PollCard: React.FC<PropTypes> = React.memo(({ poll, setPoll }) => { } }; + const handleClick = (which: Which) => () => { + if (!prevent) { + prevent = true; + timer = setTimeout(() => { + prevent = false; + }, 200); + } else { + clearTimeout(timer); + prevent = false; + handleVote(which); + } + }; + let leftPercentage; let rightPercentage; |