From 856522da17348e54b0d390f10772c21b4029e9bd Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Mon, 29 Jun 2020 17:31:51 +0300 Subject: fix: make code redably clear --- src/pages/FeedPage/PollSubmissionImage.tsx | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/pages/FeedPage/PollSubmissionImage.tsx') 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 = ({ 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 = ({ setContents, which, contents return ( <> - - + + { image === '' - ? + ? : clearIconDisplay - ? - : null + ? + : null } - + ); }; -- cgit v1.2.3