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';
|
2017-09-12 03:11:32 +00:00
|
|
|
import { toggleSeasonMonitored } from 'Store/Actions/artistActions';
|
2017-09-04 02:20:56 +00:00
|
|
|
import { toggleEpisodesMonitored, setEpisodesTableOption } from 'Store/Actions/episodeActions';
|
|
|
|
import { executeCommand } from 'Store/Actions/commandActions';
|
|
|
|
import * as commandNames from 'Commands/commandNames';
|
2017-09-15 03:35:12 +00:00
|
|
|
import ArtistDetailsSeason from './ArtistDetailsSeason';
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
2017-09-15 03:35:12 +00:00
|
|
|
(state, { label }) => label,
|
2017-09-04 02:20:56 +00:00
|
|
|
(state) => state.episodes,
|
|
|
|
createArtistSelector(),
|
|
|
|
createCommandsSelector(),
|
|
|
|
createDimensionsSelector(),
|
2017-09-15 03:35:12 +00:00
|
|
|
(label, episodes, series, commands, dimensions) => {
|
2017-09-04 02:20:56 +00:00
|
|
|
const isSearching = !!findCommand(commands, {
|
|
|
|
name: commandNames.SEASON_SEARCH,
|
|
|
|
artistId: series.id,
|
2017-09-15 03:35:12 +00:00
|
|
|
label
|
2017-09-04 02:20:56 +00:00
|
|
|
});
|
|
|
|
|
2017-09-15 03:35:12 +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-09-15 03:35:12 +00:00
|
|
|
artistMonitored: series.monitored,
|
2017-09-04 02:20:56 +00:00
|
|
|
isSmallScreen: dimensions.isSmallScreen
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
toggleSeasonMonitored,
|
|
|
|
toggleEpisodesMonitored,
|
|
|
|
setEpisodesTableOption,
|
|
|
|
executeCommand
|
|
|
|
};
|
|
|
|
|
2017-09-15 03:35:12 +00:00
|
|
|
class ArtistDetailsSeasonConnector extends Component {
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
onTableOptionChange = (payload) => {
|
|
|
|
this.props.setEpisodesTableOption(payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
onMonitorSeasonPress = (monitored) => {
|
|
|
|
const {
|
2017-09-15 03:35:12 +00:00
|
|
|
artistId
|
2017-09-04 02:20:56 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
this.props.toggleSeasonMonitored({
|
|
|
|
artistId,
|
|
|
|
monitored
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSearchPress = () => {
|
|
|
|
const {
|
2017-09-15 03:35:12 +00:00
|
|
|
artistId
|
2017-09-04 02:20:56 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
this.props.executeCommand({
|
|
|
|
name: commandNames.SEASON_SEARCH,
|
2017-09-15 03:35:12 +00:00
|
|
|
artistId
|
2017-09-04 02:20:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-15 03:35:12 +00:00
|
|
|
onMonitorAlbumPress = (albumIds, monitored) => {
|
2017-09-04 02:20:56 +00:00
|
|
|
this.props.toggleEpisodesMonitored({
|
2017-09-15 03:35:12 +00:00
|
|
|
albumIds,
|
2017-09-04 02:20:56 +00:00
|
|
|
monitored
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2017-09-15 03:35:12 +00:00
|
|
|
<ArtistDetailsSeason
|
2017-09-04 02:20:56 +00:00
|
|
|
{...this.props}
|
|
|
|
onTableOptionChange={this.onTableOptionChange}
|
|
|
|
onMonitorSeasonPress={this.onMonitorSeasonPress}
|
|
|
|
onSearchPress={this.onSearchPress}
|
2017-09-15 03:35:12 +00:00
|
|
|
onMonitorAlbumPress={this.onMonitorAlbumPress}
|
2017-09-04 02:20:56 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 03:35:12 +00:00
|
|
|
ArtistDetailsSeasonConnector.propTypes = {
|
2017-09-04 02:20:56 +00:00
|
|
|
artistId: PropTypes.number.isRequired,
|
|
|
|
toggleSeasonMonitored: PropTypes.func.isRequired,
|
|
|
|
toggleEpisodesMonitored: PropTypes.func.isRequired,
|
|
|
|
setEpisodesTableOption: PropTypes.func.isRequired,
|
|
|
|
executeCommand: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2017-09-15 03:35:12 +00:00
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(ArtistDetailsSeasonConnector);
|