aboutsummaryrefslogtreecommitdiff
path: root/src/containers
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers')
-rw-r--r--src/containers/Page/Page.tsx8
-rw-r--r--src/containers/Page/Router.tsx2
-rw-r--r--src/containers/PollCreation/ImageInput.tsx46
-rw-r--r--src/containers/PollCreation/PollCreation.tsx52
4 files changed, 62 insertions, 46 deletions
diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx
index b7e1938..e60f7da 100644
--- a/src/containers/Page/Page.tsx
+++ b/src/containers/Page/Page.tsx
@@ -10,10 +10,6 @@ import DynoWaiter from './DynoWaiter';
import Loading from '../../components/Loading/Loading';
import EmptyState from '../../components/EmptyState/EmptyState';
-interface HistoryChange {
- state?: LocationState | null;
-}
-
const useStyles = makeStyles(theme => ({
root: {
[theme.breakpoints.down('sm')]: {
@@ -32,10 +28,10 @@ const ErrorFallback: React.FC = () => (
const Page: React.FC = () => {
const classes = useStyles();
const theme = useTheme();
- const history = useHistory();
+ const history = useHistory<LocationState>();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
- useEffect(() => history.listen((update: HistoryChange) => {
+ useEffect(() => history.listen(update => {
if (!update.state?.background) window.scrollTo(0, 0);
}), [history]);
diff --git a/src/containers/Page/Router.tsx b/src/containers/Page/Router.tsx
index 7c3a418..7c74e9a 100644
--- a/src/containers/Page/Router.tsx
+++ b/src/containers/Page/Router.tsx
@@ -12,7 +12,7 @@ const Home = React.lazy(() => import('../Home/Home'));
const Notifications = React.lazy(() => import('../Notifications/Notifications'));
export interface LocationState {
- background?: Location;
+ background: Location;
}
const Router: React.FC = React.memo(() => {
diff --git a/src/containers/PollCreation/ImageInput.tsx b/src/containers/PollCreation/ImageInput.tsx
index e807865..181294e 100644
--- a/src/containers/PollCreation/ImageInput.tsx
+++ b/src/containers/PollCreation/ImageInput.tsx
@@ -17,13 +17,33 @@ interface PropTypes {
progress?: number;
}
-const useStyles = makeStyles({
+const useStyles = makeStyles(theme => ({
root: {
+ width: '50%',
+ display: 'flex'
+ },
+ mediaRoot: {
+ display: 'flex'
+ },
+ uploadRoot: {
+ flex: 1,
+ display: 'flex',
+ [theme.breakpoints.up('md')]: {
+ padding: theme.spacing(4)
+ },
+ [theme.breakpoints.down('sm')]: {
+ padding: theme.spacing(8, 1)
+ }
+ },
+ outline: {
+ padding: theme.spacing(2),
+ flex: 1,
+ border: '2px dashed gray',
+ borderRadius: theme.spacing(1),
display: 'flex',
justifyContent: 'center',
flexDirection: 'column',
- alignItems: 'center',
- width: '50%'
+ alignItems: 'center'
},
clearIcon: {
opacity: '.5',
@@ -48,7 +68,7 @@ const useStyles = makeStyles({
icon: {
color: 'white'
}
-});
+}));
const ImageInput: React.FC<PropTypes> = ({ callback, progress }) => {
@@ -69,15 +89,17 @@ const ImageInput: React.FC<PropTypes> = ({ callback, progress }) => {
};
const Upload = (
- <div className={classes.root}>
- <FileUpload callback={childrenCallback} />
- <Typography variant="h6"> or </Typography>
- <AttachLink callback={childrenCallback} />
+ <div className={classes.uploadRoot}>
+ <div className={classes.outline}>
+ <FileUpload callback={childrenCallback} />
+ <Typography variant="h6"> or </Typography>
+ <AttachLink callback={childrenCallback} />
+ </div>
</div>
);
const Media = (
- <CardActionArea onClick={handleClear} className={classes.root} disabled={Boolean(progress)}>
+ <CardActionArea onClick={handleClear} className={classes.mediaRoot} disabled={Boolean(progress)}>
<BackgroundImage src={url} />
<div className={`${classes.overlay} ${progress === 100 && classes.invisible}`}>
{
@@ -91,7 +113,11 @@ const ImageInput: React.FC<PropTypes> = ({ callback, progress }) => {
</CardActionArea>
);
- return url ? Media : Upload;
+ return (
+ <div className={classes.root}>
+ {url ? Media : Upload}
+ </div>
+ );
};
export default ImageInput;
diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx
index b7ee00a..68f41d2 100644
--- a/src/containers/PollCreation/PollCreation.tsx
+++ b/src/containers/PollCreation/PollCreation.tsx
@@ -1,21 +1,17 @@
import React from 'react';
import Bluebird from 'bluebird';
-import { useHistory } from 'react-router-dom';
import { makeStyles } from '@material-ui/core/styles';
-import {
- Button,
- Card,
- Container,
- LinearProgress
-} from '@material-ui/core';
+import { Card, Container, LinearProgress } from '@material-ui/core';
+import SendIcon from '@material-ui/icons/Send';
import { useSnackbar } from 'notistack';
import useS3Preupload from './useS3Preupload';
import ImageInput from './ImageInput';
import ModalScreen from '../../components/ModalScreen/ModalScreen';
+import Message from '../../components/Message/Message';
import UserStrip from '../../components/UserStrip/UserStrip';
import { post } from '../../requests';
-import { useFeed } from '../../hooks/APIClient';
+import { useFeed, useProfile } from '../../hooks/APIClient';
import { useAuth } from '../../hooks/useAuth';
@@ -29,10 +25,10 @@ const useStyles = makeStyles(theme => ({
const PollCreation: React.FC = () => {
const classes = useStyles();
- const history = useHistory();
const { user } = useAuth();
const { enqueueSnackbar } = useSnackbar();
const { mutate: updateFeed } = useFeed();
+ const { mutate: updateProfile } = useProfile(user?.username || '');
const {
file: left,
setFile: setLeft,
@@ -46,7 +42,7 @@ const PollCreation: React.FC = () => {
progress: rightProgress
} = useS3Preupload();
- const handleClick = async () => {
+ const handleSubmit = async () => {
try {
const [leftUrl, rightUrl] = await Bluebird.all([resolveLeft(), resolveRight()]);
@@ -55,20 +51,23 @@ const PollCreation: React.FC = () => {
right: { url: rightUrl }
};
- history.push('/feed');
-
post('/polls/', { contents }).then(() => {
updateFeed();
+ updateProfile();
enqueueSnackbar('Your poll has been successfully created!', { variant: 'success' });
});
} catch (error) {
enqueueSnackbar('Failed to create a poll. Please, try again.', { variant: 'error' });
- history.push('/feed');
}
};
return (
- <ModalScreen title="Create a poll">
+ <ModalScreen
+ title="Create a poll"
+ actionIcon={<SendIcon />}
+ handleAction={handleSubmit}
+ isActionDisabled={!(left && right) || leftProgress > 0 || rightProgress > 0}
+ >
<Container maxWidth="sm" disableGutters>
<Card elevation={3}>
{user && <UserStrip user={user} info="" />}
@@ -76,22 +75,17 @@ const PollCreation: React.FC = () => {
<ImageInput callback={setLeft} progress={leftProgress} />
<ImageInput callback={setRight} progress={rightProgress} />
</div>
- {
- leftProgress || rightProgress
- ? <LinearProgress color="primary" />
- : (
- <Button
- color="primary"
- disabled={!(left && right)}
- variant="contained"
- onClick={handleClick}
- fullWidth
- >
- Submit
- </Button>
- )
- }
</Card>
+ {(leftProgress > 0 || rightProgress > 0) && (
+ <>
+ <LinearProgress color="primary" />
+ <Message
+ tagline="You can close this window now"
+ message="We will upload your images in the background."
+ noMargin
+ />
+ </>
+ )}
</Container>
</ModalScreen>
);