mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
Initial Commit Rework
This commit is contained in:
parent
74a4cc048c
commit
95051cbd63
2483 changed files with 101351 additions and 111396 deletions
160
frontend/src/Artist/Index/ArtistIndexConnector.js
Normal file
160
frontend/src/Artist/Index/ArtistIndexConnector.js
Normal file
|
@ -0,0 +1,160 @@
|
|||
import _ from 'lodash';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import dimensions from 'Styles/Variables/dimensions';
|
||||
import createCommandSelector from 'Store/Selectors/createCommandSelector';
|
||||
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||
import { fetchArtist } from 'Store/Actions/seriesActions';
|
||||
import scrollPositions from 'Store/scrollPositions';
|
||||
import { setArtistSort, setArtistFilter, setArtistView } from 'Store/Actions/artistIndexActions';
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
return scrollTop + padding;
|
||||
}
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
(state) => state.series,
|
||||
(state) => state.seriesIndex,
|
||||
createCommandSelector(commandNames.REFRESH_SERIES),
|
||||
createCommandSelector(commandNames.RSS_SYNC),
|
||||
createDimensionsSelector(),
|
||||
(series, seriesIndex, isRefreshingSeries, isRssSyncExecuting, dimensionsState) => {
|
||||
return {
|
||||
isRefreshingSeries,
|
||||
isRssSyncExecuting,
|
||||
isSmallScreen: dimensionsState.isSmallScreen,
|
||||
...series,
|
||||
...seriesIndex
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
fetchArtist,
|
||||
setArtistSort,
|
||||
setArtistFilter,
|
||||
setArtistView,
|
||||
executeCommand
|
||||
};
|
||||
|
||||
class ArtistIndexConnector extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
const {
|
||||
view,
|
||||
scrollTop,
|
||||
isSmallScreen
|
||||
} = props;
|
||||
|
||||
this.state = {
|
||||
scrollTop: getScrollTop(view, scrollTop, isSmallScreen)
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.fetchArtist();
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onSortSelect = (sortKey) => {
|
||||
this.props.setArtistSort({ sortKey });
|
||||
}
|
||||
|
||||
onFilterSelect = (filterKey, filterValue, filterType) => {
|
||||
this.props.setArtistFilter({ filterKey, filterValue, filterType });
|
||||
}
|
||||
|
||||
onViewSelect = (view) => {
|
||||
// Reset the scroll position before changing the view
|
||||
this.setState({ scrollTop: 0 }, () => {
|
||||
this.props.setArtistView({ view });
|
||||
});
|
||||
}
|
||||
|
||||
onScroll = ({ scrollTop }) => {
|
||||
this.setState({
|
||||
scrollTop
|
||||
}, () => {
|
||||
scrollPositions.seriesIndex = scrollTop;
|
||||
});
|
||||
}
|
||||
|
||||
onRefreshSeriesPress = () => {
|
||||
this.props.executeCommand({
|
||||
name: commandNames.REFRESH_SERIES
|
||||
});
|
||||
}
|
||||
|
||||
onRssSyncPress = () => {
|
||||
this.props.executeCommand({
|
||||
name: commandNames.RSS_SYNC
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
return (
|
||||
<ArtistIndex
|
||||
{...this.props}
|
||||
scrollTop={this.state.scrollTop}
|
||||
onSortSelect={this.onSortSelect}
|
||||
onFilterSelect={this.onFilterSelect}
|
||||
onViewSelect={this.onViewSelect}
|
||||
onScroll={this.onScroll}
|
||||
onRefreshSeriesPress={this.onRefreshSeriesPress}
|
||||
onRssSyncPress={this.onRssSyncPress}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ArtistIndexConnector.propTypes = {
|
||||
view: PropTypes.string.isRequired,
|
||||
scrollTop: PropTypes.number.isRequired,
|
||||
fetchArtist: PropTypes.func.isRequired,
|
||||
setArtistSort: PropTypes.func.isRequired,
|
||||
setArtistFilter: PropTypes.func.isRequired,
|
||||
setArtistView: PropTypes.func.isRequired,
|
||||
executeCommand: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default withScrollPosition(
|
||||
connect(createMapStateToProps, mapDispatchToProps)(ArtistIndexConnector),
|
||||
'seriesIndex'
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue