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-08-01 00:26:52 +02:00
|
|
|
import Immutable from "immutable";
|
2016-07-07 23:23:18 +02:00
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Local imports
|
2016-07-07 23:23:18 +02:00
|
|
|
import FilterablePaginatedGrid from "./elements/Grid";
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Paginated albums grid
|
|
|
|
*/
|
2016-07-07 23:23:18 +02:00
|
|
|
export default class Albums extends Component {
|
2016-08-10 23:50:23 +02:00
|
|
|
render() {
|
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
|
|
|
// Set grid props
|
2016-08-12 13:57:53 +02:00
|
|
|
const artists = this.props.artists;
|
2016-08-01 00:26:52 +02:00
|
|
|
const grid = {
|
|
|
|
isFetching: this.props.isFetching,
|
|
|
|
items: this.props.albums,
|
2016-08-02 13:07:12 +02:00
|
|
|
itemsType: "album",
|
2016-08-01 00:26:52 +02:00
|
|
|
itemsLabel: "app.common.album",
|
|
|
|
subItemsType: "tracks",
|
2016-08-10 23:50:23 +02:00
|
|
|
subItemsLabel: "app.common.track",
|
2016-08-12 13:57:53 +02:00
|
|
|
buildLinkTo: (itemType, item) => {
|
|
|
|
let artist = encodeURIComponent(item.get("artist"));
|
|
|
|
if (artists && artists.size > 0) {
|
|
|
|
const id = item.get("artist");
|
|
|
|
artist = encodeURIComponent(id + "-" + artists.getIn([id, "name"]));
|
|
|
|
}
|
|
|
|
return "/artist/" + artist + "/album/" + item.get("id") + "-" + encodeURIComponent(item.get("name"));
|
|
|
|
},
|
2016-08-01 00:26:52 +02:00
|
|
|
};
|
2016-08-10 21:36:11 +02:00
|
|
|
|
2016-07-07 23:23:18 +02:00
|
|
|
return (
|
2016-08-06 16:46:54 +02:00
|
|
|
<div>
|
|
|
|
{ error }
|
|
|
|
<FilterablePaginatedGrid grid={grid} pagination={this.props.pagination} />
|
|
|
|
</div>
|
2016-07-07 23:23:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Albums.propTypes = {
|
2016-08-06 16:46:54 +02:00
|
|
|
error: PropTypes.string,
|
2016-08-10 21:36:11 +02:00
|
|
|
isFetching: PropTypes.bool.isRequired,
|
2016-08-01 00:26:52 +02:00
|
|
|
albums: PropTypes.instanceOf(Immutable.List).isRequired,
|
2016-08-12 13:57:53 +02:00
|
|
|
artists: PropTypes.instanceOf(Immutable.Map),
|
2016-08-01 00:26:52 +02:00
|
|
|
pagination: PropTypes.object.isRequired,
|
2016-07-07 23:23:18 +02:00
|
|
|
};
|