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';
|
|
|
|
import { push } from 'react-router-redux';
|
2017-09-12 03:11:32 +00:00
|
|
|
import createAllArtistSelector from 'Store/Selectors/createAllArtistSelector';
|
2017-09-04 02:20:56 +00:00
|
|
|
import NotFound from 'Components/NotFound';
|
2017-09-15 03:35:12 +00:00
|
|
|
import ArtistDetailsConnector from './ArtistDetailsConnector';
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
|
|
|
(state, { match }) => match,
|
2017-09-12 03:11:32 +00:00
|
|
|
createAllArtistSelector(),
|
2017-09-16 20:22:06 +00:00
|
|
|
(match, allArtists) => {
|
2018-01-18 02:28:47 +00:00
|
|
|
const foreignArtistId = match.params.foreignArtistId;
|
|
|
|
const artistIndex = _.findIndex(allArtists, { foreignArtistId });
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2017-09-16 20:22:06 +00:00
|
|
|
if (artistIndex > -1) {
|
2017-09-04 02:20:56 +00:00
|
|
|
return {
|
2018-01-18 02:28:47 +00:00
|
|
|
foreignArtistId
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
push
|
|
|
|
};
|
|
|
|
|
2017-09-15 03:35:12 +00:00
|
|
|
class ArtistDetailsPageConnector extends Component {
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
2018-01-18 02:28:47 +00:00
|
|
|
if (!this.props.foreignArtistId) {
|
2018-01-26 03:01:53 +00:00
|
|
|
this.props.push(`${window.Lidarr.urlBase}/`);
|
2017-09-04 02:20:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2018-01-18 02:28:47 +00:00
|
|
|
foreignArtistId
|
2017-09-04 02:20:56 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2018-01-18 02:28:47 +00:00
|
|
|
if (!foreignArtistId) {
|
2017-09-04 02:20:56 +00:00
|
|
|
return (
|
|
|
|
<NotFound
|
2017-10-07 22:38:31 +00:00
|
|
|
message="Sorry, that artist cannot be found."
|
2017-09-04 02:20:56 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-09-15 03:35:12 +00:00
|
|
|
<ArtistDetailsConnector
|
2018-01-18 02:28:47 +00:00
|
|
|
foreignArtistId={foreignArtistId}
|
2017-09-04 02:20:56 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 03:35:12 +00:00
|
|
|
ArtistDetailsPageConnector.propTypes = {
|
2018-01-18 02:28:47 +00:00
|
|
|
foreignArtistId: PropTypes.string,
|
|
|
|
match: PropTypes.shape({ params: PropTypes.shape({ foreignArtistId: PropTypes.string.isRequired }).isRequired }).isRequired,
|
2017-09-04 02:20:56 +00:00
|
|
|
push: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2017-09-15 03:35:12 +00:00
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(ArtistDetailsPageConnector);
|