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-07 00:58:36 +02:00
|
|
|
import { defineMessages, FormattedMessage, injectIntl, intlShape } from "react-intl";
|
2016-08-04 15:28:07 +02:00
|
|
|
import FontAwesome from "react-fontawesome";
|
2016-08-06 15:30:03 +02:00
|
|
|
import Immutable from "immutable";
|
2016-07-07 23:23:18 +02:00
|
|
|
|
2016-08-02 13:07:12 +02:00
|
|
|
import { formatLength, messagesMap } from "../utils";
|
|
|
|
|
|
|
|
import commonMessages from "../locales/messagesDescriptors/common";
|
2016-07-07 23:23:18 +02:00
|
|
|
|
2016-07-29 23:57:21 +02:00
|
|
|
import css from "../styles/Album.scss";
|
|
|
|
|
2016-08-06 16:46:54 +02:00
|
|
|
const albumMessages = defineMessages(messagesMap(Array.concat([], commonMessages)));
|
2016-08-02 13:07:12 +02:00
|
|
|
|
2016-08-07 00:58:36 +02:00
|
|
|
class AlbumTrackRowCSSIntl extends Component {
|
2016-07-07 23:23:18 +02:00
|
|
|
render () {
|
2016-08-07 00:58:36 +02:00
|
|
|
const { formatMessage } = this.props.intl;
|
2016-08-05 00:00:25 +02:00
|
|
|
const length = formatLength(this.props.track.get("time"));
|
2016-07-07 23:23:18 +02:00
|
|
|
return (
|
|
|
|
<tr>
|
2016-08-02 13:07:12 +02:00
|
|
|
<td>
|
2016-08-07 00:58:36 +02:00
|
|
|
<button styleName="play" title={formatMessage(albumMessages["app.common.play"])} onClick={() => this.props.playAction(this.props.track.get("id"))}>
|
2016-08-03 15:44:29 +02:00
|
|
|
<span className="sr-only">
|
|
|
|
<FormattedMessage {...albumMessages["app.common.play"]} />
|
|
|
|
</span>
|
2016-08-04 15:28:07 +02:00
|
|
|
<FontAwesome name="play-circle-o" aria-hidden="true" />
|
2016-08-03 15:44:29 +02:00
|
|
|
</button>
|
2016-08-02 13:07:12 +02:00
|
|
|
</td>
|
2016-08-05 00:00:25 +02:00
|
|
|
<td>{this.props.track.get("track")}</td>
|
|
|
|
<td>{this.props.track.get("name")}</td>
|
2016-07-07 23:23:18 +02:00
|
|
|
<td>{length}</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-07 00:58:36 +02:00
|
|
|
AlbumTrackRowCSSIntl.propTypes = {
|
|
|
|
playAction: PropTypes.func.isRequired,
|
|
|
|
track: PropTypes.instanceOf(Immutable.Map).isRequired,
|
|
|
|
intl: intlShape.isRequired
|
2016-07-07 23:23:18 +02:00
|
|
|
};
|
|
|
|
|
2016-08-07 00:58:36 +02:00
|
|
|
export let AlbumTrackRow = injectIntl(CSSModules(AlbumTrackRowCSSIntl, css));
|
2016-08-03 15:44:29 +02:00
|
|
|
|
2016-07-07 23:23:18 +02:00
|
|
|
|
2016-07-30 01:05:25 +02:00
|
|
|
class AlbumTracksTableCSS extends Component {
|
2016-07-07 23:23:18 +02:00
|
|
|
render () {
|
2016-08-05 00:00:25 +02:00
|
|
|
let rows = [];
|
2016-08-07 00:58:36 +02:00
|
|
|
const playAction = this.props.playAction;
|
2016-07-07 23:23:18 +02:00
|
|
|
this.props.tracks.forEach(function (item) {
|
2016-08-07 00:58:36 +02:00
|
|
|
rows.push(<AlbumTrackRow playAction={playAction} track={item} key={item.get("id")} />);
|
2016-07-07 23:23:18 +02:00
|
|
|
});
|
|
|
|
return (
|
2016-07-30 01:05:25 +02:00
|
|
|
<table className="table table-hover" styleName="songs">
|
2016-07-07 23:23:18 +02:00
|
|
|
<tbody>
|
|
|
|
{rows}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 01:05:25 +02:00
|
|
|
AlbumTracksTableCSS.propTypes = {
|
2016-08-07 00:58:36 +02:00
|
|
|
playAction: PropTypes.func.isRequired,
|
2016-08-06 15:30:03 +02:00
|
|
|
tracks: PropTypes.instanceOf(Immutable.List).isRequired
|
2016-07-07 23:23:18 +02:00
|
|
|
};
|
|
|
|
|
2016-07-30 01:05:25 +02:00
|
|
|
export let AlbumTracksTable = CSSModules(AlbumTracksTableCSS, css);
|
|
|
|
|
2016-07-29 23:57:21 +02:00
|
|
|
class AlbumRowCSS extends Component {
|
2016-07-07 23:23:18 +02:00
|
|
|
render () {
|
|
|
|
return (
|
2016-07-29 23:57:21 +02:00
|
|
|
<div className="row" styleName="row">
|
2016-08-03 15:44:29 +02:00
|
|
|
<div className="col-sm-offset-2 col-xs-9 col-sm-10" styleName="nameRow">
|
2016-08-05 00:00:25 +02:00
|
|
|
<h2>{this.props.album.get("name")}</h2>
|
2016-07-07 23:23:18 +02:00
|
|
|
</div>
|
2016-08-03 15:44:29 +02:00
|
|
|
<div className="col-xs-3 col-sm-2" styleName="artRow">
|
2016-08-05 00:00:25 +02:00
|
|
|
<p className="text-center"><img src={this.props.album.get("art")} width="200" height="200" className="img-responsive img-circle" styleName="art" alt={this.props.album.get("name")} /></p>
|
2016-07-27 13:51:30 +02:00
|
|
|
</div>
|
2016-08-03 15:44:29 +02:00
|
|
|
<div className="col-xs-9 col-sm-10 table-responsive">
|
2016-07-29 23:57:21 +02:00
|
|
|
{
|
2016-08-05 00:00:25 +02:00
|
|
|
this.props.songs.size > 0 ?
|
2016-08-07 00:58:36 +02:00
|
|
|
<AlbumTracksTable playAction={this.props.playAction} tracks={this.props.songs} /> :
|
2016-07-29 23:57:21 +02:00
|
|
|
null
|
|
|
|
}
|
2016-07-07 23:23:18 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 23:57:21 +02:00
|
|
|
AlbumRowCSS.propTypes = {
|
2016-08-07 00:58:36 +02:00
|
|
|
playAction: PropTypes.func.isRequired,
|
2016-08-06 15:30:03 +02:00
|
|
|
album: PropTypes.instanceOf(Immutable.Map).isRequired,
|
|
|
|
songs: PropTypes.instanceOf(Immutable.List).isRequired
|
2016-07-07 23:23:18 +02:00
|
|
|
};
|
|
|
|
|
2016-07-29 23:57:21 +02:00
|
|
|
export let AlbumRow = CSSModules(AlbumRowCSS, css);
|
|
|
|
|
2016-07-07 23:23:18 +02:00
|
|
|
export default class Album extends Component {
|
|
|
|
render () {
|
|
|
|
return (
|
2016-08-05 00:00:25 +02:00
|
|
|
<AlbumRow album={this.props.album} songs={this.props.songs} />
|
2016-07-07 23:23:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Album.propTypes = {
|
2016-08-06 15:30:03 +02:00
|
|
|
album: PropTypes.instanceOf(Immutable.Map).isRequired,
|
|
|
|
songs: PropTypes.instanceOf(Immutable.List).isRequired
|
2016-07-07 23:23:18 +02:00
|
|
|
};
|