add scroll selector

This commit is contained in:
Sean Yesmunt 2019-07-22 19:43:30 -04:00
parent ab068bc66f
commit 0b841bf268
4 changed files with 10 additions and 4 deletions

View file

@ -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);

View file

@ -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';
}

View file

@ -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();

View file

@ -123,3 +123,8 @@ export const selectSearchOptionsExpanded = createSelector(
selectState,
state => state.searchOptionsExpanded
);
export const selectScrollStartingPosition = createSelector(
selectState,
state => state.currentScroll
);