2016-10-20 21:38:01 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
|
|
|
|
|
import TrackList from '../components/TrackList'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../components/Header'
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
2016-10-21 09:56:07 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
2016-10-20 21:38:01 +13:00
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
class Playlist extends React.Component{
|
2016-10-20 21:38:01 +13:00
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// on render
|
|
|
|
|
componentDidMount(){
|
2016-10-21 09:56:07 +13:00
|
|
|
this.props.spotifyActions.getPlaylist( this.props.params.uri );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when props changed
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
|
|
|
|
if( nextProps.params.uri != this.props.params.uri ){
|
|
|
|
|
this.props.spotifyActions.getPlaylist( nextProps.params.uri );
|
|
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
2016-10-21 09:56:07 +13:00
|
|
|
if( this.props.spotify.playlist ){
|
2016-10-27 10:02:12 +13:00
|
|
|
|
|
|
|
|
var context = null;
|
|
|
|
|
if( this.props.spotify.playlist.owner.id == this.props.spotify.me.id ) context = 'editable-playlist'
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
return (
|
2016-10-26 16:55:47 +13:00
|
|
|
<div className="view playlist-view">
|
2016-10-24 21:26:01 +13:00
|
|
|
<Header icon="playlist" title={ this.props.spotify.playlist.name } />
|
2016-10-27 10:02:12 +13:00
|
|
|
<TrackList context={context} tracks={this.props.spotify.playlist.tracks.items} />
|
2016-10-20 21:38:01 +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 {
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Playlist)
|