Improved dummy note handling, sfjs 0.3.61

This commit is contained in:
Mo Bitar
2019-06-01 12:00:51 -05:00
parent bb282f868f
commit e8d8a91937
7 changed files with 42 additions and 30 deletions

View File

@@ -14,7 +14,7 @@ angular.module('app')
bindToController: true,
link:function(scope, elem, attrs, ctrl) {
scope.$watch('ctrl.note', function(note, oldNote){
scope.$watch('ctrl.note', (note, oldNote) => {
if(note) {
ctrl.noteDidChange(note, oldNote);
}
@@ -43,9 +43,7 @@ angular.module('app')
}
else if(eventName == "sync:completed") {
this.syncTakingTooLong = false;
if(this.note.dirty) {
// if we're still dirty, don't change status, a sync is likely upcoming.
} else {
@@ -283,8 +281,6 @@ angular.module('app')
return;
}
modelManager.setItemDirty(note, true, updateClientModified);
this.showSavingStatus();
if(!dontUpdatePreviews) {
@@ -292,11 +288,12 @@ angular.module('app')
var text = note.text || "";
var truncate = text.length > limit;
note.content.preview_plain = text.substring(0, limit) + (truncate ? "..." : "");
// Clear dynamic previews if using plain editor
note.content.preview_html = null;
}
modelManager.setItemDirty(note, true, updateClientModified);
if(this.saveTimeout) {
$timeout.cancel(this.saveTimeout);
}

View File

@@ -238,6 +238,7 @@ angular.module('app')
$scope.notesAddNew = function(note) {
modelManager.addItem(note);
modelManager.setItemDirty(note);
if(!$scope.selectedTag.isSmartTag()) {
$scope.selectedTag.addItemAsRelationship(note);

View File

@@ -40,14 +40,28 @@ angular.module('app')
modelManager.removeItemLocally(this.selectedNote);
_.pull(this.notes, this.selectedNote);
this.selectedNote = null;
this.selectNote(null);
// We now want to see if the user will download any items from the server.
// If the next sync completes and our notes are still 0, we need to create a dummy.
this.createDummyOnSynCompletionIfNoNotes = true;
}
}
})
syncManager.addEventHandler((syncEvent, data) => {
if(syncEvent == "local-data-loaded") {
this.localDataLoaded = true;
this.needsHandleDataLoad = true;
if(this.notes.length == 0) {
this.createNewNote();
}
} else if(syncEvent == "sync:completed") {
// Pad with a timeout just to be extra patient
$timeout(() => {
if(this.createDummyOnSynCompletionIfNoNotes && this.notes.length == 0) {
this.createDummyOnSynCompletionIfNoNotes = false;
this.createNewNote();
}
}, 100)
}
});
@@ -55,13 +69,6 @@ angular.module('app')
// reload our notes
this.reloadNotes();
if(this.needsHandleDataLoad) {
this.needsHandleDataLoad = false;
if(this.tag && this.notes.length == 0) {
this.createNewNote();
}
}
// Note has changed values, reset its flags
let notes = allItems.filter((item) => item.content_type == "Note");
for(let note of notes) {
@@ -305,8 +312,8 @@ angular.module('app')
this.showMenu = false;
if(this.selectedNote && this.selectedNote.dummy) {
if(oldTag) {
if(this.selectedNote) {
if(this.selectedNote.dummy && oldTag) {
_.remove(oldTag.notes, this.selectedNote);
}
}
@@ -320,8 +327,14 @@ angular.module('app')
if(this.notes.length > 0) {
this.notes.forEach((note) => { note.visible = true; })
this.selectFirstNote();
} else if(this.localDataLoaded) {
this.createNewNote();
} else if(syncManager.initialDataLoaded()) {
if(!tag.isSmartTag()) {
this.createNewNote();
} else {
if(this.selectedNote && !this.notes.includes(this.selectedNote)) {
this.selectNote(null);
}
}
}
})
}
@@ -360,6 +373,7 @@ angular.module('app')
this.selectNote = async function(note, viaClick = false) {
if(!note) {
this.selectionMade()(null);
return;
}

View File

@@ -74,7 +74,7 @@ class ActionsManager {
if(!item.errorDecrypting) {
if(merge) {
var items = this.modelManager.mapResponseItemsToLocalModels([item], SFModelManager.MappingSourceRemoteActionRetrieved);
var items = await this.modelManager.mapResponseItemsToLocalModels([item], SFModelManager.MappingSourceRemoteActionRetrieved);
for(var mappedItem of items) {
this.modelManager.setItemDirty(mappedItem, true);
}

View File

@@ -55,7 +55,7 @@ class NativeExtManager {
}, (valueCallback) => {
// Safe to create. Create and return object.
let url = window._extensions_manager_location;
console.log("Installing Extensions Manager from URL", url);
// console.log("Installing Extensions Manager from URL", url);
if(!url) {
console.error("window._extensions_manager_location must be set.");
return;
@@ -131,7 +131,7 @@ class NativeExtManager {
}, (valueCallback) => {
// Safe to create. Create and return object.
let url = window._batch_manager_location;
console.log("Installing Batch Manager from URL", url);
// console.log("Installing Batch Manager from URL", url);
if(!url) {
console.error("window._batch_manager_location must be set.");
return;

12
package-lock.json generated
View File

@@ -5724,9 +5724,9 @@
}
},
"snjs": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/snjs/-/snjs-0.2.3.tgz",
"integrity": "sha512-b8CR7AvIO7IQgxps970NgfqsIk+YUgreesa6ViELAxDAa7Cyqrh15sLk2LrNiQDrPw/WHKu+qWCAIu2w9pIzkQ==",
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/snjs/-/snjs-0.2.4.tgz",
"integrity": "sha512-WYrDWZpLnJ9PnE5d93ONGgCaN+D3y/kBdtI8orDkmbYsfSL0v5OX/Fbj96z6xMEskOFvXTH6vYO//LmlPrk4WQ==",
"dev": true
},
"source-map": {
@@ -5817,9 +5817,9 @@
"dev": true
},
"standard-file-js": {
"version": "0.3.60",
"resolved": "https://registry.npmjs.org/standard-file-js/-/standard-file-js-0.3.60.tgz",
"integrity": "sha512-dd7VPsQUt/+ZpOZzO7G1sM0euqjctPWBHSAwhr7AFyHSVlRBughGvmQl820ZYVuZsQo7trOCWedlprJAnhH7iQ==",
"version": "0.3.61",
"resolved": "https://registry.npmjs.org/standard-file-js/-/standard-file-js-0.3.61.tgz",
"integrity": "sha512-KxjtvYmZQIY9HIIDpW9Ss2cdMBID805Hjilz4xu7Ea2lZkTY4gk7/mx9x8/usNWeBEdfWvywQGFJ69iW6LZo1w==",
"dev": true
},
"static-extend": {

View File

@@ -39,7 +39,7 @@
"mocha": "^5.2.0",
"serve-static": "^1.13.2",
"sn-stylekit": "2.0.15",
"snjs": "0.2.3",
"standard-file-js": "0.3.60"
"snjs": "0.2.4",
"standard-file-js": "0.3.61"
}
}