Radarr/frontend/src/Components/withScrollPosition.js
Robin Dadswell d7ab9292fb
Fixed: restoring scroll position when going back to index page (#6308)
(cherry picked from commit 1bc52d0138c7bcb94ffce31ec05f675387612a62)

Co-authored-by: ta264 <ta264@users.noreply.github.com>
2021-05-12 12:36:20 +01:00

30 lines
687 B
JavaScript

import PropTypes from 'prop-types';
import React from 'react';
import scrollPositions from 'Store/scrollPositions';
function withScrollPosition(WrappedComponent, scrollPositionKey) {
function ScrollPosition(props) {
const {
history
} = props;
const scrollTop = history.action === 'POP' || (history.location.state && history.location.state.restoreScrollPosition) ?
scrollPositions[scrollPositionKey] :
0;
return (
<WrappedComponent
{...props}
scrollTop={scrollTop}
/>
);
}
ScrollPosition.propTypes = {
history: PropTypes.object.isRequired
};
return ScrollPosition;
}
export default withScrollPosition;