2016-07-07 23:23:18 +02:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import { bindActionCreators } from "redux";
|
|
|
|
import { connect } from "react-redux";
|
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";
|
|
|
|
|
|
|
|
import Album from "../components/Album";
|
|
|
|
|
2016-08-03 15:44:29 +02:00
|
|
|
// TODO: AlbumPage should be scrolled ArtistPage
|
|
|
|
|
2016-07-07 23:23:18 +02:00
|
|
|
export class AlbumPage extends Component {
|
|
|
|
componentWillMount () {
|
|
|
|
// Load the data
|
|
|
|
this.props.actions.loadAlbums({
|
|
|
|
pageNumber: 1,
|
|
|
|
filter: this.props.params.id,
|
|
|
|
include: ["songs"]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-08-05 00:00:25 +02:00
|
|
|
if (this.props.album) {
|
2016-07-07 23:23:18 +02:00
|
|
|
return (
|
2016-08-05 00:00:25 +02:00
|
|
|
<Album album={this.props.album} songs={this.props.songs} />
|
2016-07-07 23:23:18 +02:00
|
|
|
);
|
|
|
|
}
|
2016-08-05 00:00:25 +02:00
|
|
|
return (
|
|
|
|
<div></div>
|
|
|
|
); // TODO: Loading
|
2016-07-07 23:23:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 00:00:25 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
const albums = state.api.entities.get("album");
|
|
|
|
let album = undefined;
|
|
|
|
let songs = new Immutable.List();
|
|
|
|
if (albums) {
|
|
|
|
// Get artist
|
|
|
|
album = albums.find(
|
|
|
|
item => item.get("id") == ownProps.params.id
|
|
|
|
);
|
|
|
|
// Get songs
|
|
|
|
const tracks = album.get("tracks");
|
|
|
|
if (Immutable.List.isList(tracks)) {
|
|
|
|
songs = new Immutable.Map(
|
|
|
|
tracks.map(
|
|
|
|
id => [id, state.api.entities.getIn(["track", id])]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
album: album,
|
|
|
|
songs: songs
|
|
|
|
};
|
|
|
|
};
|
2016-07-07 23:23:18 +02:00
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
actions: bindActionCreators(actionCreators, dispatch)
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AlbumPage);
|