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';
|
2017-12-30 03:23:04 +00:00
|
|
|
import createArtistSelector from 'Store/Selectors/createArtistSelector';
|
2019-04-14 02:08:35 +00:00
|
|
|
import createExecutingCommandsSelector from 'Store/Selectors/createExecutingCommandsSelector';
|
2019-04-28 03:45:59 +00:00
|
|
|
import createArtistQualityProfileSelector from 'Store/Selectors/createArtistQualityProfileSelector';
|
|
|
|
import createArtistMetadataProfileSelector from 'Store/Selectors/createArtistMetadataProfileSelector';
|
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(),
|
2019-04-28 03:45:59 +00:00
|
|
|
createArtistQualityProfileSelector(),
|
|
|
|
createArtistMetadataProfileSelector(),
|
2018-11-11 04:08:31 +00:00
|
|
|
selectShowSearchAction(),
|
2019-04-06 03:03:42 +00:00
|
|
|
createExecutingCommandsSelector(),
|
2018-11-11 04:08:31 +00:00
|
|
|
(
|
|
|
|
artist,
|
|
|
|
qualityProfile,
|
|
|
|
metadataProfile,
|
|
|
|
showSearchAction,
|
2019-04-06 03:03:42 +00:00
|
|
|
executingCommands
|
2018-11-11 04:08:31 +00:00
|
|
|
) => {
|
2019-04-06 03:08:07 +00:00
|
|
|
|
|
|
|
// If an artist is deleted this selector may fire before the parent
|
|
|
|
// selectors, which will result in an undefined artist, if that happens
|
|
|
|
// we want to return early here and again in the render function to avoid
|
|
|
|
// trying to show an artist that has no information available.
|
|
|
|
|
|
|
|
if (!artist) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-04-06 03:03:42 +00:00
|
|
|
const isRefreshingArtist = executingCommands.some((command) => {
|
2018-09-05 02:40:26 +00:00
|
|
|
return (
|
|
|
|
command.name === commandNames.REFRESH_ARTIST &&
|
2019-04-06 03:03:42 +00:00
|
|
|
command.body.artistId === artist.id
|
2018-09-05 02:40:26 +00:00
|
|
|
);
|
2017-09-04 02:20:56 +00:00
|
|
|
});
|
|
|
|
|
2019-04-06 03:03:42 +00:00
|
|
|
const isSearchingArtist = executingCommands.some((command) => {
|
2018-11-11 04:08:31 +00:00
|
|
|
return (
|
|
|
|
command.name === commandNames.ARTIST_SEARCH &&
|
2019-04-06 03:03:42 +00:00
|
|
|
command.body.artistId === artist.id
|
2018-11-11 04:08:31 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
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,
|
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 = {
|
2019-04-28 03:45:59 +00:00
|
|
|
dispatchExecuteCommand: executeCommand
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ArtistIndexItemConnector extends Component {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
2017-09-12 03:11:32 +00:00
|
|
|
onRefreshArtistPress = () => {
|
2019-04-28 03:45:59 +00:00
|
|
|
this.props.dispatchExecuteCommand({
|
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 = () => {
|
2019-04-28 03:45:59 +00:00
|
|
|
this.props.dispatchExecuteCommand({
|
2018-11-11 04:08:31 +00:00
|
|
|
name: commandNames.ARTIST_SEARCH,
|
|
|
|
artistId: this.props.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2019-04-06 03:08:07 +00:00
|
|
|
id,
|
2017-09-04 02:20:56 +00:00
|
|
|
component: ItemComponent,
|
|
|
|
...otherProps
|
|
|
|
} = this.props;
|
|
|
|
|
2019-04-06 03:08:07 +00:00
|
|
|
if (!id) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
return (
|
|
|
|
<ItemComponent
|
|
|
|
{...otherProps}
|
2019-04-06 03:08:07 +00:00
|
|
|
id={id}
|
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 = {
|
2019-04-06 03:08:07 +00:00
|
|
|
id: PropTypes.number,
|
2019-08-05 00:44:34 +00:00
|
|
|
component: PropTypes.elementType.isRequired,
|
2019-04-28 03:45:59 +00:00
|
|
|
dispatchExecuteCommand: PropTypes.func.isRequired
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(ArtistIndexItemConnector);
|