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/containers/Page/Page.tsx | 15 ++++++++----- src/containers/Page/Router.tsx | 48 +++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 20 deletions(-) (limited to 'src/containers') 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