From a03127a0a29c6896643d6043afb5fcd0d3407f7b Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Thu, 3 Sep 2020 12:42:36 +0300
Subject: feat: add separation function of single and double clicks

---
 src/components/PollCard/PollCard.tsx | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

(limited to 'src/components/PollCard/PollCard.tsx')

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>
-- 
cgit v1.2.3


From 319e7fc67dd4329606b09dca1cb78ea132b1264a Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Fri, 11 Sep 2020 02:11:54 +0300
Subject: fix eslint errors

---
 src/components/PollCard/PollCard.tsx | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

(limited to 'src/components/PollCard/PollCard.tsx')

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;
 
-- 
cgit v1.2.3


From 9f6aa186dec2f77753f713ec2f534f83ce2c49ca Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Sat, 12 Sep 2020 01:37:46 +0300
Subject: delete separation of single and double click

---
 src/components/PollCard/PollCard.tsx | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

(limited to 'src/components/PollCard/PollCard.tsx')

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>
-- 
cgit v1.2.3

