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'
|
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'
|
2018-04-19 13:34:16 +12:00
|
|
|
import ConfirmationButton from '../components/Fields/ConfirmationButton'
|
2016-11-07 18:09:42 +13:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener'
|
2018-04-19 13:34:16 +12:00
|
|
|
import FollowButton from '../components/Fields/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'
|
2017-11-10 15:56:01 +13:00
|
|
|
import URILink from '../components/URILink'
|
2018-05-21 06:01:53 +12:00
|
|
|
import Icon from '../components/Icon'
|
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(){
|
2018-06-29 14:26:06 +12:00
|
|
|
this.setWindowTitle();
|
2018-08-31 16:04:55 +12:00
|
|
|
this.props.coreActions.loadPlaylist(this.props.params.uri);
|
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){
|
2018-08-31 16:04:55 +12:00
|
|
|
this.props.coreActions.loadPlaylist(nextProps.params.uri);
|
2018-06-29 14:26:06 +12:00
|
|
|
} 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'){
|
2018-08-31 16:04:55 +12:00
|
|
|
this.props.coreActions.loadPlaylist(nextProps.params.uri);
|
2016-11-01 11:49:04 +13:00
|
|
|
}
|
2016-10-21 09:56:07 +13:00
|
|
|
}
|
2018-06-29 14:26:06 +12:00
|
|
|
|
|
|
|
|
if (!this.props.playlist && nextProps.playlist){
|
|
|
|
|
this.setWindowTitle(nextProps.playlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.props.params.uri !== nextProps.params.uri && nextProps.playlist){
|
|
|
|
|
this.setWindowTitle(nextProps.playlist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setWindowTitle(playlist = this.props.playlist){
|
|
|
|
|
if (playlist){
|
|
|
|
|
this.props.uiActions.setWindowTitle(playlist.name+" (playlist)");
|
|
|
|
|
} else{
|
|
|
|
|
this.props.uiActions.setWindowTitle("Playlist");
|
|
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:09:42 +13:00
|
|
|
loadMore(){
|
2017-11-12 09:05:34 +13:00
|
|
|
this.props.spotifyActions.getMore(
|
2017-11-09 21:04:45 +13:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-04-01 21:26:42 +12:00
|
|
|
handleContextMenu(e){
|
|
|
|
|
var data = {
|
|
|
|
|
e: e,
|
|
|
|
|
context: (this.props.playlist.can_edit ? 'editable-playlist' : 'playlist'),
|
|
|
|
|
items: [this.props.playlist],
|
|
|
|
|
uris: [this.props.params.uri]
|
|
|
|
|
}
|
|
|
|
|
this.props.uiActions.showContextMenu(data)
|
|
|
|
|
}
|
|
|
|
|
|
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(){
|
2018-06-05 13:43:02 +12:00
|
|
|
if (this.props.allow_reporting){
|
|
|
|
|
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(){
|
2018-06-05 13:43:02 +12:00
|
|
|
if (this.props.allow_reporting){
|
|
|
|
|
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-11-10 15:56:01 +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){
|
2017-11-10 15:56:01 +13:00
|
|
|
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){
|
2017-11-10 15:56:01 +13:00
|
|
|
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-11-10 15:56:01 +13: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(){
|
2018-08-31 16:04:55 +12: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>
|
2018-07-25 21:33:14 +12:00
|
|
|
<Link className="button secondary" to={global.baseURL+'playlist/'+encodeURIComponent(this.props.params.uri)+'/edit'}>Edit</Link>
|
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>
|
2018-07-08 21:12:18 +12:00
|
|
|
<Link className="button secondary" to={global.baseURL+'playlist/'+encodeURIComponent(this.props.params.uri)+'/edit'}>Edit</Link>
|
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(){
|
2018-04-10 08:01:36 +12:00
|
|
|
var scheme = helpers.uriSource(this.props.params.uri);
|
|
|
|
|
var playlist_id = helpers.getFromUri('playlistid',this.props.params.uri);
|
|
|
|
|
|
|
|
|
|
if (!this.props.playlist){
|
2018-09-14 11:58:13 +12:00
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_playlists/'+playlist_id+'?'])){
|
2018-04-10 08:01:36 +12:00
|
|
|
return (
|
|
|
|
|
<div className="body-loader loading">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 16:04:55 +12:00
|
|
|
var playlist = helpers.collate(this.props.playlist, {tracks: this.props.tracks, users: this.props.users});
|
|
|
|
|
|
2018-04-10 08:01:36 +12:00
|
|
|
var context = 'playlist';
|
2018-08-31 16:04:55 +12:00
|
|
|
if (playlist.can_edit){
|
2018-04-10 08:01:36 +12:00
|
|
|
context = 'editable-playlist';
|
2017-05-22 04:19:44 +12:00
|
|
|
}
|
2016-11-01 13:19:51 +13:00
|
|
|
|
2018-09-14 11:58:13 +12:00
|
|
|
if (playlist.tracks && playlist.tracks.length <= 0 && helpers.isLoading(this.props.load_queue,['spotify_playlists/'+playlist_id, 'spotify_playlists/'+playlist_id+'/tracks'])){
|
2018-04-14 13:48:03 +12:00
|
|
|
var is_loading_tracks = true;
|
|
|
|
|
} else {
|
|
|
|
|
var is_loading_tracks = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
return (
|
|
|
|
|
<div className="view playlist-view content-wrapper">
|
|
|
|
|
<div className="thumbnail-wrapper">
|
2018-08-31 16:04:55 +12:00
|
|
|
<Thumbnail size="large" canZoom images={playlist.images} />
|
2017-02-23 22:06:43 +13:00
|
|
|
</div>
|
|
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
<div className="title">
|
2018-08-31 16:04:55 +12:00
|
|
|
<h1>{playlist.name}</h1>
|
|
|
|
|
{playlist.description ? <h2 className="description grey-text" dangerouslySetInnerHTML={{__html: playlist.description}}></h2> : null }
|
2017-06-27 09:37:33 +12:00
|
|
|
|
|
|
|
|
<ul className="details">
|
2018-08-31 16:04:55 +12:00
|
|
|
{!this.props.slim_mode ? <li className="has-tooltip"><Icon type="fontawesome" name={helpers.sourceIcon(playlist.uri)} /><span className="tooltip">{helpers.uriSource(playlist.uri)} playlist</span></li> : null }
|
|
|
|
|
{playlist.user_uri && !this.props.slim_mode ? <li><URILink type="user" uri={playlist.user_uri}>{playlist.user ? playlist.user.name : helpers.getFromUri('userid',playlist.user_uri)}</URILink></li> : null }
|
2018-09-14 16:11:55 +12:00
|
|
|
{playlist.followers !== undefined ? <li>{playlist.followers.toLocaleString()} followers</li> : null }
|
2018-08-31 16:04:55 +12:00
|
|
|
{playlist.last_modified_date ? <li>Edited <Dater type="ago" data={playlist.last_modified_date} /></li> : null }
|
2017-06-27 09:37:33 +12:00
|
|
|
<li>
|
2018-08-31 16:04:55 +12:00
|
|
|
{playlist.tracks_total ? playlist.tracks_total : (playlist.tracks ? playlist.tracks.length : '0')} tracks,
|
|
|
|
|
<Dater type="total-time" data={playlist.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">
|
2018-08-31 16:04:55 +12:00
|
|
|
<TrackList uri={playlist.uri} className="playlist-track-list" context={context} tracks={playlist.tracks} removeTracks={ tracks_indexes => this.removeTracks(tracks_indexes) } reorderTracks={ (indexes, index) => this.reorderTracks(indexes, index) } />
|
2018-09-03 08:24:49 +12:00
|
|
|
<LazyLoadListener
|
|
|
|
|
loadKey={playlist.tracks_more}
|
|
|
|
|
showLoader={is_loading_tracks}
|
|
|
|
|
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 {
|
2018-06-05 13:43:02 +12:00
|
|
|
allow_reporting: state.ui.allow_reporting,
|
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,
|
2018-08-31 16:04:55 +12:00
|
|
|
users: state.core.users,
|
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,
|
2018-09-14 11:58:13 +12:00
|
|
|
spotify_userid: (state.spotify.me && state.spotify.me.id ? state.spotify.me.id : null)
|
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)
|