You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/frontend/src/Album/AlbumSearchCellConnector.js

47 lines
1.3 KiB

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 AlbumSearchCell from './AlbumSearchCell';
function createMapStateToProps() {
return createSelector(
(state, { albumId }) => albumId,
createArtistSelector(),
createCommandsSelector(),
(albumId, artist, commands) => {
const isSearching = _.some(commands, (command) => {
const albumSearch = command.name === commandNames.ALBUM_SEARCH;
if (!albumSearch) {
return false;
}
return command.body.albumIds.indexOf(albumId) > -1;
});
return {
artistMonitored: artist.monitored,
artistType: artist.artistType,
isSearching
};
}
);
}
function createMapDispatchToProps(dispatch, props) {
return {
onSearchPress(name, path) {
dispatch(executeCommand({
name: commandNames.ALBUM_SEARCH,
albumIds: [props.albumId]
}));
}
};
}
export default connect(createMapStateToProps, createMapDispatchToProps)(AlbumSearchCell);