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]