2016-08-10 21:36:11 +02:00
|
|
|
// NPM imports
|
2016-07-07 23:23:18 +02:00
|
|
|
import React, { Component, PropTypes } from "react";
|
2016-07-29 23:57:21 +02:00
|
|
|
import CSSModules from "react-css-modules";
|
2016-08-06 15:30:03 +02:00
|
|
|
import { defineMessages, FormattedMessage } from "react-intl";
|
|
|
|
import FontAwesome from "react-fontawesome";
|
|
|
|
import Immutable from "immutable";
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Local imports
|
2016-08-06 15:30:03 +02:00
|
|
|
import { messagesMap } from "../utils/";
|
2016-07-07 23:23:18 +02:00
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Other components
|
2016-07-07 23:23:18 +02:00
|
|
|
import { AlbumRow } from "./Album";
|
2016-08-06 16:46:54 +02:00
|
|
|
import DismissibleAlert from "./elements/DismissibleAlert";
|
2016-07-07 23:23:18 +02:00
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Translations
|
2016-08-06 15:30:03 +02:00
|
|
|
import commonMessages from "../locales/messagesDescriptors/common";
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Styles
|
2016-07-29 23:57:21 +02:00
|
|
|
import css from "../styles/Artist.scss";
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Define translations
|
2016-08-06 15:30:03 +02:00
|
|
|
const artistMessages = defineMessages(messagesMap(Array.concat([], commonMessages)));
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Single artist page
|
|
|
|
*/
|
2016-07-29 23:57:21 +02:00
|
|
|
class ArtistCSS extends Component {
|
2016-08-10 23:50:23 +02:00
|
|
|
render() {
|
2016-08-10 21:36:11 +02:00
|
|
|
// Define loading message
|
|
|
|
let loading = null;
|
|
|
|
if (this.props.isFetching) {
|
|
|
|
loading = (
|
|
|
|
<div className="row text-center">
|
|
|
|
<p>
|
|
|
|
<FontAwesome name="spinner" className="fa-pulse fa-3x fa-fw" aria-hidden="true" />
|
|
|
|
<span className="sr-only"><FormattedMessage {...artistMessages["app.common.loading"]} /></span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
2016-08-06 15:30:03 +02:00
|
|
|
}
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Handle error
|
2016-08-06 16:46:54 +02:00
|
|
|
let error = null;
|
|
|
|
if (this.props.error) {
|
|
|
|
error = (<DismissibleAlert type="danger" text={this.props.error} />);
|
|
|
|
}
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Build album rows
|
2016-08-05 00:00:25 +02:00
|
|
|
let albumsRows = [];
|
2016-08-07 00:58:36 +02:00
|
|
|
const { albums, songs, playAction } = this.props;
|
2016-08-10 21:36:11 +02:00
|
|
|
if (albums && songs) {
|
|
|
|
albums.forEach(function (album) {
|
2016-08-06 15:30:03 +02:00
|
|
|
const albumSongs = album.get("tracks").map(
|
|
|
|
id => songs.get(id)
|
2016-08-05 00:00:25 +02:00
|
|
|
);
|
2016-08-07 00:58:36 +02:00
|
|
|
albumsRows.push(<AlbumRow playAction={playAction} album={album} songs={albumSongs} key={album.get("id")} />);
|
2016-07-07 23:23:18 +02:00
|
|
|
});
|
|
|
|
}
|
2016-08-10 21:36:11 +02:00
|
|
|
|
2016-07-07 23:23:18 +02:00
|
|
|
return (
|
|
|
|
<div>
|
2016-08-06 16:46:54 +02:00
|
|
|
{ error }
|
2016-07-29 23:57:21 +02:00
|
|
|
<div className="row" styleName="name">
|
2016-07-27 13:51:30 +02:00
|
|
|
<div className="col-sm-12">
|
2016-08-05 00:00:25 +02:00
|
|
|
<h1>{this.props.artist.get("name")}</h1>
|
2016-07-07 23:23:18 +02:00
|
|
|
<hr/>
|
2016-07-27 13:51:30 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-sm-9">
|
2016-08-05 00:00:25 +02:00
|
|
|
<p>{this.props.artist.get("summary")}</p>
|
2016-07-07 23:23:18 +02:00
|
|
|
</div>
|
2016-07-27 13:51:30 +02:00
|
|
|
<div className="col-sm-3 text-center">
|
2016-08-05 00:00:25 +02:00
|
|
|
<p><img src={this.props.artist.get("art")} width="200" height="200" className="img-responsive img-circle" styleName="art" alt={this.props.artist.get("name")}/></p>
|
2016-07-07 23:23:18 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{ albumsRows }
|
2016-08-10 21:36:11 +02:00
|
|
|
{ loading }
|
2016-07-07 23:23:18 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-07-29 23:57:21 +02:00
|
|
|
ArtistCSS.propTypes = {
|
2016-08-06 16:46:54 +02:00
|
|
|
error: PropTypes.string,
|
2016-08-10 21:36:11 +02:00
|
|
|
isFetching: PropTypes.bool.isRequired,
|
|
|
|
playAction: PropTypes.func.isRequired,
|
2016-08-06 15:30:03 +02:00
|
|
|
artist: PropTypes.instanceOf(Immutable.Map),
|
2016-08-10 21:36:11 +02:00
|
|
|
albums: PropTypes.instanceOf(Immutable.List),
|
2016-08-10 23:50:23 +02:00
|
|
|
songs: PropTypes.instanceOf(Immutable.Map),
|
2016-07-07 23:23:18 +02:00
|
|
|
};
|
2016-07-29 23:57:21 +02:00
|
|
|
export default CSSModules(ArtistCSS, css);
|