2016-10-20 21:38:01 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-11-14 18:15:22 +13:00
|
|
|
import { Link } from 'react-router'
|
2016-11-02 16:51:00 +13:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
2017-01-04 15:24:13 +13:00
|
|
|
import ReactGA from 'react-ga'
|
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-11-18 13:21:30 +13:00
|
|
|
import FollowButton from '../components/FollowButton'
|
2017-07-17 07:16:33 +12:00
|
|
|
import Header from '../components/Header'
|
2017-02-28 16:13:27 +13:00
|
|
|
import ContextMenuTrigger from '../components/ContextMenuTrigger'
|
2016-10-23 23:48:06 +13:00
|
|
|
|
2016-11-18 13:21:30 +13:00
|
|
|
import * as helpers from '../helpers'
|
2017-08-02 21:11:22 +12:00
|
|
|
import * as coreActions from '../services/core/actions'
|
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
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2016-10-20 21:38:01 +13:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2016-11-01 11:49:04 +13:00
|
|
|
this.loadPlaylist();
|
2016-10-21 09:56:07 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
componentWillReceiveProps(nextProps){
|
|
|
|
|
if (nextProps.params.uri != this.props.params.uri){
|
|
|
|
|
this.loadPlaylist(nextProps )
|
|
|
|
|
}else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
|
2017-10-26 20:36:27 +13:00
|
|
|
if (helpers.uriSource(this.props.params.uri) != 'spotify'){
|
2017-10-10 13:05:28 +13:00
|
|
|
this.loadPlaylist(nextProps )
|
2016-11-01 11:49:04 +13:00
|
|
|
}
|
2016-10-21 09:56:07 +13:00
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
2017-02-27 08:44:02 +13:00
|
|
|
handleContextMenu(e){
|
|
|
|
|
var data = {
|
|
|
|
|
e: e,
|
|
|
|
|
context: (this.props.playlist.can_edit ? 'editable-playlist' : 'playlist'),
|
2017-02-28 16:13:27 +13:00
|
|
|
items: [this.props.playlist],
|
2017-02-27 08:44:02 +13:00
|
|
|
uris: [this.props.params.uri]
|
|
|
|
|
}
|
|
|
|
|
this.props.uiActions.showContextMenu(data)
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 08:29:26 +12:00
|
|
|
loadPlaylist(props = this.props){
|
2016-11-11 12:12:50 +13:00
|
|
|
|
2017-07-10 08:29:26 +12:00
|
|
|
if (props.playlist && props.playlist.tracks && (props.playlist.tracks_total == 0 || props.playlist.tracks.length > 0)){
|
|
|
|
|
console.info('Loading playlist from index')
|
2016-11-11 12:12:50 +13:00
|
|
|
|
2017-07-10 08:29:26 +12:00
|
|
|
} else {
|
2017-10-10 13:05:28 +13:00
|
|
|
switch (helpers.uriSource(props.params.uri)){
|
2016-11-11 12:12:50 +13:00
|
|
|
|
2017-07-10 08:29:26 +12:00
|
|
|
case 'spotify':
|
2017-11-01 08:14:26 +13:00
|
|
|
this.props.spotifyActions.getPlaylist(props.params.uri);
|
|
|
|
|
this.props.spotifyActions.following(props.params.uri);
|
2017-07-10 08:29:26 +12:00
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (props.mopidy_connected){
|
2017-11-01 08:14:26 +13:00
|
|
|
this.props.mopidyActions.getPlaylist(props.params.uri);
|
2017-07-10 08:29:26 +12:00
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
2016-11-01 11:49:04 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:09:42 +13:00
|
|
|
loadMore(){
|
2017-11-09 21:04:45 +13:00
|
|
|
this.props.spotifyActions.loadMore(
|
|
|
|
|
this.props.playlist.tracks_more,
|
|
|
|
|
{
|
|
|
|
|
parent_type: 'playlist',
|
|
|
|
|
parent_key: this.props.playlist.uri,
|
|
|
|
|
records_type: 'track'
|
|
|
|
|
}
|
|
|
|
|
);
|
2016-11-07 18:09:42 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-11 09:33:35 +13:00
|
|
|
play(){
|
2017-04-07 10:33:54 +12:00
|
|
|
this.props.mopidyActions.playPlaylist(this.props.playlist.uri)
|
2016-11-11 09:33:35 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
follow(){
|
2017-01-04 15:24:13 +13:00
|
|
|
ReactGA.event({ category: 'Playlist', action: 'Follow', label: this.props.playlist.uri })
|
2017-05-07 09:29:18 +12:00
|
|
|
this.props.spotifyActions.toggleFollowingPlaylist(this.props.playlist.uri, 'PUT')
|
2016-11-11 09:33:35 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 21:02:46 +13:00
|
|
|
// TODO: Once unfollowing occurs, remove playlist from global playlists list
|
2016-11-11 09:33:35 +13:00
|
|
|
unfollow(){
|
2017-01-04 15:24:13 +13:00
|
|
|
ReactGA.event({ category: 'Playlist', action: 'Unfollow', label: this.props.playlist.uri })
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.spotifyActions.toggleFollowingPlaylist(this.props.playlist.uri, 'DELETE' )
|
2016-11-11 09:33:35 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 21:02:46 +13:00
|
|
|
// TODO: Once deletion occurs, remove playlist from global playlists list
|
2016-11-11 09:33:35 +13:00
|
|
|
delete(){
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.mopidyActions.deletePlaylist(this.props.playlist.uri )
|
2016-11-11 09:33:35 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
reorderTracks(indexes, index){
|
|
|
|
|
this.props.coreActions.reorderPlaylistTracks(this.props.playlist.uri, indexes, index, this.props.playlist.snapshot_id )
|
2016-11-16 13:13:35 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
removeTracks(tracks_indexes){
|
|
|
|
|
this.props.coreActions.removeTracksFromPlaylist(this.props.playlist.uri, tracks_indexes )
|
2016-11-11 12:12:50 +13:00
|
|
|
}
|
|
|
|
|
|
2017-03-09 21:37:16 +13:00
|
|
|
inLibrary(){
|
2017-08-15 16:36:50 +12:00
|
|
|
var library = helpers.uriSource(this.props.params.uri)+'_library_playlists'
|
|
|
|
|
return (this.props[library] && this.props[library].indexOf(this.props.params.uri) > -1)
|
2017-03-09 21:37:16 +13:00
|
|
|
}
|
|
|
|
|
|
2017-02-08 11:12:53 +13:00
|
|
|
renderActions(){
|
2017-10-10 13:05:28 +13:00
|
|
|
switch(helpers.uriSource(this.props.playlist.uri )){
|
2016-11-11 09:33:35 +13:00
|
|
|
|
|
|
|
|
case 'm3u':
|
2016-11-14 17:32:36 +13:00
|
|
|
return (
|
2017-02-08 11:12:53 +13:00
|
|
|
<div className="actions">
|
2017-02-12 21:11:50 +13:00
|
|
|
<button className="primary" onClick={ e => this.play() }>Play</button>
|
2017-08-15 16:36:50 +12:00
|
|
|
<button className="secondary" onClick={ e => this.props.uiActions.openModal('edit_playlist', { uri: this.props.params.uri, name: this.props.playlist.name }) }>Edit</button>
|
2017-10-21 21:58:53 +13:00
|
|
|
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
|
2017-02-08 11:12:53 +13:00
|
|
|
</div>
|
2016-11-14 17:32:36 +13:00
|
|
|
)
|
2016-11-11 09:33:35 +13:00
|
|
|
|
2016-11-14 11:20:02 +13:00
|
|
|
case 'spotify':
|
2017-10-10 13:05:28 +13:00
|
|
|
if (this.props.playlist.can_edit){
|
2016-11-14 17:32:36 +13:00
|
|
|
return (
|
2017-02-08 11:12:53 +13:00
|
|
|
<div className="actions">
|
2017-02-12 21:11:50 +13:00
|
|
|
<button className="primary" onClick={ e => this.play() }>Play</button>
|
2017-08-17 17:37:53 +12:00
|
|
|
<button className="secondary" onClick={ e => this.props.uiActions.openModal('edit_playlist', { uri: this.props.params.uri, name: this.props.playlist.name, public: this.props.playlist.public, collaborative: this.props.playlist.collaborative, description: this.props.playlist.description }) }>Edit</button>
|
2017-10-21 21:58:53 +13:00
|
|
|
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
|
2017-02-08 11:12:53 +13:00
|
|
|
</div>
|
2016-11-14 17:32:36 +13:00
|
|
|
)
|
2016-11-11 09:33:35 +13:00
|
|
|
}
|
2017-02-08 11:12:53 +13:00
|
|
|
return (
|
|
|
|
|
<div className="actions">
|
2017-02-12 21:11:50 +13:00
|
|
|
<button className="primary" onClick={ e => this.play() }>Play</button>
|
2017-08-15 16:36:50 +12:00
|
|
|
<FollowButton className="secondary" uri={this.props.params.uri} addText="Add to library" removeText="Remove from library" is_following={this.inLibrary()} />
|
2017-10-21 21:58:53 +13:00
|
|
|
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
|
2017-02-08 11:12:53 +13:00
|
|
|
</div>
|
|
|
|
|
)
|
2016-11-11 09:33:35 +13:00
|
|
|
|
2017-02-08 11:12:53 +13:00
|
|
|
default:
|
|
|
|
|
return (
|
|
|
|
|
<div className="actions">
|
2017-02-12 21:36:45 +13:00
|
|
|
<button className="primary" onClick={ e => this.play() }>Play</button>
|
2017-10-21 21:58:53 +13:00
|
|
|
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
|
2017-02-08 11:12:53 +13:00
|
|
|
</div>
|
|
|
|
|
)
|
2016-11-11 09:33:35 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 13:19:51 +13:00
|
|
|
render(){
|
2017-06-27 09:37:33 +12:00
|
|
|
if (!this.props.playlist) return null
|
2017-05-22 08:04:29 +12:00
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
var scheme = helpers.uriSource(this.props.params.uri )
|
2017-05-22 08:04:29 +12:00
|
|
|
var context = 'playlist'
|
2017-06-27 09:37:33 +12:00
|
|
|
if (this.props.playlist.can_edit) context = 'editable-playlist'
|
2017-05-22 08:04:29 +12:00
|
|
|
var user_id = helpers.getFromUri('userid',this.props.params.uri)
|
|
|
|
|
var playlist_id = helpers.getFromUri('playlistid',this.props.params.uri)
|
|
|
|
|
|
|
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_users/'+user_id+'/playlists/'+playlist_id+'?'])){
|
2017-05-22 04:19:44 +12:00
|
|
|
return (
|
2017-08-07 21:34:33 +12:00
|
|
|
<div className="body-loader loading">
|
2017-05-22 04:19:44 +12:00
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2016-11-01 13:19:51 +13:00
|
|
|
|
2017-11-09 09:12:23 +13:00
|
|
|
var tracks = [];
|
|
|
|
|
if (this.props.playlist.tracks_uris && this.props.tracks){
|
|
|
|
|
for (var i = 0; i < this.props.playlist.tracks_uris.length; i++){
|
|
|
|
|
var uri = this.props.playlist.tracks_uris[i]
|
|
|
|
|
if (this.props.tracks.hasOwnProperty(uri)){
|
|
|
|
|
tracks.push(this.props.tracks[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
return (
|
|
|
|
|
<div className="view playlist-view content-wrapper">
|
|
|
|
|
<div className="thumbnail-wrapper">
|
|
|
|
|
<Thumbnail size="large" canZoom images={ this.props.playlist.images } />
|
2017-02-23 22:06:43 +13:00
|
|
|
</div>
|
|
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
<div className="title">
|
|
|
|
|
<h1>{ this.props.playlist.name }</h1>
|
|
|
|
|
{ this.props.playlist.description ? <h2 className="description grey-text" dangerouslySetInnerHTML={{__html: this.props.playlist.description}}></h2> : null }
|
|
|
|
|
|
|
|
|
|
<ul className="details">
|
2017-10-10 13:05:28 +13:00
|
|
|
{ !this.props.slim_mode ? <li className="has-tooltip"><FontAwesome name={helpers.sourceIcon(this.props.params.uri )} /><span className="tooltip">{helpers.uriSource(this.props.params.uri )} playlist</span></li> : null }
|
2017-08-23 07:39:33 +12:00
|
|
|
{ this.props.playlist.owner && !this.props.slim_mode ? <li><Link to={'/user/'+this.props.playlist.owner.uri}>{this.props.playlist.owner.id}</Link></li> : null }
|
2017-06-27 09:37:33 +12:00
|
|
|
{ this.props.playlist.followers ? <li>{this.props.playlist.followers.total.toLocaleString()} followers</li> : null }
|
2017-10-27 10:51:48 +13:00
|
|
|
{ this.props.playlist.last_modified ? <li>Edited <Dater type="ago" data={this.props.playlist.last_modified} /></li> : null }
|
2017-06-27 09:37:33 +12:00
|
|
|
<li>
|
2017-11-09 09:12:23 +13:00
|
|
|
{ this.props.playlist.tracks_total ? this.props.playlist.tracks_total : tracks.length} tracks,
|
|
|
|
|
<Dater type="total-time" data={tracks} />
|
2017-06-27 09:37:33 +12:00
|
|
|
</li>
|
|
|
|
|
</ul>
|
2017-02-23 22:06:43 +13:00
|
|
|
</div>
|
2017-06-27 09:37:33 +12:00
|
|
|
|
|
|
|
|
{ this.renderActions() }
|
|
|
|
|
|
|
|
|
|
<section className="list-wrapper">
|
2017-11-09 09:12:23 +13:00
|
|
|
<TrackList uri={this.props.params.uri} className="playlist-track-list" context={context} tracks={tracks} removeTracks={ tracks_indexes => this.removeTracks(tracks_indexes) } reorderTracks={ (indexes, index) => this.reorderTracks(indexes, index) } />
|
2017-08-16 18:03:07 +12:00
|
|
|
<LazyLoadListener loading={this.props.playlist.tracks_more} loadMore={ () => this.loadMore() }/>
|
2017-06-27 09:37:33 +12:00
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2017-10-26 20:36:27 +13:00
|
|
|
var uri = ownProps.params.uri;
|
2016-11-09 21:13:40 +13:00
|
|
|
return {
|
2017-08-23 07:39:33 +12:00
|
|
|
slim_mode: state.ui.slim_mode,
|
2017-05-22 04:19:44 +12:00
|
|
|
load_queue: state.ui.load_queue,
|
2017-11-09 09:12:23 +13:00
|
|
|
tracks: state.core.tracks,
|
2017-11-09 21:04:45 +13:00
|
|
|
playlist: (state.core.playlists[uri] !== undefined ? state.core.playlists[uri] : false ),
|
2017-08-15 16:36:50 +12:00
|
|
|
spotify_library_playlists: state.spotify.library_playlists,
|
|
|
|
|
local_library_playlists: state.mopidy.library_playlists,
|
2016-11-11 09:33:35 +13:00
|
|
|
mopidy_connected: state.mopidy.connected,
|
2017-08-04 22:33:49 +12:00
|
|
|
spotify_authorized: state.spotify.authorization,
|
2016-11-11 09:33:35 +13:00
|
|
|
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 {
|
2017-08-02 21:11:22 +12:00
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
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)
|