diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-09-12 01:37:46 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-09-12 01:37:46 +0300 |
commit | 9f6aa186dec2f77753f713ec2f534f83ce2c49ca (patch) | |
tree | 87c48171cf2c0d0a86293cb4e1e90b851a3d5300 /src/components/PollCard | |
parent | 319e7fc67dd4329606b09dca1cb78ea132b1264a (diff) | |
download | which-ui-9f6aa186dec2f77753f713ec2f534f83ce2c49ca.tar.gz |
delete separation of single and double click
Diffstat (limited to 'src/components/PollCard')
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index 56f5dbd..540679f 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -51,10 +51,8 @@ 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: ReturnType<typeof setTimeout>; - let prevent = false; - const handleVote = (which: Which) => { + const handleVote = (which: Which) => () => { if (!isAuthenticated) { enqueueSnackbar('Unauthorized users can not vote in polls', { variant: 'error' @@ -79,19 +77,6 @@ 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; @@ -109,11 +94,11 @@ const PollCard: React.FC<PropTypes> = React.memo(({ poll, setPoll }) => { <Card elevation={3}> <UserStrip user={author} info={date} /> <div className={classes.media}> - <CardActionArea onClick={handleClick('left')} className={classes.media}> + <CardActionArea onDoubleClick={handleVote('left')} className={classes.media}> <BackgroundImage src={left.url} /> <PercentageBar value={leftPercentage} which="left" like={vote?.which === 'left'} /> </CardActionArea> - <CardActionArea onClick={handleClick('right')} className={classes.media}> + <CardActionArea onDoubleClick={handleVote('right')} className={classes.media}> <BackgroundImage src={right.url} /> <PercentageBar value={rightPercentage} which="right" like={vote?.which === 'right'} /> </CardActionArea> |