From 4471fef74dfe312a8cf6a1440f5a703e897af136 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 7 Oct 2020 23:25:52 +0300 Subject: feat: wire modal routes --- src/components/Fab/Fab.tsx | 23 +++++++++----------- src/containers/Page/Page.tsx | 15 ++++++++----- src/containers/Page/Router.tsx | 48 +++++++++++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/components/Fab/Fab.tsx b/src/components/Fab/Fab.tsx index 7ca2893..f6b85e5 100644 --- a/src/components/Fab/Fab.tsx +++ b/src/components/Fab/Fab.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useHistory } from 'react-router-dom'; +import { useLocation, Link } from 'react-router-dom'; import { Fab as FabBase, Slide, useScrollTrigger } from '@material-ui/core/'; import { makeStyles } from '@material-ui/core/styles'; import PlusIcon from '@material-ui/icons/Add'; @@ -26,22 +26,19 @@ const useStyles = makeStyles(theme => ({ const Fab: React.FC = ({ hideOnScroll = false }) => { const classes = useStyles(); - const history = useHistory(); + const location = useLocation(); const trigger = useScrollTrigger(); - const handleClick = () => { - history.push('/new'); - }; - return ( - - - + + + + + ); }; diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx index 7df62cd..51b6d21 100644 --- a/src/containers/Page/Page.tsx +++ b/src/containers/Page/Page.tsx @@ -5,11 +5,14 @@ import { SnackbarProvider } from 'notistack'; import { ErrorBoundary } from 'react-error-boundary'; import { useHistory } from 'react-router-dom'; -import Router from './Router'; +import Router, { LocationState } from './Router'; 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: { @@ -32,11 +35,13 @@ const Page: React.FC = () => { const history = useHistory(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); - useEffect(() => { - return history.listen(() => { + useEffect(() => history.listen((update: HistoryChange) => { + console.log(update) + if (!update.state?.background) { + console.log('scrolling') window.scrollTo(0, 0); - }); - }, [history]); + } + }), [history]); return ( import('../Profile/Profile')); const Feed = React.lazy(() => import('../Feed/Feed')); @@ -7,20 +10,35 @@ const Login = React.lazy(() => import('../Login/Login')); const Registration = React.lazy(() => import('../Registration/Registration')); const Home = React.lazy(() => import('../Home/Home')); const Notifications = React.lazy(() => import('../Notifications/Notifications')); -const PollCreation = React.lazy(() => import('../PollCreation/PollCreation')); - - -const Router: React.FC = React.memo(() => ( - - - - - - - - - -)); + +export interface LocationState { + background?: Location; +} + +const Router: React.FC = React.memo(() => { + const location = useLocation(); + const background = location.state && location.state.background; + + const ModalSwitch = ( + + + + ); + + return ( + <> + {background && ModalSwitch} + + + + + + + + + + ); +}); export default Router; -- cgit v1.2.3 From a283d4310c11f03fe9ff889c6274798b70cf6a19 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 7 Oct 2020 23:51:45 +0300 Subject: feat: create ModalScreen component --- src/components/ModalScreen/ModalScreen.tsx | 39 +++++++++++++++++++ src/containers/Page/Page.tsx | 6 +-- src/containers/PollCreation/PollCreation.tsx | 58 +++++++++++++--------------- 3 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 src/components/ModalScreen/ModalScreen.tsx diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx new file mode 100644 index 0000000..6b7c52c --- /dev/null +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -0,0 +1,39 @@ +import React, { useCallback } from 'react'; +import { useHistory } from 'react-router-dom'; +import { + Dialog, + Toolbar, + Typography, + IconButton, + useMediaQuery, + useTheme +} from '@material-ui/core'; +import CloseIcon from '@material-ui/icons/Close'; + +interface PropTypes { + title: string; +} + +const ModalScreen: React.FC = ({ title, children }) => { + const theme = useTheme(); + const isMobile = useMediaQuery(theme.breakpoints.down('sm')); + const history = useHistory(); + + const handleClose = useCallback(() => history.goBack(), [history]); + + return ( + + + + + + + { title } + + + { children } + + ); +}; + +export default ModalScreen; diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx index 51b6d21..b7e1938 100644 --- a/src/containers/Page/Page.tsx +++ b/src/containers/Page/Page.tsx @@ -36,11 +36,7 @@ const Page: React.FC = () => { const isMobile = useMediaQuery(theme.breakpoints.down('sm')); useEffect(() => history.listen((update: HistoryChange) => { - console.log(update) - if (!update.state?.background) { - console.log('scrolling') - window.scrollTo(0, 0); - } + if (!update.state?.background) window.scrollTo(0, 0); }), [history]); return ( diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index ecc6757..079c79f 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -5,7 +5,6 @@ import { makeStyles } from '@material-ui/core/styles'; import { Button, Card, - Divider, Container, LinearProgress } from '@material-ui/core'; @@ -13,16 +12,12 @@ import { useSnackbar } from 'notistack'; import useS3Preupload from './useS3Preupload'; import ImageInput from './ImageInput'; -import UserStrip from '../../components/UserStrip/UserStrip'; +import ModalScreen from '../../components/ModalScreen/ModalScreen'; import { post } from '../../requests'; -import { useAuth } from '../../hooks/useAuth'; import { useFeed } from '../../hooks/APIClient'; const useStyles = makeStyles(theme => ({ - root: { - marginBottom: theme.spacing(4) - }, images: { height: theme.spacing(50), display: 'flex' @@ -34,7 +29,6 @@ const PollCreation: React.FC = () => { const classes = useStyles(); const history = useHistory(); const { enqueueSnackbar } = useSnackbar(); - const { user } = useAuth(); const { mutate: updateFeed } = useFeed(); const { file: left, @@ -71,31 +65,31 @@ const PollCreation: React.FC = () => { }; return ( - - - {user && } - -
- - -
- { - leftProgress || rightProgress - ? - : ( - - ) - } -
-
+ + + +
+ + +
+ { + leftProgress || rightProgress + ? + : ( + + ) + } +
+
+
); }; -- cgit v1.2.3 From d2146a79fb059cb41d03b16f799f89cbaf1c6312 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 7 Oct 2020 23:53:58 +0300 Subject: chore: add history to dependencies --- package-lock.json | 41 ++++++++++++++++++++++++++++++++--------- package.json | 1 + 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index d80d20f..03961ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6397,16 +6397,11 @@ "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==" }, "history": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", - "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.0.0.tgz", + "integrity": "sha512-3NyRMKIiFSJmIPdq7FxkNMJkQ7ZEtVblOQ38VtKaA0zZMW1Eo6Q6W8oDKEflr1kNNTItSnk4JMCO1deeSgbLLg==", "requires": { - "@babel/runtime": "^7.1.2", - "loose-envify": "^1.2.0", - "resolve-pathname": "^3.0.0", - "tiny-invariant": "^1.0.2", - "tiny-warning": "^1.0.0", - "value-equal": "^1.0.1" + "@babel/runtime": "^7.7.6" } }, "hmac-drbg": { @@ -10998,6 +10993,19 @@ "tiny-warning": "^1.0.0" }, "dependencies": { + "history": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", + "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "requires": { + "@babel/runtime": "^7.1.2", + "loose-envify": "^1.2.0", + "resolve-pathname": "^3.0.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0", + "value-equal": "^1.0.1" + } + }, "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -11025,6 +11033,21 @@ "react-router": "5.2.0", "tiny-invariant": "^1.0.2", "tiny-warning": "^1.0.0" + }, + "dependencies": { + "history": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", + "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "requires": { + "@babel/runtime": "^7.1.2", + "loose-envify": "^1.2.0", + "resolve-pathname": "^3.0.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0", + "value-equal": "^1.0.1" + } + } } }, "react-scripts": { diff --git a/package.json b/package.json index 2bb2500..f45d4e7 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "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", -- cgit v1.2.3 From 0397903b9046e062fc6adb367183e2169bd4b4b6 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 12:58:45 +0300 Subject: feat: return UserStrip to PollCreation --- src/components/ModalScreen/ModalScreen.tsx | 46 ++++++++++++++++++++++------ src/containers/PollCreation/PollCreation.tsx | 6 +++- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 6b7c52c..6ffc978 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -1,20 +1,36 @@ import React, { useCallback } from 'react'; import { useHistory } from 'react-router-dom'; import { + AppBar, Dialog, Toolbar, Typography, IconButton, + Divider, useMediaQuery, useTheme } from '@material-ui/core'; +import { makeStyles } from '@material-ui/core/styles'; import CloseIcon from '@material-ui/icons/Close'; interface PropTypes { title: string; } +const useStyles = makeStyles(theme => ({ + root: { + backgroundColor: theme.palette.background.default + }, + content: { + padding: theme.spacing(3, 0, 0, 0) + }, + toolbar: { + display: 'flex', + } +})); + const ModalScreen: React.FC = ({ title, children }) => { + const classes = useStyles(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); const history = useHistory(); @@ -22,16 +38,26 @@ const ModalScreen: React.FC = ({ title, children }) => { const handleClose = useCallback(() => history.goBack(), [history]); return ( - - - - - - - { title } - - - { children } + + + + + + + + { title } + + + + +
+ { children } +
); }; diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index 079c79f..b7ee00a 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -13,8 +13,10 @@ import { useSnackbar } from 'notistack'; import useS3Preupload from './useS3Preupload'; import ImageInput from './ImageInput'; import ModalScreen from '../../components/ModalScreen/ModalScreen'; +import UserStrip from '../../components/UserStrip/UserStrip'; import { post } from '../../requests'; import { useFeed } from '../../hooks/APIClient'; +import { useAuth } from '../../hooks/useAuth'; const useStyles = makeStyles(theme => ({ @@ -28,6 +30,7 @@ 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 { @@ -67,7 +70,8 @@ const PollCreation: React.FC = () => { return ( - + + {user && }
-- cgit v1.2.3 From 3ec8fb942f09e29020f6e466932ed0cca7db3d69 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 13:03:49 +0300 Subject: feat: add slide transition to modal --- src/components/ModalScreen/ModalScreen.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 6ffc978..c6044af 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from 'react'; +import React, { useState, useCallback } from 'react'; import { useHistory } from 'react-router-dom'; import { AppBar, @@ -7,11 +7,13 @@ import { Typography, IconButton, Divider, + Slide, useMediaQuery, 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'; interface PropTypes { title: string; @@ -29,17 +31,28 @@ const useStyles = makeStyles(theme => ({ } })); +const Transition = React.forwardRef(function Transition( + props: TransitionProps & { children?: React.ReactElement }, + ref: React.Ref, +) { + return ; +}); + const ModalScreen: React.FC = ({ title, children }) => { + const [isOpen, setIsOpen] = useState(true); const classes = useStyles(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); const history = useHistory(); - const handleClose = useCallback(() => history.goBack(), [history]); + const handleClose = useCallback(() => setIsOpen(false), [setIsOpen]); + const onExited = useCallback(() => history.goBack(), [history]) return ( Date: Thu, 8 Oct 2020 13:28:24 +0300 Subject: feat: stick all headers to same logic --- src/components/ModalScreen/ModalScreen.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index c6044af..4a4b1be 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -28,6 +28,7 @@ const useStyles = makeStyles(theme => ({ }, toolbar: { display: 'flex', + justifyContent: 'space-between' } })); @@ -35,7 +36,7 @@ const Transition = React.forwardRef(function Transition( props: TransitionProps & { children?: React.ReactElement }, ref: React.Ref, ) { - return ; + return ; }); const ModalScreen: React.FC = ({ title, children }) => { @@ -59,12 +60,15 @@ const ModalScreen: React.FC = ({ title, children }) => { > - + { title } + + + -- cgit v1.2.3 From 4a86d5c3f0b023c6e4e7862f2a49301ef8b4d3f7 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 13:33:39 +0300 Subject: feat: allow reaching modal routes from outside --- src/containers/Page/Router.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/containers/Page/Router.tsx b/src/containers/Page/Router.tsx index abf8f00..7c3a418 100644 --- a/src/containers/Page/Router.tsx +++ b/src/containers/Page/Router.tsx @@ -27,7 +27,7 @@ const Router: React.FC = React.memo(() => { return ( <> - {background && ModalSwitch} + {ModalSwitch} -- cgit v1.2.3 From 80a09a9ec176c7585dca9d81f6b3d690660ce633 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 13:56:28 +0300 Subject: style: fix eslint errors --- .eslintrc.json | 3 ++- src/components/ModalScreen/ModalScreen.tsx | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 479e04f..1102af4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,6 +25,7 @@ "react/prop-types": 0, "react/no-children-prop": 0, "react/no-danger": 0, - "react/jsx-one-expression-per-line": 0 + "react/jsx-one-expression-per-line": 0, + "react/jsx-props-no-spreading": 0 } } diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 4a4b1be..81e5c5a 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -32,12 +32,10 @@ const useStyles = makeStyles(theme => ({ } })); -const Transition = React.forwardRef(function Transition( - props: TransitionProps & { children?: React.ReactElement }, - ref: React.Ref, -) { - return ; -}); +const Transition = React.forwardRef(( + props: TransitionProps & { children?: React.ReactElement }, + ref: React.Ref +) => ); const ModalScreen: React.FC = ({ title, children }) => { const [isOpen, setIsOpen] = useState(true); @@ -47,7 +45,7 @@ const ModalScreen: React.FC = ({ title, children }) => { const history = useHistory(); const handleClose = useCallback(() => setIsOpen(false), [setIsOpen]); - const onExited = useCallback(() => history.goBack(), [history]) + const onExited = useCallback(() => history.goBack(), [history]); return (