2017-12-17 05:49:47 +00:00
|
|
|
/* eslint max-params: 0 */
|
2017-09-04 02:20:56 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
2018-08-08 00:57:15 +00:00
|
|
|
import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector';
|
2017-09-04 02:20:56 +00:00
|
|
|
import dimensions from 'Styles/Variables/dimensions';
|
2018-08-31 03:07:50 +00:00
|
|
|
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
|
2017-09-04 02:20:56 +00:00
|
|
|
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
2017-09-12 03:11:32 +00:00
|
|
|
import { fetchArtist } from 'Store/Actions/artistActions';
|
2017-09-04 02:20:56 +00:00
|
|
|
import scrollPositions from 'Store/scrollPositions';
|
2019-02-23 22:39:11 +00:00
|
|
|
import { setArtistSort, setArtistFilter, setArtistView, setArtistTableOption } from 'Store/Actions/artistIndexActions';
|
2017-09-04 02:20:56 +00:00
|
|
|
import { executeCommand } from 'Store/Actions/commandActions';
|
|
|
|
import * as commandNames from 'Commands/commandNames';
|
|
|
|
import withScrollPosition from 'Components/withScrollPosition';
|
|
|
|
import ArtistIndex from './ArtistIndex';
|
|
|
|
|
|
|
|
const POSTERS_PADDING = 15;
|
|
|
|
const POSTERS_PADDING_SMALL_SCREEN = 5;
|
2017-09-17 06:24:15 +00:00
|
|
|
const BANNERS_PADDING = 15;
|
|
|
|
const BANNERS_PADDING_SMALL_SCREEN = 5;
|
2017-09-04 02:20:56 +00:00
|
|
|
const TABLE_PADDING = parseInt(dimensions.pageContentBodyPadding);
|
|
|
|
const TABLE_PADDING_SMALL_SCREEN = parseInt(dimensions.pageContentBodyPaddingSmallScreen);
|
|
|
|
|
|
|
|
// If the scrollTop is greater than zero it needs to be offset
|
|
|
|
// by the padding so when it is set initially so it is correct
|
|
|
|
// after React Virtualized takes the padding into account.
|
|
|
|
|
|
|
|
function getScrollTop(view, scrollTop, isSmallScreen) {
|
|
|
|
if (scrollTop === 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
let padding = isSmallScreen ? TABLE_PADDING_SMALL_SCREEN : TABLE_PADDING;
|
|
|
|
|
|
|
|
if (view === 'posters') {
|
|
|
|
padding = isSmallScreen ? POSTERS_PADDING_SMALL_SCREEN : POSTERS_PADDING;
|
|
|
|
}
|
|
|
|
|
2017-09-17 06:24:15 +00:00
|
|
|
if (view === 'banners') {
|
|
|
|
padding = isSmallScreen ? BANNERS_PADDING_SMALL_SCREEN : BANNERS_PADDING;
|
|
|
|
}
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
return scrollTop + padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
2018-08-08 00:57:15 +00:00
|
|
|
createClientSideCollectionSelector('artist', 'artistIndex'),
|
2018-08-31 03:07:50 +00:00
|
|
|
createCommandExecutingSelector(commandNames.REFRESH_ARTIST),
|
|
|
|
createCommandExecutingSelector(commandNames.RSS_SYNC),
|
2017-09-04 02:20:56 +00:00
|
|
|
createDimensionsSelector(),
|
2018-08-08 00:57:15 +00:00
|
|
|
(
|
|
|
|
artist,
|
|
|
|
isRefreshingArtist,
|
|
|
|
isRssSyncExecuting,
|
|
|
|
dimensionsState
|
|
|
|
) => {
|
2017-09-04 02:20:56 +00:00
|
|
|
return {
|
2018-08-08 00:57:15 +00:00
|
|
|
...artist,
|
2017-09-16 20:22:06 +00:00
|
|
|
isRefreshingArtist,
|
2017-09-04 02:20:56 +00:00
|
|
|
isRssSyncExecuting,
|
2018-08-08 00:57:15 +00:00
|
|
|
isSmallScreen: dimensionsState.isSmallScreen
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:39:11 +00:00
|
|
|
function createMapDispatchToProps(dispatch, props) {
|
|
|
|
return {
|
|
|
|
dispatchFetchArtist() {
|
|
|
|
dispatch(fetchArtist);
|
|
|
|
},
|
|
|
|
|
|
|
|
onTableOptionChange(payload) {
|
|
|
|
dispatch(setArtistTableOption(payload));
|
|
|
|
},
|
|
|
|
|
|
|
|
onSortSelect(sortKey) {
|
|
|
|
dispatch(setArtistSort({ sortKey }));
|
|
|
|
},
|
|
|
|
|
|
|
|
onFilterSelect(selectedFilterKey) {
|
|
|
|
dispatch(setArtistFilter({ selectedFilterKey }));
|
|
|
|
},
|
|
|
|
|
|
|
|
dispatchSetArtistView(view) {
|
|
|
|
dispatch(setArtistView({ view }));
|
|
|
|
},
|
|
|
|
|
|
|
|
onRefreshArtistPress() {
|
|
|
|
dispatch(executeCommand({
|
|
|
|
name: commandNames.REFRESH_ARTIST
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
onRssSyncPress() {
|
|
|
|
dispatch(executeCommand({
|
|
|
|
name: commandNames.RSS_SYNC
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
class ArtistIndexConnector extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
const {
|
|
|
|
view,
|
|
|
|
scrollTop,
|
|
|
|
isSmallScreen
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
scrollTop: getScrollTop(view, scrollTop, isSmallScreen)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-02-23 22:39:11 +00:00
|
|
|
this.props.dispatchFetchArtist();
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
onViewSelect = (view) => {
|
|
|
|
// Reset the scroll position before changing the view
|
|
|
|
this.setState({ scrollTop: 0 }, () => {
|
2019-02-23 22:39:11 +00:00
|
|
|
this.props.dispatchSetArtistView(view);
|
2017-09-04 02:20:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onScroll = ({ scrollTop }) => {
|
|
|
|
this.setState({
|
|
|
|
scrollTop
|
|
|
|
}, () => {
|
2017-09-16 20:22:06 +00:00
|
|
|
scrollPositions.artistIndex = scrollTop;
|
2017-09-04 02:20:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ArtistIndex
|
|
|
|
{...this.props}
|
|
|
|
scrollTop={this.state.scrollTop}
|
|
|
|
onViewSelect={this.onViewSelect}
|
|
|
|
onScroll={this.onScroll}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArtistIndexConnector.propTypes = {
|
2017-10-07 06:21:06 +00:00
|
|
|
isSmallScreen: PropTypes.bool.isRequired,
|
2017-09-04 02:20:56 +00:00
|
|
|
view: PropTypes.string.isRequired,
|
|
|
|
scrollTop: PropTypes.number.isRequired,
|
2019-02-23 22:39:11 +00:00
|
|
|
dispatchFetchArtist: PropTypes.func.isRequired
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default withScrollPosition(
|
2019-02-23 22:39:11 +00:00
|
|
|
connect(createMapStateToProps, createMapDispatchToProps)(ArtistIndexConnector),
|
2017-09-16 20:22:06 +00:00
|
|
|
'artistIndex'
|
2017-09-04 02:20:56 +00:00
|
|
|
);
|