Editing playlist description; Handling change of local playlist URIs
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
|
||||
import Mopidy from 'mopidy'
|
||||
import { hashHistory } from 'react-router'
|
||||
import * as helpers from '../../helpers'
|
||||
|
||||
var mopidyActions = require('./actions.js')
|
||||
@ -733,17 +734,33 @@ const MopidyMiddleware = (function(){
|
||||
});
|
||||
break
|
||||
|
||||
case 'MOPIDY_SAVE_PLAYLIST':
|
||||
case 'MOPIDY_SAVE_PLAYLIST':
|
||||
var uri = action.key
|
||||
|
||||
instruct( socket, store, 'playlists.lookup', { uri: action.key })
|
||||
.then( response => {
|
||||
var playlist = Object.assign({}, response, { name: action.name })
|
||||
instruct( socket, store, 'playlists.save', { playlist: playlist } )
|
||||
.then( response => {
|
||||
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: action.key,
|
||||
key: action.key,
|
||||
playlist: playlist
|
||||
})
|
||||
|
||||
// When we rename a playlist, the URI also changes to reflect the name change
|
||||
// We need to update our index, as well as redirect our current page URL
|
||||
if (action.key != response.key){
|
||||
store.dispatch({
|
||||
type: 'PLAYLIST_KEY_UPDATED',
|
||||
key: action.key,
|
||||
new_key: response.uri
|
||||
})
|
||||
hashHistory.push(global.baseURL+'playlist/'+response.uri)
|
||||
}
|
||||
|
||||
store.dispatch(uiActions.createNotification('Saved'))
|
||||
})
|
||||
});
|
||||
break
|
||||
@ -793,7 +810,8 @@ const MopidyMiddleware = (function(){
|
||||
|
||||
case 'MOPIDY_CREATE_PLAYLIST':
|
||||
instruct( socket, store, 'playlists.create', { name: action.name, uri_scheme: action.scheme })
|
||||
.then( response => {
|
||||
.then( response => {
|
||||
store.dispatch(uiActions.createNotification('Created playlist'))
|
||||
|
||||
// re-load our global playlists
|
||||
//store.dispatch({ type: 'MOPIDY_GET_PLAYLISTS' });
|
||||
@ -803,6 +821,7 @@ const MopidyMiddleware = (function(){
|
||||
case 'MOPIDY_DELETE_PLAYLIST':
|
||||
instruct( socket, store, 'playlists.delete', { uri: action.key })
|
||||
.then( response => {
|
||||
store.dispatch(uiActions.createNotification('Deleted playlist'))
|
||||
|
||||
// re-load our global playlists
|
||||
// store.dispatch({ type: 'MOPIDY_PLAYLISTS' });
|
||||
|
||||
@ -1095,23 +1095,34 @@ export function createPlaylist( name, is_public ){
|
||||
dispatch({
|
||||
type: 'LIBRARY_PLAYLISTS_LOADED',
|
||||
uris: [response.uri]
|
||||
});
|
||||
})
|
||||
|
||||
dispatch(uiActions.createNotification('Created playlist'))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function savePlaylist(uri, name, is_public){
|
||||
export function savePlaylist(uri, name, is_public, description){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
sendRequest( dispatch, getState, 'users/'+ getState().spotify.me.id +'/playlists/'+ helpers.getFromUri('playlistid',uri), 'PUT', { name: name, public: is_public } )
|
||||
var data = {
|
||||
name: name,
|
||||
public: is_public,
|
||||
description: description
|
||||
}
|
||||
|
||||
sendRequest( dispatch, getState, 'users/'+ getState().spotify.me.id +'/playlists/'+ helpers.getFromUri('playlistid',uri), 'PUT', data)
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'PLAYLIST_UPDATED',
|
||||
key: uri,
|
||||
playlist: {
|
||||
name: name,
|
||||
public: is_public
|
||||
public: is_public,
|
||||
description: description
|
||||
}
|
||||
});
|
||||
})
|
||||
dispatch(uiActions.createNotification('Saved'))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ const SpotifyMiddleware = (function(){
|
||||
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
|
||||
return
|
||||
}
|
||||
store.dispatch( spotifyActions.savePlaylist( action.key, action.name, action.is_public ))
|
||||
store.dispatch( spotifyActions.savePlaylist( action.key, action.name, action.is_public, action.description ))
|
||||
break
|
||||
|
||||
// when radio returns
|
||||
|
||||
@ -130,7 +130,7 @@ export function reorderPlaylistTracks( uri, indexes, insert_before, snapshot_id
|
||||
}
|
||||
}
|
||||
|
||||
export function savePlaylist( uri, name, is_public = false ){
|
||||
export function savePlaylist(uri, name, is_public = false, description = ''){
|
||||
switch( helpers.uriSource( uri ) ){
|
||||
|
||||
case 'spotify':
|
||||
@ -138,7 +138,8 @@ export function savePlaylist( uri, name, is_public = false ){
|
||||
type: 'SPOTIFY_SAVE_PLAYLIST',
|
||||
key: uri,
|
||||
name: name,
|
||||
is_public: is_public
|
||||
is_public: is_public,
|
||||
description: (description == '' ? null : description)
|
||||
}
|
||||
|
||||
case 'm3u':
|
||||
|
||||
@ -471,7 +471,22 @@ export default function reducer(ui = {}, action){
|
||||
}
|
||||
|
||||
playlists[action.key] = merged_playlist
|
||||
return Object.assign({}, ui, { playlists: playlists });
|
||||
return Object.assign({}, ui, { playlists: playlists })
|
||||
|
||||
case 'PLAYLIST_KEY_UPDATED':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
|
||||
// URI not in our index? No change needed then
|
||||
if (typeof(playlists[action.key]) === 'undefined'){
|
||||
return ui
|
||||
}
|
||||
|
||||
// Delete our old playlist by key, and add by new key
|
||||
var playlist = Object.assign({}, playlists[action.key])
|
||||
delete playlists[action.key]
|
||||
playlists[playlist.uri] = playlist
|
||||
|
||||
return Object.assign({}, ui, { playlists: playlists })
|
||||
|
||||
case 'PLAYLISTS_LOADED':
|
||||
var playlists = Object.assign([], ui.playlists)
|
||||
|
||||
Reference in New Issue
Block a user