From 0b841bf268134a9caa5d75c9843bdad24a364109 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 22 Jul 2019 19:43:30 -0400 Subject: [PATCH] add scroll selector --- src/ui/component/router/index.js | 5 ++--- src/ui/component/router/view.jsx | 2 +- src/ui/redux/reducers/app.js | 2 ++ src/ui/redux/selectors/app.js | 5 +++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ui/component/router/index.js b/src/ui/component/router/index.js index 699e590ba..11f9ee843 100644 --- a/src/ui/component/router/index.js +++ b/src/ui/component/router/index.js @@ -1,10 +1,9 @@ import { connect } from 'react-redux'; +import { selectScrollStartingPosition } from 'redux/selectors/app'; import Router from './view'; const select = state => ({ - scroll: state.app.scrollHistory[state.app.scrollHistory.length - 1], - scrollHistory: state.app.scrollHistory, - currentScroll: state.app.currentScroll || 0, + currentScroll: selectScrollStartingPosition(state), }); export default connect(select)(Router); diff --git a/src/ui/component/router/view.jsx b/src/ui/component/router/view.jsx index 90be7b36c..13f6b3872 100644 --- a/src/ui/component/router/view.jsx +++ b/src/ui/component/router/view.jsx @@ -22,7 +22,7 @@ import NavigationHistory from 'page/navigationHistory'; import TagsPage from 'page/tags'; import FollowingPage from 'page/following'; -// Let app handle scroll +// Tell the browser we are handling scroll restoration if ('scrollRestoration' in history) { history.scrollRestoration = 'manual'; } diff --git a/src/ui/redux/reducers/app.js b/src/ui/redux/reducers/app.js index cc32dcc02..bea508dcf 100644 --- a/src/ui/redux/reducers/app.js +++ b/src/ui/redux/reducers/app.js @@ -67,6 +67,8 @@ const defaultState: AppState = { scrollHistory: [0], }; +// @@router comes from react-router +// This action is dispatched any time a user navigates forward or back reducers['@@router/LOCATION_CHANGE'] = (state, action) => { const { currentScroll } = state; const scrollHistory = state.scrollHistory.slice(); diff --git a/src/ui/redux/selectors/app.js b/src/ui/redux/selectors/app.js index 276c0496f..7ddd1ae03 100644 --- a/src/ui/redux/selectors/app.js +++ b/src/ui/redux/selectors/app.js @@ -123,3 +123,8 @@ export const selectSearchOptionsExpanded = createSelector( selectState, state => state.searchOptionsExpanded ); + +export const selectScrollStartingPosition = createSelector( + selectState, + state => state.currentScroll +);