From feb68907d0cab826e0fbb8db68dfc7e377033e4c Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Sun, 10 Feb 2019 17:21:29 -0600 Subject: [PATCH] Fixes dummy note auto creation issue --- .../javascripts/app/controllers/notes.js | 29 +++++++++++++++---- package-lock.json | 12 ++++---- package.json | 4 +-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/app/controllers/notes.js b/app/assets/javascripts/app/controllers/notes.js index 455e56ae5..0a40f627c 100644 --- a/app/assets/javascripts/app/controllers/notes.js +++ b/app/assets/javascripts/app/controllers/notes.js @@ -35,9 +35,7 @@ angular.module('app') syncManager.addEventHandler((syncEvent, data) => { if(syncEvent == "local-data-loaded") { this.localDataLoaded = true; - if(this.tag && this.notes.length == 0) { - this.createNewNote(); - } + this.handledDataLoad = false; } }); @@ -45,6 +43,13 @@ angular.module('app') // reload our notes this.reloadNotes(); + if(!this.handledDataLoad) { + this.handledDataLoad = true; + 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) { @@ -55,7 +60,10 @@ angular.module('app') // select first note if none is selected if(!this.selectedNote) { - this.selectFirstNote(); + $timeout(() => { + // required to be in timeout since selecting notes depends on rendered notes + this.selectFirstNote(); + }) } }); @@ -71,7 +79,18 @@ angular.module('app') } this.reloadNotes = function() { - this.setNotes(this.tag.notes); + let notes = this.tag.notes; + + if(notes.length > 0 && this.selectedNote && this.selectedNote.dummy) { + // remove dummy + modelManager.removeItemLocally(this.selectedNote); + notes = _.pull(notes, this.selectedNote); + $timeout(() => { + this.selectFirstNote(); + }) + } + + this.setNotes(notes); } this.reorderNotes = function() { diff --git a/package-lock.json b/package-lock.json index 9e9b53338..b47062dc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4750,9 +4750,9 @@ "dev": true }, "sn-models": { - "version": "0.1.13", - "resolved": "https://registry.npmjs.org/sn-models/-/sn-models-0.1.13.tgz", - "integrity": "sha512-I7vKVXrpYOVVthDD37us9cWcbrhQ/9mTQ2uGXITUonaNIP06xfGgNaPDs9MRKj5F0+4PtiCLuVYkh9ibbtGtig==", + "version": "0.1.14", + "resolved": "https://registry.npmjs.org/sn-models/-/sn-models-0.1.14.tgz", + "integrity": "sha512-p5Tp18sKP68saA4EkdAeYo+X3dNdmGwgqPKL0Bi0Y6lv2SO0LiHPbcBxKcsQjrikE8ePUviJVeckRfMgR5QbYA==", "dev": true }, "sn-stylekit": { @@ -4830,9 +4830,9 @@ "dev": true }, "standard-file-js": { - "version": "0.3.44", - "resolved": "https://registry.npmjs.org/standard-file-js/-/standard-file-js-0.3.44.tgz", - "integrity": "sha512-9g/XQxL/j1ugOiX6eV5hTashi79JEOrA/IuifTcBPE09Lc0SEYtJM+33pVvoATQrYaa6NEHMTSPCpKl+2ZjTsA==", + "version": "0.3.46", + "resolved": "https://registry.npmjs.org/standard-file-js/-/standard-file-js-0.3.46.tgz", + "integrity": "sha512-fGym9hkkWr+Fi+FTsNWJXPXUNUkkVf3A/T2Jc1YqqLSK5/ze0Txo3Ij9pVIfWD7EQcTN6arI7vw1ErpoXWfMaw==", "dev": true }, "statuses": { diff --git a/package.json b/package.json index ba6c9634a..ef51dd51d 100644 --- a/package.json +++ b/package.json @@ -36,9 +36,9 @@ "grunt-ng-annotate": "^3.0.0", "mocha": "^5.2.0", "serve-static": "^1.13.2", - "sn-models": "0.1.13", + "sn-models": "0.1.14", "sn-stylekit": "2.0.13", - "standard-file-js": "0.3.44", + "standard-file-js": "0.3.46", "grunt-shell": "^2.1.0" } }