From 8d0e34c5a94ec351ae22429fcc962112a85d7c19 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 29 Jun 2020 20:51:21 +0300 Subject: refactor!: improve code quality :recycle: --- src/components/UploadImage/UploadImage.tsx | 16 ++++--- src/pages/FeedPage/PollSubmission.tsx | 44 ++++++++------------ src/pages/FeedPage/PollSubmissionImage.tsx | 67 +++++++++++++++++------------- src/pages/ProfilePage/ProfileInfo.tsx | 2 +- 4 files changed, 62 insertions(+), 67 deletions(-) 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 = ({ - display, isOpen, callback -}) => { +const UploadImage: React.FC = ({ 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) => { @@ -33,8 +31,8 @@ const UploadImage: React.FC = ({ return (
- - Upload an Image + + Upload an Image Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image. 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 = ({ user, polls, setPolls }) => { return ( - + {}} /> - +
- +
-
diff --git a/src/pages/FeedPage/PollSubmissionImage.tsx b/src/pages/FeedPage/PollSubmissionImage.tsx index 2dadbee..757083b 100644 --- a/src/pages/FeedPage/PollSubmissionImage.tsx +++ b/src/pages/FeedPage/PollSubmissionImage.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import CloudUploadIcon from '@material-ui/icons/CloudUpload'; -import { CardActionArea, CardMedia } from '@material-ui/core'; +import { CardActionArea, CardMedia, Typography } from '@material-ui/core'; import UploadImage from '../../components/UploadImage/UploadImage'; import { Contents } from './types'; import CancelOutlinedIcon from '@material-ui/icons/CancelOutlined'; @@ -13,24 +13,29 @@ interface PropTypes { } const useStyles = makeStyles(theme => ({ - images: { - height: theme.spacing(50), - width: 300, + root: { display: 'flex', justifyContent: 'center', - alignItems: 'center', - cursor: 'pointer', - boxShadow: 'inset 0 0 10px;' + flexDirection: 'column', + alignItems: 'center' }, clearIcon: { opacity: '.5', - fontSize: 100 + fontSize: 50 + }, + media: { + height: '100%', + width: '100%', + display: 'flex', + justifyContent: 'center', + alignItems: 'center' } })); + const PollSubmissionImage: React.FC = ({ setContents, which, contents }) => { const classes = useStyles(); - const [display, setDisplay] = useState(false); + const [isModalOpen, setIsModalOpen] = useState(false); const [image, setImage] = useState(''); const [clearIconDisplay, setClearIconDisplay] = useState(false); @@ -41,9 +46,7 @@ const PollSubmissionImage: React.FC = ({ setContents, which, contents }; const handleClick = () => { - image === '' - ? setDisplay(!display) - : patchUrl(''); + image ? patchUrl('') : setIsModalOpen(!isModalOpen); }; const handleMouseEnter = () => { @@ -54,27 +57,31 @@ const PollSubmissionImage: React.FC = ({ setContents, which, contents setClearIconDisplay(false); }; - return ( + + const Upload = ( <> - - - { - image === '' - ? - : clearIconDisplay - ? - : null - } - - - + + Upload an image + ); + + const Media = ( + + {clearIconDisplay && } + + ) + + return ( + + {image ? Media : Upload} + + ); }; export default PollSubmissionImage; diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx index ec6c387..9fe5912 100644 --- a/src/pages/ProfilePage/ProfileInfo.tsx +++ b/src/pages/ProfilePage/ProfileInfo.tsx @@ -121,7 +121,7 @@ const ProfileInfo: React.FC = ({
- + ) : -- cgit v1.2.3