sonarr-repo-only/frontend/src/Episode/EpisodeSearchCellConnector.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-01-13 02:01:27 +00:00
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import * as commandNames from 'Commands/commandNames';
2022-05-20 04:15:43 +00:00
import { executeCommand } from 'Store/Actions/commandActions';
import createCommandsSelector from 'Store/Selectors/createCommandsSelector';
import createSeriesSelector from 'Store/Selectors/createSeriesSelector';
import { isCommandExecuting } from 'Utilities/Command';
2018-01-13 02:01:27 +00:00
import EpisodeSearchCell from './EpisodeSearchCell';
function createMapStateToProps() {
return createSelector(
(state, { episodeId }) => episodeId,
(state, { sceneSeasonNumber }) => sceneSeasonNumber,
createSeriesSelector(),
createCommandsSelector(),
(episodeId, sceneSeasonNumber, series, commands) => {
const isSearching = commands.some((command) => {
const episodeSearch = command.name === commandNames.EPISODE_SEARCH;
if (!episodeSearch) {
return false;
}
return (
isCommandExecuting(command) &&
command.body.episodeIds.indexOf(episodeId) > -1
);
});
return {
seriesMonitored: series.monitored,
seriesType: series.seriesType,
isSearching
};
}
);
}
function createMapDispatchToProps(dispatch, props) {
return {
onSearchPress(name, path) {
dispatch(executeCommand({
name: commandNames.EPISODE_SEARCH,
episodeIds: [props.episodeId]
}));
}
};
}
export default connect(createMapStateToProps, createMapDispatchToProps)(EpisodeSearchCell);