Adding as an index reference where index uris change

This commit is contained in:
James Barnsley
2019-02-01 10:19:21 +13:00
parent 1406985662
commit 9afbaa5b03
8 changed files with 131 additions and 72 deletions

View File

@ -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
}
}
/**

View File

@ -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);

View File

@ -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