diff options
Diffstat (limited to 'src/containers')
-rw-r--r-- | src/containers/Page/Page.tsx | 3 | ||||
-rw-r--r-- | src/containers/PollCreation/PollCreation.tsx | 39 |
2 files changed, 33 insertions, 9 deletions
diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx index e60f7da..9a904a4 100644 --- a/src/containers/Page/Page.tsx +++ b/src/containers/Page/Page.tsx @@ -17,7 +17,8 @@ const useStyles = makeStyles(theme => ({ }, [theme.breakpoints.up('md')]: { padding: theme.spacing(15, 5, 8, 5) - } + }, + backgroundColor: 'whitesmoke' } })); diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index 68f41d2..2e2bd06 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -1,7 +1,7 @@ -import React from 'react'; +import React, { ChangeEvent, useState, useMemo } from 'react'; import Bluebird from 'bluebird'; import { makeStyles } from '@material-ui/core/styles'; -import { Card, Container, LinearProgress } from '@material-ui/core'; +import { Card, Container, LinearProgress, InputBase, Typography } from '@material-ui/core'; import SendIcon from '@material-ui/icons/Send'; import { useSnackbar } from 'notistack'; @@ -19,14 +19,22 @@ const useStyles = makeStyles(theme => ({ images: { height: theme.spacing(50), display: 'flex' + }, + textarea: { + width: '100%', + height: 100 + }, + description: { + padding: theme.spacing(1, 2) } })); const PollCreation: React.FC = () => { + const [description, setDescription] = useState<string>(''); const classes = useStyles(); - const { user } = useAuth(); const { enqueueSnackbar } = useSnackbar(); + const { user } = useAuth(); const { mutate: updateFeed } = useFeed(); const { mutate: updateProfile } = useProfile(user?.username || ''); const { @@ -42,16 +50,19 @@ const PollCreation: React.FC = () => { progress: rightProgress } = useS3Preupload(); + const handleDescriptionChange = (e: ChangeEvent<HTMLTextAreaElement|HTMLInputElement>) => { + setDescription(e.target.value); + }; + const handleSubmit = async () => { try { const [leftUrl, rightUrl] = await Bluebird.all([resolveLeft(), resolveRight()]); - const contents = { left: { url: leftUrl }, right: { url: rightUrl } }; - post('/polls/', { contents }).then(() => { + post('/polls/', { contents, description }).then(() => { updateFeed(); updateProfile(); enqueueSnackbar('Your poll has been successfully created!', { variant: 'success' }); @@ -61,22 +72,34 @@ const PollCreation: React.FC = () => { } }; + const isSubmitting = useMemo(() => leftProgress + rightProgress > 0, [leftProgress, rightProgress]); + return ( <ModalScreen title="Create a poll" actionIcon={<SendIcon />} handleAction={handleSubmit} - isActionDisabled={!(left && right) || leftProgress > 0 || rightProgress > 0} + isActionDisabled={!(left && right) || isSubmitting} > <Container maxWidth="sm" disableGutters> <Card elevation={3}> - {user && <UserStrip user={user} info="" />} + {user && <UserStrip user={user} />} + <Typography> + <InputBase + multiline + fullWidth + placeholder="Add description" + onChange={handleDescriptionChange} + className={classes.description} + readOnly={isSubmitting} + /> + </Typography> <div className={classes.images}> <ImageInput callback={setLeft} progress={leftProgress} /> <ImageInput callback={setRight} progress={rightProgress} /> </div> </Card> - {(leftProgress > 0 || rightProgress > 0) && ( + {isSubmitting && ( <> <LinearProgress color="primary" /> <Message |