From 62b091ef5e0a09de8f741a518ab4d1ed341fadfa Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Tue, 4 Jun 2019 13:36:56 -0500 Subject: [PATCH] Fix modelManager sync observer now being syncronous --- .../javascripts/app/controllers/tags.js | 28 ++++++++++--------- app/assets/templates/home.html.haml | 3 +- package-lock.json | 6 ++-- package.json | 2 +- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/app/controllers/tags.js b/app/assets/javascripts/app/controllers/tags.js index b653a8d89..f72ff9df3 100644 --- a/app/assets/javascripts/app/controllers/tags.js +++ b/app/assets/javascripts/app/controllers/tags.js @@ -30,28 +30,30 @@ angular.module('app') || syncEvent == "local-data-incremental-load") { this.tags = modelManager.tags; this.smartTags = modelManager.getSmartTags(); + if(this.noteCountsNeedReload) { + this.noteCountsNeedReload = false; + this.reloadNoteCounts(); + } } }); - modelManager.addItemSyncObserver("note-list", "*", (allItems, validItems, deletedItems, source, sourceKey) => { - // recompute note counts - let tags = []; - if(this.tags) { - tags = tags.concat(this.tags); - } - if(this.smartTags) { - tags = tags.concat(this.smartTags); - } + modelManager.addItemSyncObserver("tags-list", "*", (allItems, validItems, deletedItems, source, sourceKey) => { + this.noteCountsNeedReload = true; + }); - for(let tag of tags) { - var validNotes = SNNote.filterDummyNotes(tag.notes).filter(function(note){ + this.reloadNoteCounts = function() { + let allTags = []; + if(this.tags) { allTags = allTags.concat(this.tags);} + if(this.smartTags) { allTags = allTags.concat(this.smartTags);} + + for(let tag of allTags) { + var validNotes = SNNote.filterDummyNotes(tag.notes).filter((note) => { return !note.archived && !note.content.trashed; }); tag.cachedNoteCount = validNotes.length; } - }); - + } this.panelController = {}; diff --git a/app/assets/templates/home.html.haml b/app/assets/templates/home.html.haml index 7b408e005..e0ba05513 100644 --- a/app/assets/templates/home.html.haml +++ b/app/assets/templates/home.html.haml @@ -3,8 +3,7 @@ %lock-screen{"ng-if" => "needsUnlock", "on-success" => "onSuccessfulUnlock"} .app#app{"ng-if" => "!needsUnlock", "ng-class" => "appClass"} - %tags-section{"save" => "tagsSave", "add-new" => "tagsAddNew", "selection-made" => "tagsSelectionMade", - "tags" => "tags", "remove-tag" => "removeTag"} + %tags-section{"save" => "tagsSave", "add-new" => "tagsAddNew", "selection-made" => "tagsSelectionMade", "remove-tag" => "removeTag"} %notes-section{"add-new" => "notesAddNew", "selection-made" => "notesSelectionMade", "tag" => "selectedTag"} %editor-section{"note" => "selectedNote", "remove" => "deleteNote", "update-tags" => "updateTagsForNote"} diff --git a/package-lock.json b/package-lock.json index c2bf4ef0a..682441fce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5724,9 +5724,9 @@ } }, "snjs": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/snjs/-/snjs-0.2.6.tgz", - "integrity": "sha512-nBWwzNcOKtCj6Z0f0buD/vswd3agU+sI2KHWQuUn1tuhNoGdzh20DgjcmxEEmW7QiiEkvZHDL/TC8N47tx66SQ==", + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/snjs/-/snjs-0.2.7.tgz", + "integrity": "sha512-MPegTzgrQY5xh24jBsAQKqxiCpLDDtgelcrv4G1Xz6yZqH2H2WrUTr7YSE1QCPbKHMXvuX7kn/cTDchyhEdESQ==", "dev": true }, "source-map": { diff --git a/package.json b/package.json index d937db359..45c7008b5 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "mocha": "^5.2.0", "serve-static": "^1.13.2", "sn-stylekit": "2.0.15", - "snjs": "0.2.6", + "snjs": "0.2.7", "standard-file-js": "0.3.63" } }