You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/frontend/src/Artist/Details/ArtistDetailsSeasonConnecto...

100 lines
2.9 KiB

/* eslint max-params: 0 */
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
4 years ago
import { setAlbumsSort, setAlbumsTableOption, toggleAlbumsMonitored } from 'Store/Actions/albumActions';
import { executeCommand } from 'Store/Actions/commandActions';
import createArtistSelector from 'Store/Selectors/createArtistSelector';
import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector';
4 years ago
import createCommandsSelector from 'Store/Selectors/createCommandsSelector';
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector';
import ArtistDetailsSeason from './ArtistDetailsSeason';
function createMapStateToProps() {
return createSelector(
(state, { label }) => label,
createClientSideCollectionSelector('albums'),
createArtistSelector(),
createCommandsSelector(),
createDimensionsSelector(),
createUISettingsSelector(),
(label, albums, artist, commands, dimensions, uiSettings) => {
const albumsInGroup = _.filter(albums.items, { albumType: label });
let sortDir = 'asc';
if (albums.sortDirection === 'descending') {
sortDir = 'desc';
}
const sortedAlbums = _.orderBy(albumsInGroup, albums.sortKey, sortDir);
return {
items: sortedAlbums,
columns: albums.columns,
artistMonitored: artist.monitored,
sortKey: albums.sortKey,
sortDirection: albums.sortDirection,
isSmallScreen: dimensions.isSmallScreen,
uiSettings
};
}
);
}
const mapDispatchToProps = {
toggleAlbumsMonitored,
setAlbumsTableOption,
dispatchSetAlbumSort: setAlbumsSort,
executeCommand
};
class ArtistDetailsSeasonConnector extends Component {
//
// Listeners
onTableOptionChange = (payload) => {
this.props.setAlbumsTableOption(payload);
};
onSortPress = (sortKey) => {
this.props.dispatchSetAlbumSort({ sortKey });
};
onMonitorAlbumsPress = (albumIds, monitored) => {
this.props.toggleAlbumsMonitored({
albumIds,
monitored
});
};
//
// Render
render() {
return (
<ArtistDetailsSeason
{...this.props}
onSortPress={this.onSortPress}
onTableOptionChange={this.onTableOptionChange}
onMonitorAlbumsPress={this.onMonitorAlbumsPress}
/>
);
}
}
ArtistDetailsSeasonConnector.propTypes = {
artistId: PropTypes.number.isRequired,
toggleAlbumsMonitored: PropTypes.func.isRequired,
setAlbumsTableOption: PropTypes.func.isRequired,
dispatchSetAlbumSort: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(ArtistDetailsSeasonConnector);