temp fix to scroll to top on navigate

This commit is contained in:
Sean Yesmunt 2019-04-02 00:30:19 -04:00
parent 5251ce5090
commit 497e499c62
2 changed files with 40 additions and 25 deletions

View file

@ -70,14 +70,14 @@ class App extends React.PureComponent<Props> {
return ( return (
<div id="window" onContextMenu={e => openContextMenu(e)}> <div id="window" onContextMenu={e => openContextMenu(e)}>
<Header /> <Header />
<main className="page"> <section className="page">
{enhancedLayout && <Yrbl className="yrbl--enhanced" />} {enhancedLayout && <Yrbl className="yrbl--enhanced" />}
<SideBar /> <SideBar />
<div className="content" id="content"> <div className="content" id="content">
<Router /> <Router />
<ModalRouter /> <ModalRouter />
</div> </div>
</main> </section>
</div> </div>
); );
} }

View file

@ -1,5 +1,5 @@
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
import React from 'react'; import React, { useEffect } from 'react';
import { Router } from '@reach/router'; import { Router } from '@reach/router';
import SettingsPage from 'page/settings'; import SettingsPage from 'page/settings';
import HelpPage from 'page/help'; import HelpPage from 'page/help';
@ -21,9 +21,23 @@ import UserHistoryPage from 'page/userHistory';
import SendCreditsPage from 'page/sendCredits'; import SendCreditsPage from 'page/sendCredits';
import NavigationHistory from 'page/navigationHistory'; import NavigationHistory from 'page/navigationHistory';
export default function AppRouter(props) { const ScrollHandler = props => {
const { key } = props.location;
useEffect(() => {
// This shouldn't scroll to top when you click "back"
// Might take some more work but fixes scroll position being stuck on navigation for now
const main = document.querySelector('main');
main.scrollIntoView();
}, [key]);
return props.children;
};
export default function AppRouter() {
return ( return (
<Router> <Router>
<ScrollHandler path="/">
<DiscoverPage path="/" /> <DiscoverPage path="/" />
<ShowPage path="/:claimName/:claimId" /> <ShowPage path="/:claimName/:claimId" />
<ShowPage path="/:claimName" /> <ShowPage path="/:claimName" />
@ -46,6 +60,7 @@ export default function AppRouter(props) {
<SendCreditsPage path={`$/${PAGES.SEND}`} /> <SendCreditsPage path={`$/${PAGES.SEND}`} />
<UserHistoryPage path={`$/${PAGES.HISTORY}`} /> <UserHistoryPage path={`$/${PAGES.HISTORY}`} />
<NavigationHistory path={`$/${PAGES.HISTORY}/all`} /> <NavigationHistory path={`$/${PAGES.HISTORY}/all`} />
</ScrollHandler>
</Router> </Router>
); );
} }