diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-10 00:28:39 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-10 00:28:39 +0300 |
commit | 7ba15a22d1bd57e7c26ff2d5fccf5505aaf8619e (patch) | |
tree | 8a71d8dd4bf89f09f14aee2636f519572e95f891 /src/pages/FeedPage/PollSubmission.tsx | |
parent | dfa6f0a8d1415539e1ff6a3ca848627bbe87b470 (diff) | |
download | which-ui-7ba15a22d1bd57e7c26ff2d5fccf5505aaf8619e.tar.gz |
refactor: move pages -> containers
Diffstat (limited to 'src/pages/FeedPage/PollSubmission.tsx')
-rw-r--r-- | src/pages/FeedPage/PollSubmission.tsx | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx deleted file mode 100644 index 347eecc..0000000 --- a/src/pages/FeedPage/PollSubmission.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import React, { useState } from 'react'; -import { makeStyles } from '@material-ui/core/styles'; -import Collapse from '@material-ui/core/Collapse'; -import { - Button, - Card, - ClickAwayListener, - Divider -} from '@material-ui/core'; -import { Poll, Which } from 'which-types'; -import { useSnackbar } from 'notistack'; -import PollSubmissionImage from './PollSubmissionImage'; -import UserStrip from '../../components/UserStrip/UserStrip'; -import { post } from '../../requests'; -import { Contents } from './types'; -import { useAuth } from '../../hooks/useAuth'; - -interface PropTypes{ - addPoll: (poll: Poll) => void; -} - -const useStyles = makeStyles(theme => ({ - root: { - marginBottom: theme.spacing(4) - }, - images: { - height: theme.spacing(50), - display: 'flex' - } -})); - -const emptyContents: Contents = { - left: { url: '' }, - right: { url: '' } -}; - -const PollSubmission: React.FC<PropTypes> = ({ addPoll }) => { - const classes = useStyles(); - const [expanded, setExpanded] = useState(false); - const [contents, setContents] = useState<Contents>(emptyContents); - const { enqueueSnackbar } = useSnackbar(); - const { user } = useAuth(); - - const readyToSubmit = contents.left.url && contents.right.url; - - const setUrl = (which: Which) => (url: string): void => { - setContents({ ...contents, [which]: { url } }); - }; - - const handleClickAway = () => { - setExpanded(false); - }; - - const handleClick = () => { - if (expanded && readyToSubmit) { - post('/polls/', { contents }).then(response => { - addPoll(response.data); - enqueueSnackbar('Your poll has been successfully created!', { - variant: 'success' - }); - }); - setContents({ ...emptyContents }); - } - setExpanded(!expanded); - }; - - return ( - <ClickAwayListener onClickAway={handleClickAway}> - <Card className={classes.root}> - <Collapse in={expanded} timeout="auto" unmountOnExit> - {user && <UserStrip user={user} info="" />} - <Divider /> - <div className={classes.images}> - <PollSubmissionImage url={contents.left.url} setUrl={setUrl('left')} /> - <PollSubmissionImage url={contents.right.url} setUrl={setUrl('right')} /> - </div> - </Collapse> - <Button - color="primary" - disabled={expanded && !readyToSubmit} - variant={expanded ? 'contained' : 'outlined'} - onClick={handleClick} - fullWidth - > - {expanded ? 'Submit' : 'Create a Poll'} - </Button> - </Card> - </ClickAwayListener> - ); -}; - -export default PollSubmission; |