2016-10-03 14:44:27 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
import TrackList from '../components/TrackList'
|
2016-10-16 13:28:21 +13:00
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
2016-10-19 14:09:34 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
2016-10-03 14:44:27 +13:00
|
|
|
|
|
|
|
|
class Album extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// on render
|
|
|
|
|
componentDidMount(){
|
2016-10-20 21:38:01 +13:00
|
|
|
this.props.spotifyActions.getAlbum( this.props.params.uri );
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when props changed
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
2016-10-16 12:37:37 +13:00
|
|
|
if( nextProps.params.uri != this.props.params.uri ){
|
2016-10-20 21:38:01 +13:00
|
|
|
this.props.spotifyActions.getAlbum( nextProps.params.uri );
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 14:27:48 +13:00
|
|
|
render(){
|
2016-10-16 13:28:21 +13:00
|
|
|
if( this.props.spotify.album ){
|
2016-10-03 14:44:27 +13:00
|
|
|
return (
|
|
|
|
|
<div>
|
2016-10-16 13:28:21 +13:00
|
|
|
<h3>{ this.props.spotify.album.name }</h3>
|
2016-10-20 21:38:01 +13:00
|
|
|
<TrackList tracks={this.props.spotify.album.tracks.items} />
|
2016-10-03 14:44:27 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-10-19 14:09:34 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2016-10-16 13:28:21 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Album)
|