From fca54f49bb3541f726da1becffaa60197835ca68 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 14 Aug 2020 02:45:20 +0300 Subject: refactor: resolve eslint errors --- src/containers/PollCreation/ImageInput.tsx | 96 +++++++++++++++++++++++ src/containers/PollCreation/PollCreation.tsx | 33 +++++--- src/containers/PollCreation/PollCreationImage.tsx | 96 ----------------------- src/containers/PollCreation/types.ts | 7 -- 4 files changed, 116 insertions(+), 116 deletions(-) create mode 100644 src/containers/PollCreation/ImageInput.tsx delete mode 100644 src/containers/PollCreation/PollCreationImage.tsx delete mode 100644 src/containers/PollCreation/types.ts (limited to 'src/containers/PollCreation') diff --git a/src/containers/PollCreation/ImageInput.tsx b/src/containers/PollCreation/ImageInput.tsx new file mode 100644 index 0000000..cc60478 --- /dev/null +++ b/src/containers/PollCreation/ImageInput.tsx @@ -0,0 +1,96 @@ +import React, { useState } from 'react'; +import { makeStyles } from '@material-ui/core/styles'; +import { + CardActionArea, + CardMedia, + Typography, + CircularProgress +} from '@material-ui/core'; +import { Check, CancelOutlined } from '@material-ui/icons'; + +import AttachLink from '../../components/AttachLink/AttachLink'; +import FileUpload from '../../components/FileUpload/FileUpload'; + +interface PropTypes { + callback: (file?: File | string) => void; + progress?: number; +} + +const useStyles = makeStyles({ + root: { + display: 'flex', + justifyContent: 'center', + flexDirection: 'column', + alignItems: 'center', + width: '50%' + }, + clearIcon: { + opacity: '.5', + fontSize: 50 + }, + media: { + height: '100%', + width: '100%', + display: 'flex', + justifyContent: 'center', + alignItems: 'center' + }, + darkOverlay: { + backgroundColor: 'rgba(0, 0, 0, 0.45)', + color: 'white', + position: 'absolute', + top: 0, + left: 0, + transitionDuration: '0.5s' + }, + invisible: { + backgroundColor: 'rgba(0, 0, 0, 0)' + }, + icon: { + color: 'white' + } +}); + + +const ImageInput: React.FC = ({ callback, progress }) => { + const classes = useStyles(); + const [url, setUrl] = useState(); + + const handleClear = (): void => { + setUrl(undefined); + callback(undefined); + }; + + const childrenCallback = (fileUrl: string, file?: File) => { + setUrl(fileUrl); + callback(file || fileUrl); + }; + + const Upload = ( +
+ + or + +
+ ); + + const Media = ( + + +
+ { + progress + ? progress < 100 + ? + : + : + } +
+
+
+ ); + + return url ? Media : Upload; +}; + +export default ImageInput; diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index e350179..107314a 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -5,11 +5,12 @@ import { Button, Card, Divider, - Container + Container, + LinearProgress } from '@material-ui/core'; import { useSnackbar } from 'notistack'; -import PollCreationImage from './PollCreationImage'; +import ImageInput from './ImageInput'; import UserStrip from '../../components/UserStrip/UserStrip'; import { post } from '../../requests'; import { useAuth } from '../../hooks/useAuth'; @@ -73,18 +74,24 @@ const PollCreation: React.FC = () => { {user && }
- - + +
- + { + progressLeft || progressRight + ? + : ( + + ) + } ); diff --git a/src/containers/PollCreation/PollCreationImage.tsx b/src/containers/PollCreation/PollCreationImage.tsx deleted file mode 100644 index d619a8e..0000000 --- a/src/containers/PollCreation/PollCreationImage.tsx +++ /dev/null @@ -1,96 +0,0 @@ -import React, { useState } from 'react'; -import { makeStyles } from '@material-ui/core/styles'; -import { - CardActionArea, - CardMedia, - Typography, - CircularProgress -} from '@material-ui/core'; -import { Check, CancelOutlined } from '@material-ui/icons'; - -import AttachLink from '../../components/AttachLink/AttachLink'; -import FileUpload from '../../components/FileUpload/FileUpload'; - -interface PropTypes { - callback: (file?: File | string) => void; - progress?: number; -} - -const useStyles = makeStyles({ - root: { - display: 'flex', - justifyContent: 'center', - flexDirection: 'column', - alignItems: 'center', - width: '50%' - }, - clearIcon: { - opacity: '.5', - fontSize: 50 - }, - media: { - height: '100%', - width: '100%', - display: 'flex', - justifyContent: 'center', - alignItems: 'center' - }, - darkOverlay: { - backgroundColor: 'rgba(0, 0, 0, 0.45)', - color: 'white', - position: 'absolute', - top: 0, - left: 0, - transitionDuration: '0.5s' - }, - invisible: { - backgroundColor: 'rgba(0, 0, 0, 0)', - }, - icon: { - color: 'white' - } -}); - - -const PollCreationImage: React.FC = ({ callback, progress }) => { - const classes = useStyles(); - const [url, setUrl] = useState(); - - const handleClear = (): void => { - setUrl(undefined); - callback(undefined); - }; - - const childrenCallback = (fileUrl: string, file?: File) => { - setUrl(fileUrl); - callback(file || fileUrl); - }; - - const Upload = ( -
- - or - -
- ); - - const Media = ( - - -
- { - progress - ? progress < 100 - ? - : - : - } -
-
-
- ); - - return url ? Media : Upload; -}; - -export default PollCreationImage; diff --git a/src/containers/PollCreation/types.ts b/src/containers/PollCreation/types.ts deleted file mode 100644 index 24ace4e..0000000 --- a/src/containers/PollCreation/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface ImageData { - url: string; -} -export interface Contents { - left: ImageData; - right: ImageData; -} -- cgit v1.2.3