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 ReactGA from 'react-ga' 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 FollowButton from '../components/FollowButton' import Header from '../components/Header' import ContextMenuTrigger from '../components/ContextMenuTrigger' import * as helpers from '../helpers' import * as coreActions from '../services/core/actions' 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) != 'spotify'){ this.loadPlaylist(nextProps ) } } } 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) } loadPlaylist(props = this.props){ if (props.playlist && props.playlist.tracks && (props.playlist.tracks_total == 0 || props.playlist.tracks.length > 0)){ console.info('Loading playlist from index') } else { switch (helpers.uriSource(props.params.uri)){ case 'spotify': this.props.spotifyActions.getPlaylist(props.params.uri ) break default: if (props.mopidy_connected){ this.props.mopidyActions.getPlaylist(props.params.uri ) } break } } } loadMore(){ this.props.spotifyActions.getURL(this.props.playlist.tracks_more, 'PLAYLIST_LOADED_MORE_TRACKS', this.props.playlist.uri ); } play(){ this.props.mopidyActions.playPlaylist(this.props.playlist.uri) } follow(){ ReactGA.event({ category: 'Playlist', action: 'Follow', label: this.props.playlist.uri }) this.props.spotifyActions.toggleFollowingPlaylist(this.props.playlist.uri, 'PUT') } // TODO: Once unfollowing occurs, remove playlist from global playlists list unfollow(){ ReactGA.event({ category: 'Playlist', action: 'Unfollow', label: this.props.playlist.uri }) this.props.spotifyActions.toggleFollowingPlaylist(this.props.playlist.uri, 'DELETE' ) } // TODO: Once deletion occurs, remove playlist from global playlists list delete(){ this.props.mopidyActions.deletePlaylist(this.props.playlist.uri ) } reorderTracks(indexes, index){ this.props.coreActions.reorderPlaylistTracks(this.props.playlist.uri, indexes, index, this.props.playlist.snapshot_id ) } removeTracks(tracks_indexes){ this.props.coreActions.removeTracksFromPlaylist(this.props.playlist.uri, tracks_indexes ) } inLibrary(){ var library = helpers.uriSource(this.props.params.uri)+'_library_playlists' return (this.props[library] && this.props[library].indexOf(this.props.params.uri) > -1) } renderActions(){ switch(helpers.uriSource(this.props.playlist.uri )){ case 'm3u': return (