From c73a0d7643ac335dbcdc64b90467ba7d3a45c4f4 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 15:10:15 +0300 Subject: feat: add dashed borders to ImageInput --- src/components/AttachLink/AttachLink.tsx | 2 +- src/containers/PollCreation/ImageInput.tsx | 46 +++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/components/AttachLink/AttachLink.tsx b/src/components/AttachLink/AttachLink.tsx index 742ba65..7c32635 100644 --- a/src/components/AttachLink/AttachLink.tsx +++ b/src/components/AttachLink/AttachLink.tsx @@ -21,7 +21,7 @@ const AttachLink: React.FC = ({ callback, children }) => { color="primary" startIcon={} > - Attach a link + Link ); 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 = ({ callback, progress }) => { @@ -69,15 +89,17 @@ const ImageInput: React.FC = ({ callback, progress }) => { }; const Upload = ( -
- - or - +
+
+ + or + +
); const Media = ( - +
{ @@ -91,7 +113,11 @@ const ImageInput: React.FC = ({ callback, progress }) => { ); - return url ? Media : Upload; + return ( +
+ {url ? Media : Upload} +
+ ); }; export default ImageInput; -- cgit v1.2.3 From 3cbf292b6d4976589428d0841cd1201057d104d4 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 15:51:19 +0300 Subject: feat: use icon in header instead of submit button --- src/components/ModalScreen/ModalScreen.tsx | 13 ++++++++----- src/containers/PollCreation/PollCreation.tsx | 29 +++++++++++----------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 81e5c5a..110bd8b 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -12,11 +12,12 @@ import { useTheme } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; -import CloseIcon from '@material-ui/icons/Close'; import { TransitionProps } from '@material-ui/core/transitions'; +import CloseIcon from '@material-ui/icons/Close'; interface PropTypes { title: string; + rightIcon?: JSX.Element; } const useStyles = makeStyles(theme => ({ @@ -37,7 +38,7 @@ const Transition = React.forwardRef(( ref: React.Ref ) => ); -const ModalScreen: React.FC = ({ title, children }) => { +const ModalScreen: React.FC = ({ title, rightIcon, children }) => { const [isOpen, setIsOpen] = useState(true); const classes = useStyles(); const theme = useTheme(); @@ -64,9 +65,11 @@ const ModalScreen: React.FC = ({ title, children }) => { { title } - - - + { rightIcon || ( + + + + )} diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index b7ee00a..18c3c6b 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -3,11 +3,12 @@ import Bluebird from 'bluebird'; import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { - Button, + IconButton, Card, Container, LinearProgress } from '@material-ui/core'; +import SendIcon from '@material-ui/icons/Send'; import { useSnackbar } from 'notistack'; import useS3Preupload from './useS3Preupload'; @@ -46,7 +47,7 @@ const PollCreation: React.FC = () => { progress: rightProgress } = useS3Preupload(); - const handleClick = async () => { + const handleSubmit = async () => { try { const [leftUrl, rightUrl] = await Bluebird.all([resolveLeft(), resolveRight()]); @@ -67,8 +68,14 @@ const PollCreation: React.FC = () => { } }; + const submitIcon = ( + + + + ); + return ( - + {user && } @@ -76,21 +83,7 @@ const PollCreation: React.FC = () => {
- { - leftProgress || rightProgress - ? - : ( - - ) - } + {(leftProgress > 0 || rightProgress > 0) && } -- cgit v1.2.3 From 8660ae7ba37c3e1812bfbbf4bca31bfe3274edcf Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 19:22:09 +0300 Subject: fix: resolve ts errors --- package-lock.json | 8 -------- package.json | 1 - src/containers/Page/Page.tsx | 8 ++------ src/containers/Page/Router.tsx | 2 +- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 03961ee..e25fb85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6396,14 +6396,6 @@ "resolved": "https://registry.npmjs.org/hex-color-regex/-/hex-color-regex-1.1.0.tgz", "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==" }, - "history": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/history/-/history-5.0.0.tgz", - "integrity": "sha512-3NyRMKIiFSJmIPdq7FxkNMJkQ7ZEtVblOQ38VtKaA0zZMW1Eo6Q6W8oDKEflr1kNNTItSnk4JMCO1deeSgbLLg==", - "requires": { - "@babel/runtime": "^7.7.6" - } - }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", diff --git a/package.json b/package.json index f45d4e7..2bb2500 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "bluebird": "^3.7.2", "compressorjs": "^1.0.6", "formik": "^2.1.5", - "history": "^5.0.0", "lodash": "^4.17.15", "notistack": "^0.9.17", "react": "^16.13.1", 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(); 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(() => { -- cgit v1.2.3 From 3ea7d6bd0bfd6aefd939bf84f5dc1696cf68231e Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 19:31:20 +0300 Subject: feat: tweak modal paddings on desktop --- src/components/ModalScreen/ModalScreen.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 110bd8b..7090980 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -25,7 +25,7 @@ const useStyles = makeStyles(theme => ({ backgroundColor: theme.palette.background.default }, content: { - padding: theme.spacing(3, 0, 0, 0) + padding: theme.spacing(6, 0) }, toolbar: { display: 'flex', @@ -55,6 +55,7 @@ const ModalScreen: React.FC = ({ title, rightIcon, children }) => { TransitionComponent={Transition} PaperProps={{ className: classes.root }} fullScreen={isMobile} + maxWidth="md" fullWidth > -- cgit v1.2.3 From 33b3066b04f7560455c113a18fe39d33933daaf1 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 20:18:21 +0300 Subject: fix: replace typo id -> username --- src/hooks/APIClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/APIClient.ts b/src/hooks/APIClient.ts index cf5d247..68413b0 100644 --- a/src/hooks/APIClient.ts +++ b/src/hooks/APIClient.ts @@ -13,8 +13,8 @@ export const useUser = (username: string | null): Response => { ); }; -export const useProfile = (id: string): Response => { - return useSWR(id && `/profiles/${id}`, fetcher); +export const useProfile = (username: string): Response => { + return useSWR(username && `/profiles/${username}`, fetcher); }; export const useFeed = (): Response => { -- cgit v1.2.3 From 40cc9f63feb15e1bb14c5360b4437d3379df96e2 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 20:21:10 +0300 Subject: feat: add noMargin prop to Message --- src/components/Message/Message.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/Message/Message.tsx b/src/components/Message/Message.tsx index f568552..e5191ed 100644 --- a/src/components/Message/Message.tsx +++ b/src/components/Message/Message.tsx @@ -6,6 +6,7 @@ import { makeStyles } from '@material-ui/core/styles'; interface PropTypes { tagline?: string; message?: string; + noMargin?: boolean; } const useStyles = makeStyles(theme => ({ @@ -13,7 +14,9 @@ const useStyles = makeStyles(theme => ({ display: 'flex', flexDirection: 'column', justifyContent: 'center', - alignItems: 'center', + alignItems: 'center' + }, + margin: { marginTop: theme.spacing(6) }, content: { @@ -21,11 +24,11 @@ const useStyles = makeStyles(theme => ({ } })); -const Message: React.FC = React.memo(({ tagline, message, children }) => { +const Message: React.FC = React.memo(({ tagline, message, noMargin, children }) => { const classes = useStyles(); return ( -
+
{children}
-- cgit v1.2.3 From fd7e4817cd0e0160e85ad98ad81f406c66a94800 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 20:21:35 +0300 Subject: feat: correctly wire modal logic --- src/components/ModalScreen/ModalScreen.tsx | 19 ++++++++----- src/containers/PollCreation/PollCreation.tsx | 41 ++++++++++++++-------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 7090980..6c514cd 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -17,7 +17,9 @@ import CloseIcon from '@material-ui/icons/Close'; interface PropTypes { title: string; - rightIcon?: JSX.Element; + actionIcon?: JSX.Element; + handleAction?: () => void; + isActionDisabled?: boolean; } const useStyles = makeStyles(theme => ({ @@ -38,7 +40,7 @@ const Transition = React.forwardRef(( ref: React.Ref ) => ); -const ModalScreen: React.FC = ({ title, rightIcon, children }) => { +const ModalScreen: React.FC = ({ title, actionIcon, handleAction, isActionDisabled, children }) => { const [isOpen, setIsOpen] = useState(true); const classes = useStyles(); const theme = useTheme(); @@ -48,6 +50,11 @@ const ModalScreen: React.FC = ({ title, rightIcon, children }) => { const handleClose = useCallback(() => setIsOpen(false), [setIsOpen]); const onExited = useCallback(() => history.goBack(), [history]); + const handleClickAction = useCallback(async () => { + if (handleAction) await handleAction(); + return handleClose(); + }, [handleAction, handleClose]); + return ( = ({ title, rightIcon, children }) => { { title } - { rightIcon || ( - - - - )} + + { actionIcon } + diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index 18c3c6b..68f41d2 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -1,22 +1,17 @@ import React from 'react'; import Bluebird from 'bluebird'; -import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; -import { - IconButton, - 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'; @@ -30,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, @@ -56,26 +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'); } }; - const submitIcon = ( - - - - ); - return ( - + } + handleAction={handleSubmit} + isActionDisabled={!(left && right) || leftProgress > 0 || rightProgress > 0} + > {user && } @@ -83,8 +75,17 @@ const PollCreation: React.FC = () => {
- {(leftProgress > 0 || rightProgress > 0) && } + {(leftProgress > 0 || rightProgress > 0) && ( + <> + + + + )} ); -- cgit v1.2.3 From 2c093ce738cb1281db04a8a3f2b6a35b3aa9b354 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 20:24:46 +0300 Subject: fix: close modal on clickaway --- src/components/ModalScreen/ModalScreen.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 6c514cd..c6f0565 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -58,6 +58,7 @@ const ModalScreen: React.FC = ({ title, actionIcon, handleAction, isA return (