Lidarr/frontend/src/Album/EpisodeSearchCellConnector.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-09-04 02:20:56 +00:00
import _ from 'lodash';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import createArtistSelector from 'Store/Selectors/createArtistSelector';
import createCommandsSelector from 'Store/Selectors/createCommandsSelector';
import { executeCommand } from 'Store/Actions/commandActions';
import * as commandNames from 'Commands/commandNames';
import EpisodeSearchCell from './EpisodeSearchCell';
function createMapStateToProps() {
return createSelector(
(state, { albumId }) => albumId,
2017-09-04 02:20:56 +00:00
(state, { sceneSeasonNumber }) => sceneSeasonNumber,
createArtistSelector(),
createCommandsSelector(),
2017-10-07 22:38:31 +00:00
(albumId, sceneSeasonNumber, artist, commands) => {
2017-09-04 02:20:56 +00:00
const isSearching = _.some(commands, (command) => {
const episodeSearch = command.name === commandNames.ALBUM_SEARCH;
2017-09-04 02:20:56 +00:00
if (!episodeSearch) {
return false;
}
return command.body.albumIds.indexOf(albumId) > -1;
2017-09-04 02:20:56 +00:00
});
return {
2017-10-07 22:38:31 +00:00
artistMonitored: artist.monitored,
artistType: artist.artistType,
2017-09-04 02:20:56 +00:00
isSearching
};
}
);
}
function createMapDispatchToProps(dispatch, props) {
return {
onSearchPress(name, path) {
dispatch(executeCommand({
name: commandNames.ALBUM_SEARCH,
albumIds: [props.albumId]
2017-09-04 02:20:56 +00:00
}));
}
};
}
export default connect(createMapStateToProps, createMapDispatchToProps)(EpisodeSearchCell);