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';
|
2018-01-01 06:05:24 +00:00
|
|
|
import AlbumSearchCell from './AlbumSearchCell';
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
2017-10-07 02:28:30 +00:00
|
|
|
(state, { albumId }) => albumId,
|
2017-09-04 02:20:56 +00:00
|
|
|
createArtistSelector(),
|
|
|
|
createCommandsSelector(),
|
2018-01-26 03:01:53 +00:00
|
|
|
(albumId, artist, commands) => {
|
2017-09-04 02:20:56 +00:00
|
|
|
const isSearching = _.some(commands, (command) => {
|
2018-01-01 06:05:24 +00:00
|
|
|
const albumSearch = command.name === commandNames.ALBUM_SEARCH;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2018-01-01 06:05:24 +00:00
|
|
|
if (!albumSearch) {
|
2017-09-04 02:20:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-07 02:28:30 +00:00
|
|
|
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({
|
2017-10-29 01:44:06 +00:00
|
|
|
name: commandNames.ALBUM_SEARCH,
|
2017-10-07 02:28:30 +00:00
|
|
|
albumIds: [props.albumId]
|
2017-09-04 02:20:56 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-01 06:05:24 +00:00
|
|
|
export default connect(createMapStateToProps, createMapDispatchToProps)(AlbumSearchCell);
|