Lidarr/frontend/src/Album/AlbumSearchCellConnector.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-09-04 02:20:56 +00:00
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { isCommandExecuting } from 'Utilities/Command';
2017-09-04 02:20:56 +00:00
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 AlbumSearchCell from './AlbumSearchCell';
2017-09-04 02:20:56 +00:00
function createMapStateToProps() {
return createSelector(
(state, { albumId }) => albumId,
2017-09-04 02:20:56 +00:00
createArtistSelector(),
createCommandsSelector(),
(albumId, artist, commands) => {
const isSearching = commands.some((command) => {
const albumSearch = command.name === commandNames.ALBUM_SEARCH;
2017-09-04 02:20:56 +00:00
if (!albumSearch) {
2017-09-04 02:20:56 +00:00
return false;
}
return (
isCommandExecuting(command) &&
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)(AlbumSearchCell);