diff --git a/src/js/components/ContextMenu.js b/src/js/components/ContextMenu.js index 5cee7839..65297a4b 100755 --- a/src/js/components/ContextMenu.js +++ b/src/js/components/ContextMenu.js @@ -121,13 +121,13 @@ class ContextMenu extends React.Component{ switch (helpers.uriType(item.uri)){ case 'artist': - return (this.props.library_artists && this.props.library_artists.indexOf(item.uri) > -1) + return (this.props.spotify_library_artists && this.props.spotify_library_artists.indexOf(item.uri) > -1) break case 'album': - return (this.props.library_albums && this.props.library_albums.indexOf(item.uri) > -1) + return (this.props.spotify_library_albums && this.props.spotify_library_albums.indexOf(item.uri) > -1) break case 'playlist': - return (this.props.library_playlists && this.props.library_playlists.indexOf(item.uri) > -1) + return (this.props.spotify_library_playlists && this.props.spotify_library_playlists.indexOf(item.uri) > -1) break } return false @@ -195,6 +195,11 @@ class ContextMenu extends React.Component{ this.props.coreActions.removeTracksFromPlaylist(this.props.menu.tracklist_uri, this.props.menu.indexes) } + deletePlaylist(e){ + this.props.uiActions.hideContextMenu() + this.props.coreActions.deletePlaylist(this.props.menu.uris[0]) + } + startRadio(e){ this.props.uiActions.hideContextMenu() this.props.pusherActions.startRadio(this.props.menu.uris) @@ -259,6 +264,19 @@ class ContextMenu extends React.Component{ ) } + var list = No writable playlists + if (playlists.length > 0){ + list = playlists.map(playlist => { + return ( + + this.addTracksToPlaylist(e,playlist.uri) }> + { playlist.name } + + + ) + }) + } + return (
@@ -270,17 +288,7 @@ class ContextMenu extends React.Component{ - { - playlists.map( playlist => { - return ( - - this.addTracksToPlaylist(e,playlist.uri) }> - { playlist.name } - - - ) - }) - } + {list} {loader}
) @@ -476,6 +484,14 @@ class ContextMenu extends React.Component{ ) + var delete_playlist = ( + + this.deletePlaylist(e)}> + Delete + + + ) + var copy_uris = ( this.copyURIs(e)}> @@ -522,6 +538,18 @@ class ContextMenu extends React.Component{ ) break + case 'editable-playlist': + return ( +
+ {play_playlist} + {context.source == 'spotify' ? go_to_user : null} + {copy_uris} + {this.canBeInLibrary() ? toggle_in_library : null} + {delete_playlist} +
+ ) + break + case 'queue-track': return (
diff --git a/src/js/services/core/actions.js b/src/js/services/core/actions.js index 3cf491b4..ad814d3c 100755 --- a/src/js/services/core/actions.js +++ b/src/js/services/core/actions.js @@ -1,5 +1,7 @@ import * as helpers from '../../helpers' +var spotifyActions = require('../../services/spotify/actions') +var mopidyActions = require('../../services/mopidy/actions') export function getBroadcasts(){ return (dispatch, getState) => { @@ -84,7 +86,7 @@ export function reorderPlaylistTracks( uri, indexes, insert_before, snapshot_id } export function savePlaylist(uri, name, description = '', is_public = false, is_collaborative = false){ - switch( helpers.uriSource( uri ) ){ + switch (helpers.uriSource(uri)){ case 'spotify': return { @@ -107,23 +109,28 @@ export function savePlaylist(uri, name, description = '', is_public = false, is_ } export function createPlaylist(scheme, name, description = '', is_public = false, is_collaborative = false){ - switch( scheme ){ + switch (scheme){ case 'spotify': - return { - type: 'SPOTIFY_CREATE_PLAYLIST', - name: name, - description: (description == '' ? null : description), - is_public: is_public, - is_collaborative: is_collaborative + if (description == ''){ + description = null } + return spotifyActions.createPlaylist( name, description, is_public, is_collaborative ) - case 'm3u': - return { - type: 'MOPIDY_CREATE_PLAYLIST', - scheme: scheme, - name: name - } + default: + return mopidyActions.createPlaylist(name, scheme) + } + return false +} + +export function deletePlaylist(uri){ + switch (helpers.uriSource(uri)){ + + case 'spotify': + return spotifyActions.following(uri, 'DELETE') + + default: + return mopidyActions.deletePlaylist(uri) } return false } diff --git a/src/js/services/mopidy/actions.js b/src/js/services/mopidy/actions.js index 8c18cc5a..e337cb86 100755 --- a/src/js/services/mopidy/actions.js +++ b/src/js/services/mopidy/actions.js @@ -160,6 +160,14 @@ export function getImages( context, uris ){ } } +export function createPlaylist(name, scheme){ + return { + type: 'MOPIDY_CREATE_PLAYLIST', + name: name, + scheme: scheme + } +} + export function deletePlaylist( uri ){ return { type: 'MOPIDY_DELETE_PLAYLIST', diff --git a/src/js/services/mopidy/middleware.js b/src/js/services/mopidy/middleware.js index 64ff2792..89e2118c 100755 --- a/src/js/services/mopidy/middleware.js +++ b/src/js/services/mopidy/middleware.js @@ -830,18 +830,28 @@ const MopidyMiddleware = (function(){ .then( response => { store.dispatch(uiActions.createNotification('Created playlist')) - // re-load our global playlists - //store.dispatch({ type: 'MOPIDY_GET_PLAYLISTS' }); + store.dispatch({ + type: 'PLAYLIST_LOADED', + key: action.uri, + playlist: response + }) + + store.dispatch({ + type: 'MOPIDY_LIBRARY_PLAYLIST_CREATED', + key: action.uri, + playlist: response + }) }); break case 'MOPIDY_DELETE_PLAYLIST': - instruct( socket, store, 'playlists.delete', { uri: action.key }) + instruct( socket, store, 'playlists.delete', { uri: action.uri }) .then( response => { store.dispatch(uiActions.createNotification('Deleted playlist')) - - // re-load our global playlists - // store.dispatch({ type: 'MOPIDY_PLAYLISTS' }); + store.dispatch({ + type: 'MOPIDY_LIBRARY_PLAYLIST_DELETED', + key: action.uri + }) }); break diff --git a/src/js/services/mopidy/reducer.js b/src/js/services/mopidy/reducer.js index c6df2a78..37547fd4 100755 --- a/src/js/services/mopidy/reducer.js +++ b/src/js/services/mopidy/reducer.js @@ -109,6 +109,22 @@ export default function reducer(mopidy = {}, action){ } return Object.assign({}, mopidy, { library_playlists: helpers.removeDuplicates(uris) }) + case 'MOPIDY_LIBRARY_PLAYLIST_CREATED': + var library_playlists = [] + if (mopidy.library_playlists){ + library_playlists = Object.assign([], mopidy.library_playlists) + library_playlists.push(action.key) + } + return Object.assign({}, mopidy, { library_playlists: library_playlists }) + + case 'MOPIDY_LIBRARY_PLAYLIST_DELETED': + var library_playlists = [] + if (mopidy.library_playlists){ + library_playlists = Object.assign([], mopidy.library_playlists) + library_playlists.splice(library_playlists.indexOf(action.uri), 1) + } + return Object.assign({}, mopidy, { library_playlists: library_playlists }) + case 'MOPIDY_LIBRARY_ARTISTS_LOADED': if (mopidy.library_artists){ var uris = [...mopidy.library_artists,...action.uris]