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/components/UploadImage/UploadImage.tsx | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

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

diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx
index 42ee989..464a9cf 100644
--- a/src/components/UploadImage/UploadImage.tsx
+++ b/src/components/UploadImage/UploadImage.tsx
@@ -1,4 +1,4 @@
-import React, { useRef } from 'react';
+import React, { useRef, useState } from 'react';
 import Button from '@material-ui/core/Button';
 import TextField from '@material-ui/core/TextField';
 import Dialog from '@material-ui/core/Dialog';
@@ -6,35 +6,32 @@ import DialogActions from '@material-ui/core/DialogActions';
 import DialogContent from '@material-ui/core/DialogContent';
 import DialogContentText from '@material-ui/core/DialogContentText';
 import DialogTitle from '@material-ui/core/DialogTitle';
-import { User } from 'which-types';
-import { patch } from '../../requests';
 
 interface PropTypes {
   displayD: boolean;
   setDisplayD: (d: boolean) => void;
-  setUserInfo: (a: User) => void;
-  setUser: (a: User) => void
+  callback: (a: string) => void;
 }
 
 const UploadImage: React.FC<PropTypes> = ({
-  displayD, setDisplayD, setUserInfo, setUser
+  displayD, setDisplayD, callback
 }) => {
-  const urlRef = useRef<HTMLInputElement>(null);
+  const urlRef = useRef<HTMLInputElement | null>(null);
+  const [url, setUrl] = useState('');
 
   const handleClose = () => {
     setDisplayD(false);
   };
 
-  const updateAvatar = () => {
-    const id = localStorage.getItem('userId');
-    const newAvatar = urlRef.current?.value;
-    patch(`/users/${id}`, { avatarUrl: newAvatar }).then(res => {
-      setUserInfo(res.data);
-      setUser(res.data);
-    });
+  const update = () => {
+    callback(urlRef.current?.value || '');
     setDisplayD(false);
   };
 
+  const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
+    setUrl(event.target.value);
+  };
+
   return (
     <div>
       <Dialog open={displayD} onClose={handleClose}>
@@ -52,13 +49,14 @@ const UploadImage: React.FC<PropTypes> = ({
             fullWidth
             autoComplete="off"
             inputRef={urlRef}
+            onChange={handleChange}
           />
         </DialogContent>
         <DialogActions>
           <Button onClick={handleClose} color="primary">
             Cancel
           </Button>
-          <Button onClick={updateAvatar} color="primary">
+          <Button onClick={update} color="primary" disabled={!url.length}>
             Submit
           </Button>
         </DialogActions>
-- 
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/components/UploadImage/UploadImage.tsx | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

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

diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx
index 464a9cf..3a58e29 100644
--- a/src/components/UploadImage/UploadImage.tsx
+++ b/src/components/UploadImage/UploadImage.tsx
@@ -1,4 +1,4 @@
-import React, { useRef, useState } from 'react';
+import React, { useState } from 'react';
 import Button from '@material-ui/core/Button';
 import TextField from '@material-ui/core/TextField';
 import Dialog from '@material-ui/core/Dialog';
@@ -8,24 +8,23 @@ import DialogContentText from '@material-ui/core/DialogContentText';
 import DialogTitle from '@material-ui/core/DialogTitle';
 
 interface PropTypes {
-  displayD: boolean;
-  setDisplayD: (d: boolean) => void;
-  callback: (a: string) => void;
+  display: boolean;
+  isOpen: (display: boolean) => void;
+  callback: (url: string) => void;
 }
 
 const UploadImage: React.FC<PropTypes> = ({
-  displayD, setDisplayD, callback
+  display, isOpen, callback
 }) => {
-  const urlRef = useRef<HTMLInputElement | null>(null);
   const [url, setUrl] = useState('');
 
   const handleClose = () => {
-    setDisplayD(false);
+    isOpen(false);
   };
 
-  const update = () => {
-    callback(urlRef.current?.value || '');
-    setDisplayD(false);
+  const handleSubmit = () => {
+    callback(url || '');
+    isOpen(false);
   };
 
   const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
@@ -34,7 +33,7 @@ const UploadImage: React.FC<PropTypes> = ({
 
   return (
     <div>
-      <Dialog open={displayD} onClose={handleClose}>
+      <Dialog open={display} onClose={handleClose}>
         <DialogTitle id="form-dialog-title">Upload an Image</DialogTitle>
         <DialogContent>
           <DialogContentText>
@@ -48,7 +47,6 @@ const UploadImage: React.FC<PropTypes> = ({
             type="text"
             fullWidth
             autoComplete="off"
-            inputRef={urlRef}
             onChange={handleChange}
           />
         </DialogContent>
@@ -56,7 +54,7 @@ const UploadImage: React.FC<PropTypes> = ({
           <Button onClick={handleClose} color="primary">
             Cancel
           </Button>
-          <Button onClick={update} color="primary" disabled={!url.length}>
+          <Button onClick={handleSubmit} color="primary" disabled={!url.length}>
             Submit
           </Button>
         </DialogActions>
-- 
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/components/UploadImage/UploadImage.tsx | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

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

diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx
index 3a58e29..e6f6d05 100644
--- a/src/components/UploadImage/UploadImage.tsx
+++ b/src/components/UploadImage/UploadImage.tsx
@@ -8,23 +8,21 @@ import DialogContentText from '@material-ui/core/DialogContentText';
 import DialogTitle from '@material-ui/core/DialogTitle';
 
 interface PropTypes {
-  display: boolean;
-  isOpen: (display: boolean) => void;
+  isOpen: boolean;
+  setIsOpen: (value: boolean) => void;
   callback: (url: string) => void;
 }
 
-const UploadImage: React.FC<PropTypes> = ({
-  display, isOpen, callback
-}) => {
+const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
   const [url, setUrl] = useState('');
 
   const handleClose = () => {
-    isOpen(false);
+    setIsOpen(false);
   };
 
   const handleSubmit = () => {
     callback(url || '');
-    isOpen(false);
+    setIsOpen(false);
   };
 
   const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
@@ -33,8 +31,8 @@ const UploadImage: React.FC<PropTypes> = ({
 
   return (
     <div>
-      <Dialog open={display} onClose={handleClose}>
-        <DialogTitle id="form-dialog-title">Upload an Image</DialogTitle>
+      <Dialog open={isOpen} onClose={handleClose}>
+        <DialogTitle>Upload an Image</DialogTitle>
         <DialogContent>
           <DialogContentText>
             Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image.
-- 
cgit v1.2.3

