diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-06-29 22:10:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-29 22:10:04 +0300 |
commit | 98c5a70c17416e470544a4b597461771d5a36325 (patch) | |
tree | 10ca1c1f4dd342eaca3ff1aa7698c54ae1e0f10f /src/pages/FeedPage/PollSubmissionImage.tsx | |
parent | 699c702ca941c0e7e5fdcb971c9135e28b80c221 (diff) | |
parent | aed13f230d2673a489aec455e48d6edbb503e001 (diff) | |
download | which-ui-98c5a70c17416e470544a4b597461771d5a36325.tar.gz |
Merge pull request #52 from which-ecosystem/pollSubmission
feat: add poll submission component
Diffstat (limited to 'src/pages/FeedPage/PollSubmissionImage.tsx')
-rw-r--r-- | src/pages/FeedPage/PollSubmissionImage.tsx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/pages/FeedPage/PollSubmissionImage.tsx b/src/pages/FeedPage/PollSubmissionImage.tsx new file mode 100644 index 0000000..1e9fa0e --- /dev/null +++ b/src/pages/FeedPage/PollSubmissionImage.tsx @@ -0,0 +1,80 @@ +import React, { useState } from 'react'; +import { makeStyles } from '@material-ui/core/styles'; +import CloudUploadIcon from '@material-ui/icons/CloudUpload'; +import { CardActionArea, CardMedia, Typography } from '@material-ui/core'; +import CancelOutlinedIcon from '@material-ui/icons/CancelOutlined'; + +import UploadImage from '../../components/UploadImage/UploadImage'; + +interface PropTypes { + url: string; + setUrl: (url: string) => void; +} + +const useStyles = makeStyles({ + root: { + display: 'flex', + justifyContent: 'center', + flexDirection: 'column', + alignItems: 'center' + }, + clearIcon: { + opacity: '.5', + fontSize: 50 + }, + media: { + height: '100%', + width: '100%', + display: 'flex', + justifyContent: 'center', + alignItems: 'center' + } +}); + + +const PollSubmissionImage: React.FC<PropTypes> = ({ url, setUrl }) => { + const classes = useStyles(); + const [isModalOpen, setIsModalOpen] = useState(false); + const [isMediaHover, setIsMediaHover] = useState(false); + + const handleClick = (): void => { + if (url) setUrl(''); + else setIsModalOpen(!isModalOpen); + }; + + const handleMouseEnter = (): void => { + setIsMediaHover(true); + }; + + const handleMouseLeave = (): void => { + setIsMediaHover(false); + }; + + + const Upload = ( + <> + <CloudUploadIcon fontSize="large" color="primary" /> + <Typography variant="h5"> Upload an image </Typography> + <UploadImage isOpen={isModalOpen} setIsOpen={setIsModalOpen} callback={setUrl} /> + </> + ); + + const Media = ( + <CardMedia + image={url} + className={classes.media} + onMouseEnter={handleMouseEnter} + onMouseLeave={handleMouseLeave} + > + {isMediaHover && <CancelOutlinedIcon className={classes.clearIcon} />} + </CardMedia> + ); + + return ( + <CardActionArea onClick={handleClick} className={classes.root}> + {url ? Media : Upload} + </CardActionArea> + ); +}; + +export default PollSubmissionImage; |