2016-10-20 21:38:01 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-11-02 16:51:00 +13:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
2016-11-01 13:19:51 +13:00
|
|
|
let helpers = require('../helpers.js')
|
2016-10-20 21:38:01 +13:00
|
|
|
|
|
|
|
|
import TrackList from '../components/TrackList'
|
2016-10-31 16:49:42 +13:00
|
|
|
import Thumbnail from '../components/Thumbnail'
|
|
|
|
|
import Dater from '../components/Dater'
|
2016-11-07 18:09:42 +13:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener'
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:09:42 +13:00
|
|
|
loadMore(){
|
|
|
|
|
if( !this.props.spotify.playlist || !this.props.spotify.playlist.tracks.next ) return
|
|
|
|
|
this.props.spotifyActions.getURL( this.props.spotify.playlist.tracks.next, 'SPOTIFY_PLAYLIST_LOADED_MORE' );
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 13:19:51 +13:00
|
|
|
render(){
|
|
|
|
|
var source = helpers.uriSource( this.props.params.uri );
|
2016-11-07 21:21:15 +13:00
|
|
|
var source_name = source
|
|
|
|
|
if( source == 'spotify' ){
|
|
|
|
|
var playlist = this.props.spotify.playlist
|
|
|
|
|
}else if( source == 'm3u' ){
|
|
|
|
|
var playlist = this.props.mopidy.playlist
|
|
|
|
|
source_name = 'local'
|
|
|
|
|
}
|
2016-11-01 13:19:51 +13:00
|
|
|
if( !playlist ) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view playlist-view">
|
|
|
|
|
<div className="intro">
|
|
|
|
|
{ playlist.images ? <Thumbnail size="large" images={ playlist.images } /> : null }
|
2016-11-02 16:51:00 +13:00
|
|
|
<ul className="details">
|
2016-11-02 21:23:35 +13:00
|
|
|
<li>{ playlist.tracks.total } tracks, <Dater type="total-time" data={playlist.tracks.items} /></li>
|
|
|
|
|
{ playlist.last_modified ? <li>Updated <Dater type="ago" data={playlist.last_modified} /> ago</li> : null }
|
2016-11-07 21:21:15 +13:00
|
|
|
<li><FontAwesome name={helpers.sourceIcon( this.props.params.uri )} /> {source_name} playlist</li>
|
2016-11-02 16:51:00 +13:00
|
|
|
</ul>
|
2016-10-20 21:38:01 +13:00
|
|
|
</div>
|
2016-11-01 13:19:51 +13:00
|
|
|
<div className="main">
|
2016-11-07 21:21:15 +13:00
|
|
|
|
2016-11-01 13:19:51 +13:00
|
|
|
<div className="title">
|
|
|
|
|
<h1>{ playlist.name }</h1>
|
2016-11-01 11:49:04 +13:00
|
|
|
</div>
|
2016-11-07 21:21:15 +13:00
|
|
|
|
|
|
|
|
<section className="list-wrapper">
|
|
|
|
|
<TrackList tracks={ playlist.tracks.items } />
|
|
|
|
|
<LazyLoadListener loadMore={ () => this.loadMore() }/>
|
|
|
|
|
</section>
|
|
|
|
|
|
2016-11-01 11:49:04 +13:00
|
|
|
</div>
|
2016-11-01 13:19:51 +13:00
|
|
|
</div>
|
|
|
|
|
)
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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)
|