mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-01-27 18:13:29 +01:00
25 lines
679 B
TypeScript
25 lines
679 B
TypeScript
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 initialScrollTop =
|
|
history.action === 'POP' ||
|
|
(history.location.state && history.location.state.restoreScrollPosition)
|
|
? scrollPositions[scrollPositionKey]
|
|
: 0;
|
|
|
|
return <WrappedComponent {...props} initialScrollTop={initialScrollTop} />;
|
|
}
|
|
|
|
ScrollPosition.propTypes = {
|
|
history: PropTypes.object.isRequired,
|
|
};
|
|
|
|
return ScrollPosition;
|
|
}
|
|
|
|
export default withScrollPosition;
|