Adding as an index reference where index uris change
This commit is contained in:
@ -213,6 +213,15 @@ export function loadedMore(parent_type, parent_key, records_type, records_data){
|
||||
}
|
||||
}
|
||||
|
||||
export function removeFromIndex(index_name, key, new_key = null){
|
||||
return {
|
||||
type: 'REMOVE_FROM_INDEX',
|
||||
index_name: index_name,
|
||||
key: key,
|
||||
new_key: new_key
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -233,24 +233,6 @@ const CoreMiddleware = (function(){
|
||||
* Playlist manipulation
|
||||
**/
|
||||
|
||||
case 'PLAYLIST_KEY_UPDATED':
|
||||
var playlists = Object.assign({}, core.playlists);
|
||||
|
||||
if (playlists[action.key] === undefined){
|
||||
dispatch(coreActions.handleException("Cannot change key of playlist not in index"));
|
||||
}
|
||||
|
||||
// Delete our old playlist by key, and add by new key
|
||||
var playlist = Object.assign({}, playlists[action.key]);
|
||||
delete playlists[action.key];
|
||||
playlists[action.new_key] = playlist;
|
||||
|
||||
store.dispatch({
|
||||
type: 'UPDATE_PLAYLISTS_INDEX',
|
||||
playlists: playlists
|
||||
});
|
||||
break;
|
||||
|
||||
case 'PLAYLIST_TRACKS':
|
||||
var tracks = helpers.formatTracks(action.tracks);
|
||||
action.tracks_uris = helpers.arrayOf('uri', tracks);
|
||||
|
||||
@ -152,6 +152,31 @@ export default function reducer(core = {}, action){
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Remove an item from an index
|
||||
**/
|
||||
|
||||
case 'REMOVE_FROM_INDEX':
|
||||
var index = Object.assign({}, core[action.index_name]);
|
||||
|
||||
// We have a new key to redirect to
|
||||
if (action.new_key){
|
||||
index[action.key] = {
|
||||
moved_to: action.new_key
|
||||
}
|
||||
|
||||
// No redirection, so just a clean delete
|
||||
} else {
|
||||
delete index[action.key];
|
||||
}
|
||||
|
||||
var updated_core = {};
|
||||
updated_core[action.index_name] = index;
|
||||
|
||||
return Object.assign({}, core, updated_core);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Playlists
|
||||
|
||||
Reference in New Issue
Block a user