2017-12-17 05:49:47 +00:00
|
|
|
/* eslint max-params: 0 */
|
2017-09-04 02:20:56 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
2018-09-05 02:40:26 +00:00
|
|
|
import { isCommandExecuting } from 'Utilities/Command';
|
2017-12-30 03:23:04 +00:00
|
|
|
import createArtistSelector from 'Store/Selectors/createArtistSelector';
|
2017-09-04 02:20:56 +00:00
|
|
|
import createCommandsSelector from 'Store/Selectors/createCommandsSelector';
|
|
|
|
import createQualityProfileSelector from 'Store/Selectors/createQualityProfileSelector';
|
|
|
|
import createLanguageProfileSelector from 'Store/Selectors/createLanguageProfileSelector';
|
2017-11-26 03:51:37 +00:00
|
|
|
import createMetadataProfileSelector from 'Store/Selectors/createMetadataProfileSelector';
|
2017-09-04 02:20:56 +00:00
|
|
|
import { executeCommand } from 'Store/Actions/commandActions';
|
|
|
|
import * as commandNames from 'Commands/commandNames';
|
|
|
|
|
2018-11-11 04:08:31 +00:00
|
|
|
function selectShowSearchAction() {
|
|
|
|
return createSelector(
|
|
|
|
(state) => state.artistIndex,
|
|
|
|
(artistIndex) => {
|
|
|
|
const view = artistIndex.view;
|
|
|
|
|
|
|
|
switch (view) {
|
|
|
|
case 'posters':
|
|
|
|
return artistIndex.posterOptions.showSearchAction;
|
|
|
|
case 'banners':
|
|
|
|
return artistIndex.bannerOptions.showSearchAction;
|
|
|
|
case 'overview':
|
|
|
|
return artistIndex.overviewOptions.showSearchAction;
|
|
|
|
default:
|
|
|
|
return artistIndex.tableOptions.showSearchAction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
2017-12-30 03:23:04 +00:00
|
|
|
createArtistSelector(),
|
2017-09-04 02:20:56 +00:00
|
|
|
createQualityProfileSelector(),
|
|
|
|
createLanguageProfileSelector(),
|
2017-11-26 03:51:37 +00:00
|
|
|
createMetadataProfileSelector(),
|
2018-11-11 04:08:31 +00:00
|
|
|
selectShowSearchAction(),
|
2017-09-04 02:20:56 +00:00
|
|
|
createCommandsSelector(),
|
2018-11-11 04:08:31 +00:00
|
|
|
(
|
|
|
|
artist,
|
|
|
|
qualityProfile,
|
|
|
|
languageProfile,
|
|
|
|
metadataProfile,
|
|
|
|
showSearchAction,
|
|
|
|
commands
|
|
|
|
) => {
|
2018-09-05 02:40:26 +00:00
|
|
|
const isRefreshingArtist = commands.some((command) => {
|
|
|
|
return (
|
|
|
|
command.name === commandNames.REFRESH_ARTIST &&
|
|
|
|
command.body.artistId === artist.id &&
|
|
|
|
isCommandExecuting(command)
|
|
|
|
);
|
2017-09-04 02:20:56 +00:00
|
|
|
});
|
|
|
|
|
2018-11-11 04:08:31 +00:00
|
|
|
const isSearchingArtist = commands.some((command) => {
|
|
|
|
return (
|
|
|
|
command.name === commandNames.ARTIST_SEARCH &&
|
|
|
|
command.body.artistId === artist.id &&
|
|
|
|
isCommandExecuting(command)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-12-30 03:23:04 +00:00
|
|
|
const latestAlbum = _.maxBy(artist.albums, (album) => album.releaseDate);
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
return {
|
2017-12-30 03:23:04 +00:00
|
|
|
...artist,
|
2017-09-04 02:20:56 +00:00
|
|
|
qualityProfile,
|
|
|
|
languageProfile,
|
2017-11-26 03:51:37 +00:00
|
|
|
metadataProfile,
|
2017-09-16 20:22:06 +00:00
|
|
|
latestAlbum,
|
2018-11-11 04:08:31 +00:00
|
|
|
showSearchAction,
|
|
|
|
isRefreshingArtist,
|
|
|
|
isSearchingArtist
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
executeCommand
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArtistIndexItemConnector extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
2017-09-12 03:11:32 +00:00
|
|
|
onRefreshArtistPress = () => {
|
2017-09-04 02:20:56 +00:00
|
|
|
this.props.executeCommand({
|
2017-09-12 03:11:32 +00:00
|
|
|
name: commandNames.REFRESH_ARTIST,
|
2017-09-04 02:20:56 +00:00
|
|
|
artistId: this.props.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-11 04:08:31 +00:00
|
|
|
onSearchPress = () => {
|
|
|
|
this.props.executeCommand({
|
|
|
|
name: commandNames.ARTIST_SEARCH,
|
|
|
|
artistId: this.props.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
component: ItemComponent,
|
|
|
|
...otherProps
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ItemComponent
|
|
|
|
{...otherProps}
|
2017-09-12 03:11:32 +00:00
|
|
|
onRefreshArtistPress={this.onRefreshArtistPress}
|
2018-11-11 04:08:31 +00:00
|
|
|
onSearchPress={this.onSearchPress}
|
2017-09-04 02:20:56 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArtistIndexItemConnector.propTypes = {
|
|
|
|
id: PropTypes.number.isRequired,
|
|
|
|
component: PropTypes.func.isRequired,
|
|
|
|
executeCommand: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(ArtistIndexItemConnector);
|