aboutsummaryrefslogtreecommitdiff
path: root/src/containers/PollCreation/PollCreation.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/PollCreation/PollCreation.tsx')
-rw-r--r--src/containers/PollCreation/PollCreation.tsx39
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