From 7ad127942bb12ee9de691e10dc9386849459ea46 Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Sun, 28 Jun 2020 19:09:20 +0300
Subject: feat: add poll submission component

---
 src/pages/FeedPage/PollSubmission.tsx | 87 +++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 src/pages/FeedPage/PollSubmission.tsx

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
new file mode 100644
index 0000000..c76e9fb
--- /dev/null
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -0,0 +1,87 @@
+import React, { useState } from 'react';
+import { makeStyles } from '@material-ui/core/styles';
+import Collapse from '@material-ui/core/Collapse';
+import {
+  Button, Card, CardMedia, ClickAwayListener, Divider
+} from '@material-ui/core';
+import { User } from 'which-types';
+import PollSubmissionImage from './PollSubmissionImage';
+import UserStrip from '../../components/UserStrip/UserStrip';
+import { post } from '../../requests';
+import { Contents } from './types';
+
+
+interface PropTypes{
+  user: User;
+}
+const useStyles = makeStyles(theme => ({
+  root: {
+    textAlign: 'center',
+    cursor: 'pointer'
+  },
+  card: {
+    height: 400,
+    display: 'flex'
+  },
+  images: {
+    height: theme.spacing(50),
+    width: 300,
+    display: 'flex',
+    justifyContent: 'center',
+    alignItems: 'center',
+    cursor: 'pointer'
+  },
+  button: {
+    width: '100%'
+  }
+}));
+
+const PollSubmission: React.FC<PropTypes> = ({ user }) => {
+  const classes = useStyles();
+  const [expanded, setExpanded] = useState(false);
+  const [contents, setContents] = useState<Contents>({
+    left: {
+      url: ''
+    },
+    right: {
+      url: ''
+    }
+  });
+
+  const handleClickAway = () => {
+    setExpanded(false);
+  };
+
+  const handleClick = () => {
+    if (expanded) {
+      post('/polls/', { authorId: user._id, contents }).then(res => {
+        console.log(res.data);
+      });
+    }
+    setExpanded(!expanded);
+  };
+
+  return (
+    <ClickAwayListener onClickAway={handleClickAway}>
+      <Card className={classes.root}>
+        <Collapse in={expanded} timeout="auto" unmountOnExit>
+          <UserStrip user={user} info="" navigate={() => {}} />
+          <Divider />
+          <CardMedia className={classes.card}>
+            <PollSubmissionImage which="left" setContents={setContents} />
+            <PollSubmissionImage which="right" setContents={setContents} />
+          </CardMedia>
+        </Collapse>
+        <Button onClick={handleClick} color="primary" variant="outlined" className={classes.button}>
+          {
+          expanded === false
+            ? 'Create a Poll'
+            : 'Submit'
+        }
+        </Button>
+      </Card>
+    </ClickAwayListener>
+  );
+};
+
+export default PollSubmission;
-- 
cgit v1.2.3


From 28c80d1c2e33706a3a754b3e5e26dc2685cf8592 Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Sun, 28 Jun 2020 19:32:48 +0300
Subject: fix: able to add 2 different images to poll submission

---
 src/pages/FeedPage/PollSubmission.tsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index c76e9fb..40ca3d7 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -68,8 +68,8 @@ const PollSubmission: React.FC<PropTypes> = ({ user }) => {
           <UserStrip user={user} info="" navigate={() => {}} />
           <Divider />
           <CardMedia className={classes.card}>
-            <PollSubmissionImage which="left" setContents={setContents} />
-            <PollSubmissionImage which="right" setContents={setContents} />
+            <PollSubmissionImage which="left" setContents={setContents} contents={contents}/>
+            <PollSubmissionImage which="right" setContents={setContents} contents={contents}/>
           </CardMedia>
         </Collapse>
         <Button onClick={handleClick} color="primary" variant="outlined" className={classes.button}>
-- 
cgit v1.2.3


From 37d3d4ca801ab282104ed41d97e10911e288947a Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Mon, 29 Jun 2020 04:09:40 +0300
Subject: delete images in poll submission

---
 src/pages/FeedPage/PollSubmission.tsx | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 40ca3d7..9a3a042 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -54,9 +54,11 @@ const PollSubmission: React.FC<PropTypes> = ({ user }) => {
 
   const handleClick = () => {
     if (expanded) {
-      post('/polls/', { authorId: user._id, contents }).then(res => {
-        console.log(res.data);
-      });
+      if(contents.left?.url && contents.right?.url ) {
+        post('/polls/', {authorId: user._id, contents}).then(res => {
+          console.log(res.data);
+        });
+      }
     }
     setExpanded(!expanded);
   };
-- 
cgit v1.2.3


From 0852cbeea6a3872c4a3a4b7dd974db53eb0a85dd Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Mon, 29 Jun 2020 15:35:34 +0300
Subject: show new poll right after submit

---
 src/pages/FeedPage/PollSubmission.tsx | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 9a3a042..65e33b6 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -4,7 +4,7 @@ import Collapse from '@material-ui/core/Collapse';
 import {
   Button, Card, CardMedia, ClickAwayListener, Divider
 } from '@material-ui/core';
-import { User } from 'which-types';
+import { User, Poll } from 'which-types';
 import PollSubmissionImage from './PollSubmissionImage';
 import UserStrip from '../../components/UserStrip/UserStrip';
 import { post } from '../../requests';
@@ -13,6 +13,8 @@ import { Contents } from './types';
 
 interface PropTypes{
   user: User;
+  polls: Poll[];
+  setPolls: (a:Poll[])=> void;
 }
 const useStyles = makeStyles(theme => ({
   root: {
@@ -36,7 +38,7 @@ const useStyles = makeStyles(theme => ({
   }
 }));
 
-const PollSubmission: React.FC<PropTypes> = ({ user }) => {
+const PollSubmission: React.FC<PropTypes> = ({ user , polls, setPolls}) => {
   const classes = useStyles();
   const [expanded, setExpanded] = useState(false);
   const [contents, setContents] = useState<Contents>({
@@ -54,9 +56,10 @@ const PollSubmission: React.FC<PropTypes> = ({ user }) => {
 
   const handleClick = () => {
     if (expanded) {
-      if(contents.left?.url && contents.right?.url ) {
+      if(contents.left.url && contents.right.url ) {
         post('/polls/', {authorId: user._id, contents}).then(res => {
-          console.log(res.data);
+          polls.unshift({...res.data});
+          setPolls([...polls]);
         });
       }
     }
-- 
cgit v1.2.3


From 856522da17348e54b0d390f10772c21b4029e9bd Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Mon, 29 Jun 2020 17:31:51 +0300
Subject: fix: make code redably clear

---
 src/pages/FeedPage/PollSubmission.tsx | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 65e33b6..3a73d45 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -38,7 +38,7 @@ const useStyles = makeStyles(theme => ({
   }
 }));
 
-const PollSubmission: React.FC<PropTypes> = ({ user , polls, setPolls}) => {
+const PollSubmission: React.FC<PropTypes> = ({ user, polls, setPolls }) => {
   const classes = useStyles();
   const [expanded, setExpanded] = useState(false);
   const [contents, setContents] = useState<Contents>({
@@ -56,9 +56,9 @@ const PollSubmission: React.FC<PropTypes> = ({ user , polls, setPolls}) => {
 
   const handleClick = () => {
     if (expanded) {
-      if(contents.left.url && contents.right.url ) {
-        post('/polls/', {authorId: user._id, contents}).then(res => {
-          polls.unshift({...res.data});
+      if (contents.left.url && contents.right.url) {
+        post('/polls/', { authorId: user._id, contents }).then(res => {
+          polls.unshift({ ...res.data });
           setPolls([...polls]);
         });
       }
@@ -73,13 +73,13 @@ const PollSubmission: React.FC<PropTypes> = ({ user , polls, setPolls}) => {
           <UserStrip user={user} info="" navigate={() => {}} />
           <Divider />
           <CardMedia className={classes.card}>
-            <PollSubmissionImage which="left" setContents={setContents} contents={contents}/>
-            <PollSubmissionImage which="right" setContents={setContents} contents={contents}/>
+            <PollSubmissionImage which="left" setContents={setContents} contents={contents} />
+            <PollSubmissionImage which="right" setContents={setContents} contents={contents} />
           </CardMedia>
         </Collapse>
         <Button onClick={handleClick} color="primary" variant="outlined" className={classes.button}>
           {
-          expanded === false
+          !expanded
             ? 'Create a Poll'
             : 'Submit'
         }
-- 
cgit v1.2.3


From b0a5c3d78d207a8bec15a7989c81384ee52c94a5 Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Mon, 29 Jun 2020 17:42:29 +0300
Subject: chage clearIcon design

---
 src/pages/FeedPage/PollSubmission.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 3a73d45..56c4242 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -77,7 +77,7 @@ const PollSubmission: React.FC<PropTypes> = ({ user, polls, setPolls }) => {
             <PollSubmissionImage which="right" setContents={setContents} contents={contents} />
           </CardMedia>
         </Collapse>
-        <Button onClick={handleClick} color="primary" variant="outlined" className={classes.button}>
+        <Button onClick={handleClick} color="primary" variant={expanded ? "contained" : "outlined" } className={classes.button}>
           {
           !expanded
             ? 'Create a Poll'
-- 
cgit v1.2.3


From 8d0e34c5a94ec351ae22429fcc962112a85d7c19 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 29 Jun 2020 20:51:21 +0300
Subject: refactor!: improve code quality :recycle:

---
 src/pages/FeedPage/PollSubmission.tsx | 44 ++++++++++++++---------------------
 1 file changed, 17 insertions(+), 27 deletions(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 56c4242..38f70c3 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -2,7 +2,10 @@ import React, { useState } from 'react';
 import { makeStyles } from '@material-ui/core/styles';
 import Collapse from '@material-ui/core/Collapse';
 import {
-  Button, Card, CardMedia, ClickAwayListener, Divider
+  Button,
+  Card,
+  ClickAwayListener,
+  Divider
 } from '@material-ui/core';
 import { User, Poll } from 'which-types';
 import PollSubmissionImage from './PollSubmissionImage';
@@ -14,27 +17,12 @@ import { Contents } from './types';
 interface PropTypes{
   user: User;
   polls: Poll[];
-  setPolls: (a:Poll[])=> void;
+  setPolls: (newPoll: Poll[])=> void;
 }
 const useStyles = makeStyles(theme => ({
   root: {
-    textAlign: 'center',
-    cursor: 'pointer'
-  },
-  card: {
-    height: 400,
-    display: 'flex'
-  },
-  images: {
     height: theme.spacing(50),
-    width: 300,
-    display: 'flex',
-    justifyContent: 'center',
-    alignItems: 'center',
-    cursor: 'pointer'
-  },
-  button: {
-    width: '100%'
+    display: 'flex'
   }
 }));
 
@@ -68,21 +56,23 @@ const PollSubmission: React.FC<PropTypes> = ({ user, polls, setPolls }) => {
 
   return (
     <ClickAwayListener onClickAway={handleClickAway}>
-      <Card className={classes.root}>
+      <Card>
         <Collapse in={expanded} timeout="auto" unmountOnExit>
           <UserStrip user={user} info="" navigate={() => {}} />
           <Divider />
-          <CardMedia className={classes.card}>
+          <div className={classes.root}>
             <PollSubmissionImage which="left" setContents={setContents} contents={contents} />
             <PollSubmissionImage which="right" setContents={setContents} contents={contents} />
-          </CardMedia>
+          </div>
         </Collapse>
-        <Button onClick={handleClick} color="primary" variant={expanded ? "contained" : "outlined" } className={classes.button}>
-          {
-          !expanded
-            ? 'Create a Poll'
-            : 'Submit'
-        }
+        <Button
+          color="primary"
+          disabled={expanded && !(contents.left.url && contents.right.url)}
+          variant={expanded ? "contained" : "outlined"}
+          onClick={handleClick}
+          fullWidth
+        >
+          {expanded ? 'Submit' : 'Create a Poll' }
         </Button>
       </Card>
     </ClickAwayListener>
-- 
cgit v1.2.3


From c68b0e0c3ad72a48ba421dbbc9b70d177f8ecbfc Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 29 Jun 2020 21:34:27 +0300
Subject: style: fix eslint errors

---
 src/pages/FeedPage/PollSubmission.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 38f70c3..9b1ac95 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -68,7 +68,7 @@ const PollSubmission: React.FC<PropTypes> = ({ user, polls, setPolls }) => {
         <Button
           color="primary"
           disabled={expanded && !(contents.left.url && contents.right.url)}
-          variant={expanded ? "contained" : "outlined"}
+          variant={expanded ? 'contained' : 'outlined'}
           onClick={handleClick}
           fullWidth
         >
-- 
cgit v1.2.3


From aed13f230d2673a489aec455e48d6edbb503e001 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 29 Jun 2020 22:03:52 +0300
Subject: refactor: improve poll addition

---
 src/pages/FeedPage/PollSubmission.tsx | 49 ++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 24 deletions(-)

(limited to 'src/pages/FeedPage/PollSubmission.tsx')

diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 9b1ac95..16c8350 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -7,18 +7,17 @@ import {
   ClickAwayListener,
   Divider
 } from '@material-ui/core';
-import { User, Poll } from 'which-types';
+import { User, Poll, Which } from 'which-types';
 import PollSubmissionImage from './PollSubmissionImage';
 import UserStrip from '../../components/UserStrip/UserStrip';
 import { post } from '../../requests';
 import { Contents } from './types';
 
-
 interface PropTypes{
   user: User;
-  polls: Poll[];
-  setPolls: (newPoll: Poll[])=> void;
+  addPoll: (poll: Poll) => void;
 }
+
 const useStyles = makeStyles(theme => ({
   root: {
     height: theme.spacing(50),
@@ -26,30 +25,32 @@ const useStyles = makeStyles(theme => ({
   }
 }));
 
-const PollSubmission: React.FC<PropTypes> = ({ user, polls, setPolls }) => {
+const emptyContents: Contents = {
+  left: { url: '' },
+  right: { url: '' }
+};
+
+const PollSubmission: React.FC<PropTypes> = ({ user, addPoll }) => {
   const classes = useStyles();
   const [expanded, setExpanded] = useState(false);
-  const [contents, setContents] = useState<Contents>({
-    left: {
-      url: ''
-    },
-    right: {
-      url: ''
-    }
-  });
+  const [contents, setContents] = useState<Contents>(emptyContents);
+
+  const readyToSubmit = contents.left.url && contents.right.url;
+
+  const setUrl = (which: Which) => (url: string): void => {
+    setContents({ ...contents, [which]: { url } });
+  };
 
   const handleClickAway = () => {
     setExpanded(false);
   };
 
   const handleClick = () => {
-    if (expanded) {
-      if (contents.left.url && contents.right.url) {
-        post('/polls/', { authorId: user._id, contents }).then(res => {
-          polls.unshift({ ...res.data });
-          setPolls([...polls]);
-        });
-      }
+    if (expanded && readyToSubmit) {
+      post('/polls/', { authorId: user._id, contents }).then(response => {
+        addPoll(response.data);
+      });
+      setContents({ ...emptyContents });
     }
     setExpanded(!expanded);
   };
@@ -61,18 +62,18 @@ const PollSubmission: React.FC<PropTypes> = ({ user, polls, setPolls }) => {
           <UserStrip user={user} info="" navigate={() => {}} />
           <Divider />
           <div className={classes.root}>
-            <PollSubmissionImage which="left" setContents={setContents} contents={contents} />
-            <PollSubmissionImage which="right" setContents={setContents} contents={contents} />
+            <PollSubmissionImage url={contents.left.url} setUrl={setUrl('left')} />
+            <PollSubmissionImage url={contents.right.url} setUrl={setUrl('right')} />
           </div>
         </Collapse>
         <Button
           color="primary"
-          disabled={expanded && !(contents.left.url && contents.right.url)}
+          disabled={expanded && !readyToSubmit}
           variant={expanded ? 'contained' : 'outlined'}
           onClick={handleClick}
           fullWidth
         >
-          {expanded ? 'Submit' : 'Create a Poll' }
+          {expanded ? 'Submit' : 'Create a Poll'}
         </Button>
       </Card>
     </ClickAwayListener>
-- 
cgit v1.2.3

