diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-10-09 00:30:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-09 00:30:59 +0300 |
commit | a5d0f3edcd5478c81262524cbfef8273a065df36 (patch) | |
tree | 48725733e1650fb11f59e4e8dd4f752950a26f72 /src/containers/PollCreation | |
parent | bdb4d194307c9755c2083c1a11bb876abebcb6de (diff) | |
parent | 8e9245d18ba591e93dd7dd1de9a271d0b51941a7 (diff) | |
download | which-ui-a5d0f3edcd5478c81262524cbfef8273a065df36.tar.gz |
Merge pull request #103 from which-ecosystem/feat/description
Add description to Poll Model
Diffstat (limited to 'src/containers/PollCreation')
-rw-r--r-- | src/containers/PollCreation/PollCreation.tsx | 39 |
1 files changed, 31 insertions, 8 deletions
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 |