From c5b6f8b808b7517e598ca497f283e5d854df9082 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Thu, 29 Dec 2016 11:55:25 +0100 Subject: [PATCH 1/4] Keep scroll postion. closes #27 --- frontend/src/component/app.jsx | 7 +++---- frontend/src/index.jsx | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/component/app.jsx b/frontend/src/component/app.jsx index 838a00b2ab..2b86b29716 100644 --- a/frontend/src/component/app.jsx +++ b/frontend/src/component/app.jsx @@ -9,6 +9,7 @@ import ErrorContainer from './error/error-container'; import UserContainer from './user/user-container'; import ShowUserContainer from './user/show-user-container'; +import { ScrollContainer } from 'react-router-scroll'; const base = { name: 'Unleash', @@ -42,10 +43,6 @@ export default class App extends Component { if (this.props.location.pathname !== nextProps.location.pathname) { clearTimeout(this.timer); this.timer = setTimeout(() => { - window.requestAnimationFrame(() => { - document.querySelector('.mdl-layout__content').scrollTop = 0; - }); - const layout = document.querySelector('.mdl-js-layout'); const drawer = document.querySelector('.mdl-layout__drawer'); // hack, might get a built in alternative later @@ -122,6 +119,7 @@ export default class App extends Component { {createListItem('/applications', 'Applications', 'apps')} + @@ -161,6 +159,7 @@ export default class App extends Component { + ); diff --git a/frontend/src/index.jsx b/frontend/src/index.jsx index cba21bf2f7..8a2993bcec 100644 --- a/frontend/src/index.jsx +++ b/frontend/src/index.jsx @@ -4,7 +4,8 @@ import 'react-mdl/extra/material.js'; import React from 'react'; import ReactDOM from 'react-dom'; -import { Router, Route, IndexRedirect, hashHistory } from 'react-router'; +import { applyRouterMiddleware, Router, Route, IndexRedirect, hashHistory } from 'react-router'; +import { useScroll } from 'react-router-scroll'; import { Provider } from 'react-redux'; import thunkMiddleware from 'redux-thunk'; import { createStore, applyMiddleware } from 'redux'; @@ -35,7 +36,7 @@ const unleashStore = createStore( ReactDOM.render( - + From 3e526e655e37e552c8bf9ab5293e2e51afa31950 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Thu, 29 Dec 2016 12:29:31 +0100 Subject: [PATCH 2/4] use pathname as scrollKey --- frontend/src/component/app.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/component/app.jsx b/frontend/src/component/app.jsx index 2b86b29716..924714f767 100644 --- a/frontend/src/component/app.jsx +++ b/frontend/src/component/app.jsx @@ -119,7 +119,7 @@ export default class App extends Component { {createListItem('/applications', 'Applications', 'apps')} - + From ed073230fc3a8a35beda1f1538dbc8ffb11a98f0 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Thu, 29 Dec 2016 12:36:12 +0100 Subject: [PATCH 3/4] add react-router-scroll to package.json --- frontend/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/package.json b/frontend/package.json index 0dbb7ee4f8..74343f8386 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -45,6 +45,7 @@ "react-modal": "^1.6.4", "react-redux": "^4.4.5", "react-router": "^3.0.0", + "react-router-scroll": "^0.4.1", "redux": "^3.6.0", "redux-thunk": "^2.1.0", "whatwg-fetch": "^2.0.0" From 98abaa921bf5ef4833501c7461f27e208763cdf1 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Thu, 29 Dec 2016 14:01:03 +0100 Subject: [PATCH 4/4] only keep scroll-position for back/forward actions --- frontend/src/component/app.jsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/component/app.jsx b/frontend/src/component/app.jsx index 924714f767..9369a62d80 100644 --- a/frontend/src/component/app.jsx +++ b/frontend/src/component/app.jsx @@ -93,12 +93,19 @@ export default class App extends Component { } render () { + const shouldUpdateScroll = (prevRouterProps, { location }) => { + if (prevRouterProps && location.pathname !== prevRouterProps.location.pathname) { + return location.action === 'POP'; + } else { + return [0, 0]; + } + }; const createListItem = (path, caption, icon) => - {icon && } {caption} - ; + ; return (
@@ -119,7 +126,7 @@ export default class App extends Component { {createListItem('/applications', 'Applications', 'apps')} - +