diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-29 17:31:51 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-29 17:31:51 +0300 |
commit | 856522da17348e54b0d390f10772c21b4029e9bd (patch) | |
tree | e3642a46d926b6dc4ceae041083112492486c410 /src/pages/FeedPage | |
parent | 0852cbeea6a3872c4a3a4b7dd974db53eb0a85dd (diff) | |
download | which-ui-856522da17348e54b0d390f10772c21b4029e9bd.tar.gz |
fix: make code redably clear
Diffstat (limited to 'src/pages/FeedPage')
-rw-r--r-- | src/pages/FeedPage/FeedPage.tsx | 2 | ||||
-rw-r--r-- | src/pages/FeedPage/PollSubmission.tsx | 14 | ||||
-rw-r--r-- | src/pages/FeedPage/PollSubmissionImage.tsx | 34 |
3 files changed, 27 insertions, 23 deletions
diff --git a/src/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx index a7bbbbd..329647e 100644 --- a/src/pages/FeedPage/FeedPage.tsx +++ b/src/pages/FeedPage/FeedPage.tsx @@ -22,7 +22,7 @@ const FeedPage: React.FC<PropTypes> = ({ navigate, user }) => { return ( <> - {user && <PollSubmission user={user} polls={polls} setPolls={setPolls}/>} + {user && <PollSubmission user={user} polls={polls} setPolls={setPolls} />} <Feed polls={polls} navigate={navigate} /> </> ); 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' } diff --git a/src/pages/FeedPage/PollSubmissionImage.tsx b/src/pages/FeedPage/PollSubmissionImage.tsx index 42389f6..e29ecd0 100644 --- a/src/pages/FeedPage/PollSubmissionImage.tsx +++ b/src/pages/FeedPage/PollSubmissionImage.tsx @@ -2,13 +2,13 @@ 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 ClearIcon from '@material-ui/icons/Clear'; import UploadImage from '../../components/UploadImage/UploadImage'; import { Contents } from './types'; -import ClearIcon from '@material-ui/icons/Clear'; interface PropTypes { contents: Contents; - setContents: (a: Contents) => void; + setContents: (newContents: Contents) => void; which: 'left' | 'right'; } @@ -34,17 +34,16 @@ const PollSubmissionImage: React.FC<PropTypes> = ({ setContents, which, contents const [image, setImage] = useState(''); const [clearIconDisplay, setClearIconDisplay] = useState(false); + const patchUrl = (url: string) => { + setImage(url); + contents[which] = { url } ; + setContents({ ...contents }); + }; + const handleClick = () => { image === '' ? setDisplay(!display) : patchUrl(''); - - }; - - const patchUrl = (url: string) => { - setImage(url); - contents[which] = {url}; - setContents({...contents}); }; const handleMouseEnter = () => { @@ -57,18 +56,23 @@ const PollSubmissionImage: React.FC<PropTypes> = ({ setContents, which, contents return ( <> - <CardActionArea onClick={handleClick} > - <CardMedia className={classes.images} image={image} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}> + <CardActionArea onClick={handleClick}> + <CardMedia + className={classes.images} + image={image} + onMouseEnter={handleMouseEnter} + onMouseLeave={handleMouseLeave} + > { image === '' - ? <CloudUploadIcon fontSize='large' color='primary' /> + ? <CloudUploadIcon fontSize="large" color="primary" /> : clearIconDisplay - ? <ClearIcon className={classes.clearIcon} color='primary'/> - : null + ? <ClearIcon className={classes.clearIcon} color="primary" /> + : null } </CardMedia> </CardActionArea> - <UploadImage displayD={display} setDisplayD={setDisplay} callback={patchUrl} /> + <UploadImage display={display} isOpen={setDisplay} callback={patchUrl} /> </> ); }; |