fix note move to different parent in note cache

This commit is contained in:
azivner
2018-08-31 19:55:56 +02:00
parent fdc3a7a7f2
commit c55bc471db
3 changed files with 17 additions and 9 deletions

View File

@@ -260,20 +260,19 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity})
else if (entityName === 'branches') {
const branch = entity;
if (childToParent[branch.noteId]) {
childToParent[branch.noteId] = childToParent[branch.noteId].filter(noteId => noteId !== branch.parentNoteId)
}
// first we remove records for original placement (if they exist)
childToParent[branch.noteId] = childToParent[branch.noteId] || [];
childToParent[branch.noteId] = childToParent[branch.noteId].filter(noteId => noteId !== branch.origParentNoteId);
if (branch.isDeleted) {
delete prefixes[branch.noteId + '-' + branch.parentNoteId];
delete childParentToBranchId[branch.noteId + '-' + branch.parentNoteId];
}
else {
delete prefixes[branch.noteId + '-' + branch.origParentNoteId];
delete childParentToBranchId[branch.noteId + '-' + branch.origParentNoteId];
if (!branch.isDeleted) {
// ... and then we create new records
if (branch.prefix) {
prefixes[branch.noteId + '-' + branch.parentNoteId] = branch.prefix;
}
childToParent[branch.noteId] = childToParent[branch.noteId] || [];
childToParent[branch.noteId].push(branch.parentNoteId);
childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId;
}