Lidarr/frontend/src/Artist/Details/ArtistDetailsSeasonConnecto...

100 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-09-04 02:20:56 +00:00
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { findCommand } from 'Utilities/Command';
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
import createArtistSelector from 'Store/Selectors/createArtistSelector';
import createCommandsSelector from 'Store/Selectors/createCommandsSelector';
import { toggleEpisodesMonitored, setEpisodesTableOption } from 'Store/Actions/episodeActions';
import { executeCommand } from 'Store/Actions/commandActions';
import * as commandNames from 'Commands/commandNames';
import ArtistDetailsSeason from './ArtistDetailsSeason';
2017-09-04 02:20:56 +00:00
function createMapStateToProps() {
return createSelector(
(state, { label }) => label,
2017-09-04 02:20:56 +00:00
(state) => state.episodes,
createArtistSelector(),
createCommandsSelector(),
createDimensionsSelector(),
2017-10-07 22:38:31 +00:00
(label, episodes, artist, commands, dimensions) => {
2017-09-04 02:20:56 +00:00
const isSearching = !!findCommand(commands, {
name: commandNames.SEASON_SEARCH,
2017-10-07 22:38:31 +00:00
artistId: artist.id,
label
2017-09-04 02:20:56 +00:00
});
const episodesInSeason = _.filter(episodes.items, { albumType: label });
const sortedEpisodes = _.orderBy(episodesInSeason, 'releaseDate', 'desc');
2017-09-04 02:20:56 +00:00
return {
items: sortedEpisodes,
columns: episodes.columns,
isSearching,
2017-10-07 22:38:31 +00:00
artistMonitored: artist.monitored,
2017-09-04 02:20:56 +00:00
isSmallScreen: dimensions.isSmallScreen
};
}
);
}
const mapDispatchToProps = {
toggleEpisodesMonitored,
setEpisodesTableOption,
executeCommand
};
class ArtistDetailsSeasonConnector extends Component {
2017-09-04 02:20:56 +00:00
//
// Listeners
onTableOptionChange = (payload) => {
this.props.setEpisodesTableOption(payload);
}
onSearchPress = () => {
const {
artistId
2017-09-04 02:20:56 +00:00
} = this.props;
this.props.executeCommand({
name: commandNames.SEASON_SEARCH,
artistId
2017-09-04 02:20:56 +00:00
});
}
onMonitorAlbumPress = (albumIds, monitored) => {
2017-09-04 02:20:56 +00:00
this.props.toggleEpisodesMonitored({
albumIds,
2017-09-04 02:20:56 +00:00
monitored
});
}
//
// Render
render() {
return (
<ArtistDetailsSeason
2017-09-04 02:20:56 +00:00
{...this.props}
onTableOptionChange={this.onTableOptionChange}
onMonitorSeasonPress={this.onMonitorSeasonPress}
onSearchPress={this.onSearchPress}
onMonitorAlbumPress={this.onMonitorAlbumPress}
2017-09-04 02:20:56 +00:00
/>
);
}
}
ArtistDetailsSeasonConnector.propTypes = {
2017-09-04 02:20:56 +00:00
artistId: PropTypes.number.isRequired,
toggleEpisodesMonitored: PropTypes.func.isRequired,
setEpisodesTableOption: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(ArtistDetailsSeasonConnector);