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-31 16:49:42 +13:00
|
|
|
import Thumbnail from '../components/Thumbnail'
|
|
|
|
|
import Dater from '../components/Dater'
|
2016-10-23 23:48:06 +13:00
|
|
|
|
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
|
|
|
|
2016-10-31 16:49:42 +13:00
|
|
|
var playlist = this.props.spotify.playlist;
|
2016-10-27 10:02:12 +13:00
|
|
|
var context = null;
|
2016-10-31 16:49:42 +13:00
|
|
|
if( playlist.owner.id == this.props.spotify.me.id ) context = 'editable-playlist'
|
2016-10-27 10:02:12 +13:00
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
return (
|
2016-10-26 16:55:47 +13:00
|
|
|
<div className="view playlist-view">
|
2016-10-31 16:49:42 +13:00
|
|
|
<div className="intro">
|
|
|
|
|
<Thumbnail size="large" images={ playlist.images } />
|
|
|
|
|
<div className="details">
|
|
|
|
|
<div>{ playlist.tracks.total } tracks</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="main">
|
|
|
|
|
<div className="title">
|
|
|
|
|
<h1>{ playlist.name }</h1>
|
|
|
|
|
</div>
|
|
|
|
|
<TrackList context={context} tracks={ playlist.tracks.items } />
|
|
|
|
|
</div>
|
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)
|