import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import FontAwesome from 'react-fontawesome'
import * as helpers from '../helpers'
import TrackList from '../components/TrackList'
import Thumbnail from '../components/Thumbnail'
import Dater from '../components/Dater'
import ConfirmationButton from '../components/ConfirmationButton'
import LazyLoadListener from '../components/LazyLoadListener'
import * as uiActions from '../services/ui/actions'
import * as mopidyActions from '../services/mopidy/actions'
import * as spotifyActions from '../services/spotify/actions'
class Playlist extends React.Component{
constructor(props) {
super(props);
}
componentDidMount(){
this.loadPlaylist();
}
componentWillReceiveProps( nextProps ){
if( nextProps.params.uri != this.props.params.uri ){
this.loadPlaylist( nextProps )
}else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){
if( helpers.uriSource( this.props.params.uri ) == 'm3u' ){
this.loadPlaylist( nextProps )
}
}
}
loadPlaylist( props = this.props ){
switch( helpers.uriSource( props.params.uri ) ){
case 'spotify':
this.props.spotifyActions.getPlaylist( props.params.uri );
break
case 'm3u':
if( props.mopidy_connected ) this.props.mopidyActions.getPlaylist( props.params.uri );
break
}
}
loadMore(){
if( !this.props.playlist.tracks_more ) return
this.props.spotifyActions.getURL( this.props.playlist.tracks_more, 'SPOTIFY_PLAYLIST_LOADED_MORE' );
}
play(){
this.props.mopidyActions.playTracks([this.props.params.uri])
}
follow(){
this.props.spotifyActions.toggleFollowingPlaylist( this.props.params.uri, 'PUT' )
}
unfollow(){
this.props.spotifyActions.toggleFollowingPlaylist( this.props.params.uri, 'DELETE' )
}
delete(){
this.props.mopidyActions.deletePlaylist( this.props.params.uri )
}
removeTracks( track_indexes ){
this.props.uiActions.removeTracksFromPlaylist( this.props.playlist.uri, track_indexes )
}
renderEditButtons(){
switch( helpers.uriSource( this.props.params.uri ) ){
case 'm3u':
return (