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

View File

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

View File

@@ -40,14 +40,28 @@ angular.module('app')
modelManager.removeItemLocally(this.selectedNote); modelManager.removeItemLocally(this.selectedNote);
_.pull(this.notes, this.selectedNote); _.pull(this.notes, this.selectedNote);
this.selectedNote = null; 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) => { syncManager.addEventHandler((syncEvent, data) => {
if(syncEvent == "local-data-loaded") { if(syncEvent == "local-data-loaded") {
this.localDataLoaded = true; if(this.notes.length == 0) {
this.needsHandleDataLoad = true; 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 // reload our notes
this.reloadNotes(); this.reloadNotes();
if(this.needsHandleDataLoad) {
this.needsHandleDataLoad = false;
if(this.tag && this.notes.length == 0) {
this.createNewNote();
}
}
// Note has changed values, reset its flags // Note has changed values, reset its flags
let notes = allItems.filter((item) => item.content_type == "Note"); let notes = allItems.filter((item) => item.content_type == "Note");
for(let note of notes) { for(let note of notes) {
@@ -305,8 +312,8 @@ angular.module('app')
this.showMenu = false; this.showMenu = false;
if(this.selectedNote && this.selectedNote.dummy) { if(this.selectedNote) {
if(oldTag) { if(this.selectedNote.dummy && oldTag) {
_.remove(oldTag.notes, this.selectedNote); _.remove(oldTag.notes, this.selectedNote);
} }
} }
@@ -320,8 +327,14 @@ angular.module('app')
if(this.notes.length > 0) { if(this.notes.length > 0) {
this.notes.forEach((note) => { note.visible = true; }) this.notes.forEach((note) => { note.visible = true; })
this.selectFirstNote(); this.selectFirstNote();
} else if(this.localDataLoaded) { } else if(syncManager.initialDataLoaded()) {
this.createNewNote(); 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) { this.selectNote = async function(note, viaClick = false) {
if(!note) { if(!note) {
this.selectionMade()(null);
return; return;
} }

View File

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

View File

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

12
package-lock.json generated
View File

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

View File

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