Handle case where currently selected note is deleted by a remote sync
This commit is contained in:
@@ -40,6 +40,26 @@ angular.module('app')
|
||||
this.loadTagsString();
|
||||
}.bind(this));
|
||||
|
||||
modelManager.addItemSyncObserver("component-manager", "Note", (allItems, validItems, deletedItems, source) => {
|
||||
if(!this.note) { return; }
|
||||
if(!ModelManager.isMappingSourceRetrieved(source)) {return;}
|
||||
|
||||
var matchingNote = allItems.find((item) => {
|
||||
return item.uuid == this.note.uuid;
|
||||
});
|
||||
|
||||
if(!matchingNote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(matchingNote.deleted) {
|
||||
$rootScope.notifyDelete();
|
||||
} else {
|
||||
// Update tags
|
||||
this.loadTagsString();
|
||||
}
|
||||
});
|
||||
|
||||
this.noteDidChange = function(note, oldNote) {
|
||||
this.setNote(note, oldNote);
|
||||
this.reloadComponentContext();
|
||||
|
||||
@@ -226,7 +226,7 @@ angular.module('app')
|
||||
this.$apply(fn);
|
||||
};
|
||||
|
||||
$scope.notifyDelete = function() {
|
||||
$rootScope.notifyDelete = function() {
|
||||
$timeout(function() {
|
||||
$rootScope.$broadcast("noteDeleted");
|
||||
}.bind(this), 0);
|
||||
@@ -242,7 +242,7 @@ angular.module('app')
|
||||
|
||||
if(note.dummy) {
|
||||
modelManager.removeItemLocally(note);
|
||||
$scope.notifyDelete();
|
||||
$rootScope.notifyDelete();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -250,11 +250,11 @@ angular.module('app')
|
||||
if(authManager.offline()) {
|
||||
// when deleting items while ofline, we need to explictly tell angular to refresh UI
|
||||
setTimeout(function () {
|
||||
$scope.notifyDelete();
|
||||
$rootScope.notifyDelete();
|
||||
$scope.safeApply();
|
||||
}, 50);
|
||||
} else {
|
||||
$scope.notifyDelete();
|
||||
$rootScope.notifyDelete();
|
||||
}
|
||||
}, null, "deleteNote");
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ angular.module('app')
|
||||
this.onNoteRemoval = function() {
|
||||
let visibleNotes = this.visibleNotes();
|
||||
if(this.selectedIndex < visibleNotes.length) {
|
||||
this.selectNote(visibleNotes[this.selectedIndex]);
|
||||
this.selectNote(visibleNotes[Math.max(this.selectedIndex, 0)]);
|
||||
} else {
|
||||
this.selectNote(visibleNotes[visibleNotes.length - 1]);
|
||||
}
|
||||
@@ -190,11 +190,14 @@ angular.module('app')
|
||||
}
|
||||
|
||||
this.selectNote = function(note, viaClick = false) {
|
||||
if(!note) { return; }
|
||||
if(!note) {
|
||||
this.createNewNote();
|
||||
return;
|
||||
}
|
||||
this.selectedNote = note;
|
||||
note.conflict_of = null; // clear conflict
|
||||
this.selectionMade()(note);
|
||||
this.selectedIndex = this.visibleNotes().indexOf(note);
|
||||
this.selectedIndex = Math.max(this.visibleNotes().indexOf(note), 0);
|
||||
|
||||
if(viaClick && this.isFiltering()) {
|
||||
desktopManager.searchText(this.noteFilter.text);
|
||||
|
||||
@@ -10,6 +10,14 @@ class ModelManager {
|
||||
ModelManager.MappingSourceRemoteActionRetrieved = "MappingSourceRemoteActionRetrieved"; /* aciton-based Extensions like note history */
|
||||
ModelManager.MappingSourceFileImport = "MappingSourceFileImport";
|
||||
|
||||
ModelManager.isMappingSourceRetrieved = (source) => {
|
||||
return [
|
||||
ModelManager.MappingSourceRemoteRetrieved,
|
||||
ModelManager.MappingSourceComponentRetrieved,
|
||||
ModelManager.MappingSourceRemoteActionRetrieved
|
||||
].includes(source);
|
||||
}
|
||||
|
||||
this.storageManager = storageManager;
|
||||
this.notes = [];
|
||||
this.tags = [];
|
||||
|
||||
Reference in New Issue
Block a user