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-11-01 11:49:04 +13:00
|
|
|
let helpers = require('../helpers.js')
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2016-11-01 11:49:04 +13:00
|
|
|
this.loadPlaylist();
|
2016-10-21 09:56:07 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
|
|
|
|
if( nextProps.params.uri != this.props.params.uri ){
|
2016-11-01 11:49:04 +13:00
|
|
|
this.loadPlaylist( nextProps )
|
|
|
|
|
}else if( !this.props.mopidy.connected && nextProps.mopidy.connected ){
|
|
|
|
|
if( helpers.uriSource( this.props.params.uri ) == 'm3u' ){
|
|
|
|
|
this.loadPlaylist( nextProps )
|
|
|
|
|
}
|
2016-10-21 09:56:07 +13:00
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-01 11:49:04 +13:00
|
|
|
loadPlaylist( props = this.props ){
|
|
|
|
|
var source = helpers.uriSource( props.params.uri );
|
|
|
|
|
if( source == 'spotify' ){
|
|
|
|
|
this.props.spotifyActions.getPlaylist( props.params.uri );
|
|
|
|
|
}else if( source == 'm3u' && props.mopidy.connected ){
|
|
|
|
|
this.props.mopidyActions.getPlaylist( props.params.uri );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderSpotifyPlaylist(){
|
|
|
|
|
if( this.props.spotify.playlist ){
|
2016-10-31 16:49:42 +13:00
|
|
|
var playlist = this.props.spotify.playlist;
|
2016-11-01 11:49:04 +13:00
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-11-01 11:49:04 +13:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderMopidyPlaylist(){
|
|
|
|
|
if( this.props.mopidy.playlist ){
|
|
|
|
|
var playlist = this.props.mopidy.playlist;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view playlist-view">
|
|
|
|
|
<div className="intro">
|
|
|
|
|
{ playlist.images ? <Thumbnail size="large" images={ playlist.images } /> : null }
|
|
|
|
|
<div className="details">
|
|
|
|
|
<div>Last updated { playlist.last_modified }</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="main">
|
|
|
|
|
<div className="title">
|
|
|
|
|
<h1>{ playlist.name }</h1>
|
|
|
|
|
</div>
|
|
|
|
|
<TrackList tracks={ playlist.tracks.items } />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
var source = helpers.uriSource( this.props.params.uri );
|
|
|
|
|
if( source == 'spotify' ) return this.renderSpotifyPlaylist();
|
|
|
|
|
if( source == 'm3u' ) return this.renderMopidyPlaylist();
|
2016-10-20 21:38:01 +13:00
|
|
|
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)
|