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-11 09:33:35 +13:00
|
|
|
import * as helpers from '../helpers'
|
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-11 09:33:35 +13:00
|
|
|
import ConfirmationButton from '../components/ConfirmationButton'
|
2016-11-07 18:09:42 +13:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener'
|
2016-10-23 23:48:06 +13:00
|
|
|
|
2016-11-11 12:12:50 +13:00
|
|
|
import * as uiActions from '../services/ui/actions'
|
2016-10-21 09:56:07 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
2016-11-11 12:12:50 +13:00
|
|
|
import * as spotifyActions from '../services/spotify/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 )
|
2016-11-09 21:13:40 +13:00
|
|
|
}else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){
|
2016-11-01 11:49:04 +13:00
|
|
|
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 ){
|
2016-11-11 12:12:50 +13:00
|
|
|
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
|
|
|
|
|
|
2016-11-01 11:49:04 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:09:42 +13:00
|
|
|
loadMore(){
|
2016-11-09 21:13:40 +13:00
|
|
|
if( !this.props.playlist.tracks_more ) return
|
|
|
|
|
this.props.spotifyActions.getURL( this.props.playlist.tracks_more, 'SPOTIFY_PLAYLIST_LOADED_MORE' );
|
2016-11-07 18:09:42 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-11 09:33:35 +13:00
|
|
|
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(){
|
|
|
|
|
alert('Delete me')
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-11 12:12:50 +13:00
|
|
|
removeTracks( track_indexes ){
|
|
|
|
|
this.props.uiActions.removeTracksFromPlaylist( track_indexes )
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-11 09:33:35 +13:00
|
|
|
renderFollowOrDeleteButton(){
|
|
|
|
|
if( !this.props.spotify_authorized ) return null
|
|
|
|
|
|
|
|
|
|
switch( helpers.uriSource( this.props.params.uri ) ){
|
|
|
|
|
|
|
|
|
|
case 'm3u':
|
|
|
|
|
return <ConfirmationButton className="large tertiary" content="Delete" confirmingContent="Confirm" onConfirm={ e => this.delete() } />
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'spotify':
|
|
|
|
|
if( this.props.playlist.owner && this.props.playlist.owner.id == this.props.spotify_userid ){
|
|
|
|
|
return <ConfirmationButton className="large tertiary" content="Delete" confirmingContent="Are you sure?" onConfirm={ e => this.delete() } />
|
|
|
|
|
}else if( this.props.playlist.following ){
|
|
|
|
|
return <button className="large tertiary" onClick={ e => this.unfollow() }>Unfollow</button>
|
|
|
|
|
}else{
|
|
|
|
|
return <button className="large tertiary" onClick={ e => this.follow() }>Follow</button>
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 13:19:51 +13:00
|
|
|
render(){
|
2016-11-11 09:33:35 +13:00
|
|
|
if( !this.props.playlist || !this.props.playlist.name ) return null;
|
2016-11-09 21:13:40 +13:00
|
|
|
var scheme = helpers.uriSource( this.props.params.uri );
|
2016-11-01 13:19:51 +13:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view playlist-view">
|
|
|
|
|
<div className="intro">
|
2016-11-11 09:33:35 +13:00
|
|
|
|
2016-11-09 21:13:40 +13:00
|
|
|
<Thumbnail size="large" images={ this.props.playlist.images } />
|
2016-11-11 09:33:35 +13:00
|
|
|
|
|
|
|
|
<div className="actions">
|
|
|
|
|
<button className="large primary" onClick={ e => this.play() }>Play</button>
|
|
|
|
|
{ this.renderFollowOrDeleteButton() }
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-11-02 16:51:00 +13:00
|
|
|
<ul className="details">
|
2016-11-09 21:13:40 +13:00
|
|
|
<li>{ this.props.playlist.tracks_total } tracks, <Dater type="total-time" data={this.props.playlist.tracks} /></li>
|
|
|
|
|
{ this.props.playlist.last_modified ? <li>Updated <Dater type="ago" data={this.props.playlist.last_modified} /> ago</li> : null }
|
|
|
|
|
{ scheme == 'spotify' ? <li><FontAwesome name="spotify" /> Spotify playlist</li> : null }
|
|
|
|
|
{ scheme == 'm3u' ? <li><FontAwesome name="folder" /> Local playlist</li> : null }
|
2016-11-02 16:51:00 +13:00
|
|
|
</ul>
|
2016-11-11 09:33:35 +13:00
|
|
|
|
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">
|
2016-11-09 21:13:40 +13:00
|
|
|
<h1>{ this.props.playlist.name }</h1>
|
2016-11-11 09:33:35 +13:00
|
|
|
{ this.props.playlist.description ? <h3 className="grey-text" dangerouslySetInnerHTML={{__html: this.props.playlist.description}}></h3> : null }
|
2016-11-01 11:49:04 +13:00
|
|
|
</div>
|
2016-11-07 21:21:15 +13:00
|
|
|
|
|
|
|
|
<section className="list-wrapper">
|
2016-11-11 12:12:50 +13:00
|
|
|
{ this.props.playlist.tracks ? <TrackList context="editable-playlist" tracks={ this.props.playlist.tracks } removeTracks={ track_indexes => this.removeTracks(track_indexes) } /> : null }
|
2016-11-07 21:21:15 +13:00
|
|
|
<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) => {
|
2016-11-09 21:13:40 +13:00
|
|
|
return {
|
|
|
|
|
playlist: state.ui.playlist,
|
2016-11-11 09:33:35 +13:00
|
|
|
mopidy_connected: state.mopidy.connected,
|
|
|
|
|
spotify_authorized: state.spotify.authorized,
|
|
|
|
|
spotify_userid: state.spotify.me.id
|
2016-11-09 21:13:40 +13:00
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-11-11 12:12:50 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
2016-10-20 21:38:01 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Playlist)
|