2016-07-07 23:23:18 +02:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import { bindActionCreators } from "redux";
|
|
|
|
import { connect } from "react-redux";
|
2016-08-06 16:46:54 +02:00
|
|
|
import { defineMessages, injectIntl, intlShape } from "react-intl";
|
2016-08-05 00:00:25 +02:00
|
|
|
import Immutable from "immutable";
|
2016-07-07 23:23:18 +02:00
|
|
|
|
|
|
|
import * as actionCreators from "../actions";
|
2016-08-06 16:46:54 +02:00
|
|
|
import { messagesMap, handleErrorI18nObject } from "../utils";
|
2016-07-07 23:23:18 +02:00
|
|
|
|
|
|
|
import Artist from "../components/Artist";
|
|
|
|
|
2016-08-06 16:46:54 +02:00
|
|
|
import APIMessages from "../locales/messagesDescriptors/api";
|
|
|
|
|
|
|
|
const artistMessages = defineMessages(messagesMap(Array.concat([], APIMessages)));
|
|
|
|
|
|
|
|
class ArtistPageIntl extends Component {
|
2016-07-07 23:23:18 +02:00
|
|
|
componentWillMount () {
|
|
|
|
// Load the data
|
|
|
|
this.props.actions.loadArtists({
|
|
|
|
pageNumber: 1,
|
|
|
|
filter: this.props.params.id,
|
|
|
|
include: ["albums", "songs"]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-08-06 16:46:54 +02:00
|
|
|
const {formatMessage} = this.props.intl;
|
|
|
|
const error = handleErrorI18nObject(this.props.error, formatMessage, artistMessages);
|
2016-08-05 00:00:25 +02:00
|
|
|
return (
|
2016-08-06 16:46:54 +02:00
|
|
|
<Artist isFetching={this.props.isFetching} error={error} artist={this.props.artist} albums={this.props.albums} songs={this.props.songs} />
|
2016-08-06 15:30:03 +02:00
|
|
|
);
|
2016-07-07 23:23:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 00:00:25 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
const artists = state.api.entities.get("artist");
|
|
|
|
let artist = undefined;
|
2016-08-06 15:30:03 +02:00
|
|
|
let albums = new Immutable.Map();
|
|
|
|
let songs = new Immutable.Map();
|
2016-08-05 00:00:25 +02:00
|
|
|
if (artists) {
|
|
|
|
// Get artist
|
|
|
|
artist = artists.find(
|
|
|
|
item => item.get("id") == ownProps.params.id
|
|
|
|
);
|
|
|
|
// Get albums
|
|
|
|
const artistAlbums = artist.get("albums");
|
|
|
|
if (Immutable.List.isList(artistAlbums)) {
|
|
|
|
albums = new Immutable.Map(
|
|
|
|
artistAlbums.map(
|
|
|
|
id => [id, state.api.entities.getIn(["album", id])]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Get songs
|
|
|
|
const artistSongs = artist.get("songs");
|
|
|
|
if (Immutable.List.isList(artistSongs)) {
|
|
|
|
songs = new Immutable.Map(
|
|
|
|
artistSongs.map(
|
|
|
|
id => [id, state.api.entities.getIn(["track", id])]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
2016-08-06 15:30:03 +02:00
|
|
|
isFetching: state.api.isFetching,
|
2016-08-06 16:46:54 +02:00
|
|
|
error: state.api.error,
|
2016-08-05 00:00:25 +02:00
|
|
|
artist: artist,
|
|
|
|
albums: albums,
|
|
|
|
songs: songs
|
|
|
|
};
|
|
|
|
};
|
2016-07-07 23:23:18 +02:00
|
|
|
|
2016-08-06 16:46:54 +02:00
|
|
|
ArtistPageIntl.propTypes = {
|
|
|
|
intl: intlShape.isRequired,
|
|
|
|
};
|
|
|
|
|
2016-07-07 23:23:18 +02:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
actions: bindActionCreators(actionCreators, dispatch)
|
|
|
|
});
|
|
|
|
|
2016-08-06 16:46:54 +02:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(ArtistPageIntl));
|