mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Updated ScrollTop component so that it gets the window object injected as a dependency
This commit is contained in:
parent
16cf30f26f
commit
047d99be6d
4 changed files with 9 additions and 11 deletions
|
@ -4,6 +4,7 @@ module.exports = {
|
|||
'src/**/*.js',
|
||||
'!src/registerServiceWorker.js',
|
||||
'!src/index.js',
|
||||
'!src/reducers/index.js',
|
||||
'!src/**/provideServices.js',
|
||||
'!src/container/*.js',
|
||||
],
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
export default class ScrollToTop extends React.Component {
|
||||
const ScrollToTop = (window) => class ScrollToTop extends React.Component {
|
||||
static propTypes = {
|
||||
location: PropTypes.object,
|
||||
window: PropTypes.shape({
|
||||
scrollTo: PropTypes.func,
|
||||
}),
|
||||
children: PropTypes.node,
|
||||
};
|
||||
static defaultProps = {
|
||||
window: global.window,
|
||||
};
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { location, window } = this.props;
|
||||
const { location } = this.props;
|
||||
|
||||
if (location !== prevProps.location) {
|
||||
window.scrollTo(0, 0);
|
||||
|
@ -24,4 +18,6 @@ export default class ScrollToTop extends React.Component {
|
|||
render() {
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default ScrollToTop;
|
||||
|
|
|
@ -5,7 +5,9 @@ import MenuLayout from '../MenuLayout';
|
|||
import AsideMenu from '../AsideMenu';
|
||||
|
||||
const provideServices = (bottle, connect, withRouter) => {
|
||||
bottle.constant('ScrollToTop', ScrollToTop);
|
||||
bottle.constant('window', global.window);
|
||||
|
||||
bottle.serviceFactory('ScrollToTop', ScrollToTop, 'window');
|
||||
bottle.decorator('ScrollToTop', withRouter);
|
||||
|
||||
bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown');
|
||||
|
|
|
@ -29,7 +29,6 @@ const provideServices = (bottle, connect, withRouter) => {
|
|||
|
||||
// Services
|
||||
bottle.constant('csvjson', csvjson);
|
||||
bottle.constant('window', global.window);
|
||||
bottle.service('ServersImporter', ServersImporter, 'csvjson');
|
||||
bottle.service('ServersService', ServersService, 'Storage');
|
||||
bottle.service('ServersExporter', ServersExporter, 'ServersService', 'window', 'csvjson');
|
||||
|
|
Loading…
Reference in a new issue