Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where scrolling was preserved when navigating #227

Merged
merged 6 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions workspaces/ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect } from 'react';
import './App.css';
import CssBaseline from '@material-ui/core/CssBaseline';
import { appTheme } from './theme';
import { BrowserRouter, Route } from 'react-router-dom';
import { BrowserRouter, Route, useLocation } from 'react-router-dom';
import { SnackbarProvider } from 'notistack';
import { ThemeProvider } from '@material-ui/core/styles';
import TopLevelRoutes from './entrypoints';
Expand Down Expand Up @@ -32,7 +32,7 @@ class App extends React.Component {
</React.Fragment>
);
}
// Life cylce methods
// Life cycle methods
// ------------------
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
Expand Down Expand Up @@ -106,4 +106,5 @@ function AppError() {
);
}


export default App;
9 changes: 9 additions & 0 deletions workspaces/ui/src/components/Page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useContext, useState } from 'react';
import Navbar from './navigation/Navbar';
import { useLocation } from 'react-router-dom'
import { makeStyles } from '@material-ui/core/styles';

const PageContext = React.createContext(null);
Expand Down Expand Up @@ -33,6 +34,14 @@ export default function Page(props) {
document.title = `${title} - Optic`;
}, [title]);

const { pathname } = useLocation();

useEffect(() => {
if (props.scrollToTop) {
window.scrollTo(0, 0);
}
}, [pathname]);

return (
<PageContext.Provider value={pageContext}>
<div className={classes.root}>{props.children}</div>;
Expand Down
2 changes: 1 addition & 1 deletion workspaces/ui/src/components/docs/DocsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const useStyles = makeStyles((theme) => ({
export const DocsPage = ({ match, specService }) => {
const routerPaths = useRouterPaths();
return (
<Page title="Documentation">
<Page title="Documentation" scrollToTop={true}>
<Page.Navbar mini={true} />
<Page.Body>
<Switch>
Expand Down