aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/PollCard/PollCard.tsx26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx
index 80a1386..87d9fae 100644
--- a/src/components/PollCard/PollCard.tsx
+++ b/src/components/PollCard/PollCard.tsx
@@ -51,6 +51,25 @@ 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 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) {
@@ -77,9 +96,6 @@ const PollCard: React.FC<PropTypes> = React.memo(({ poll, setPoll }) => {
}
};
- const handleLeft = () => handleVote('left');
- const handleRight = () => handleVote('right');
-
let leftPercentage;
let rightPercentage;
@@ -97,11 +113,11 @@ const PollCard: React.FC<PropTypes> = React.memo(({ poll, setPoll }) => {
<Card elevation={3}>
<UserStrip user={author} info={date} />
<div className={classes.media}>
- <CardActionArea onDoubleClick={handleLeft} className={classes.media}>
+ <CardActionArea onClick={handleClick('left')} className={classes.media}>
<BackgroundImage src={left.url} />
<PercentageBar value={leftPercentage} which="left" like={vote?.which === 'left'} />
</CardActionArea>
- <CardActionArea onDoubleClick={handleRight} className={classes.media}>
+ <CardActionArea onClick={handleClick('right')} className={classes.media}>
<BackgroundImage src={right.url} />
<PercentageBar value={rightPercentage} which="right" like={vote?.which === 'right'} />
</CardActionArea>