From d7aba191cdfbf6f2f5e35bcaa94e011fafcde3dc Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 13 Aug 2020 23:55:35 +0300 Subject: feat: scroll to top on redirects --- src/containers/Page/Page.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/containers/Page') diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx index 848ca1d..c876dae 100644 --- a/src/containers/Page/Page.tsx +++ b/src/containers/Page/Page.tsx @@ -1,8 +1,8 @@ -import React, { Suspense } from 'react'; +import React, { Suspense, useEffect } from 'react'; import { makeStyles, useTheme } from '@material-ui/core/styles'; import { useMediaQuery } from '@material-ui/core'; import { SnackbarProvider } from 'notistack'; -import { Switch, Route } from 'react-router-dom'; +import { Switch, Route, useHistory } from 'react-router-dom'; import Loading from '../../components/Loading/Loading'; const Profile = React.lazy(() => import('../Profile/Profile')); @@ -29,8 +29,15 @@ const useStyles = makeStyles(theme => ({ const Page: React.FC = () => { const classes = useStyles(); const theme = useTheme(); + const history = useHistory(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); + useEffect(() => { + return history.listen(() => { + window.scrollTo(0, 0); + }); + }, [history]) + return ( Date: Fri, 14 Aug 2020 02:45:20 +0300 Subject: refactor: resolve eslint errors --- src/containers/Page/Page.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/containers/Page') diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx index c876dae..023d86e 100644 --- a/src/containers/Page/Page.tsx +++ b/src/containers/Page/Page.tsx @@ -1,4 +1,4 @@ -import React, { Suspense, useEffect } from 'react'; +import React, { Suspense, useEffect } from 'react'; import { makeStyles, useTheme } from '@material-ui/core/styles'; import { useMediaQuery } from '@material-ui/core'; import { SnackbarProvider } from 'notistack'; @@ -17,7 +17,7 @@ const PollCreation = React.lazy(() => import('../PollCreation/PollCreation')); const useStyles = makeStyles(theme => ({ root: { [theme.breakpoints.down('sm')]: { - margin: theme.spacing(12, 0, 12, 0) + margin: theme.spacing(10, 0, 12, 0) }, [theme.breakpoints.up('md')]: { margin: theme.spacing(15, 5, 8, 5) @@ -36,7 +36,7 @@ const Page: React.FC = () => { return history.listen(() => { window.scrollTo(0, 0); }); - }, [history]) + }, [history]); return (