From 3737a0162076cd58348bb790c49795d3d4022b09 Mon Sep 17 00:00:00 2001 From: Mo Date: Tue, 11 Jan 2022 13:07:39 -0600 Subject: [PATCH 1/5] feat: use snjs tag notes index for note counts --- .../ui_models/app_state/tags_state.ts | 47 +++++-------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state/tags_state.ts b/app/assets/javascripts/ui_models/app_state/tags_state.ts index ba9325c78be..c92476bc45f 100644 --- a/app/assets/javascripts/ui_models/app_state/tags_state.ts +++ b/app/assets/javascripts/ui_models/app_state/tags_state.ts @@ -126,9 +126,6 @@ export class TagsState { ) as SNTag[]; this.smartTags = this.application.getSmartTags(); - this.tagsCountsState.update(this.tags); - this.allNotesCount_ = this.countAllNotes(); - const selectedTag = this.selected_; if (selectedTag) { const matchingTag = items.find( @@ -150,13 +147,13 @@ export class TagsState { ); appEventListeners.push( - this.application.addEventObserver(async (eventName) => { - switch (eventName) { - case ApplicationEvent.CompletedIncrementalSync: - runInAction(() => { - this.allNotesCount_ = this.countAllNotes(); - }); - break; + this.application.addNoteCountChangeObserver((tagUuid) => { + if (!tagUuid) { + this.allNotesCount_ = this.application.allCountableNotesCount(); + } else { + this.tagsCountsState.update([ + this.application.findItem(tagUuid) as SNTag, + ]); } }) ); @@ -390,23 +387,6 @@ export class TagsState { } } - private countAllNotes(): number { - const allTag = this.application.getSmartTags().find((tag) => tag.isAllTag); - - if (!allTag) { - console.error(STRING_MISSING_SYSTEM_TAG); - return -1; - } - - const notes = this.application - .notesMatchingSmartTag(allTag) - .filter((note) => { - return !note.archived && !note.trashed; - }); - - return notes.length; - } - public onFoldersComponentMessage( action: ComponentAction, data: MessageData @@ -439,9 +419,6 @@ export class TagsState { } } -/** - * Bug fix for issue 1201550111577311, - */ class TagsCountsState { public counts: { [uuid: string]: number } = {}; @@ -453,13 +430,13 @@ class TagsCountsState { } public update(tags: SNTag[]) { - const newCounts: { [uuid: string]: number } = {}; + const newCounts: { [uuid: string]: number } = Object.assign( + {}, + this.counts + ); tags.forEach((tag) => { - newCounts[tag.uuid] = this.application.referencesForItem( - tag, - ContentType.Note - ).length; + newCounts[tag.uuid] = this.application.countableNotesForTag(tag); }); this.counts = newCounts; From b9a59dd02dde85fc284f2dc81410c32c98e91dec Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 17 Jan 2022 10:40:20 +0100 Subject: [PATCH 2/5] style: clean up style --- app/assets/javascripts/ui_models/app_state/tags_state.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state/tags_state.ts b/app/assets/javascripts/ui_models/app_state/tags_state.ts index c92476bc45f..68f1aa6e3a3 100644 --- a/app/assets/javascripts/ui_models/app_state/tags_state.ts +++ b/app/assets/javascripts/ui_models/app_state/tags_state.ts @@ -1,7 +1,6 @@ import { confirmDialog } from '@/services/alertService'; -import { STRING_DELETE_TAG, STRING_MISSING_SYSTEM_TAG } from '@/strings'; +import { STRING_DELETE_TAG } from '@/strings'; import { - ApplicationEvent, ComponentAction, ContentType, MessageData, @@ -9,7 +8,7 @@ import { SNSmartTag, SNTag, TagMutator, - UuidString, + UuidString } from '@standardnotes/snjs'; import { action, @@ -17,7 +16,7 @@ import { makeAutoObservable, makeObservable, observable, - runInAction, + runInAction } from 'mobx'; import { WebApplication } from '../application'; import { FeaturesState, SMART_TAGS_FEATURE_NAME } from './features_state'; From b0544dc2ef295ea881eaf3ce4c8f2f4e35bd3af1 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 17 Jan 2022 13:59:31 +0100 Subject: [PATCH 3/5] fix: typo on parent check (#811) --- .../ui_models/app_state/tags_state.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state/tags_state.ts b/app/assets/javascripts/ui_models/app_state/tags_state.ts index ba9325c78be..63d3acc1a82 100644 --- a/app/assets/javascripts/ui_models/app_state/tags_state.ts +++ b/app/assets/javascripts/ui_models/app_state/tags_state.ts @@ -199,32 +199,33 @@ export class TagsState { public async assignParent( tagUuid: string, - parentUuid: string | undefined + futureParentUuid: string | undefined ): Promise { const tag = this.application.findItem(tagUuid) as SNTag; const currentParent = this.application.getTagParent(tag); - const currentParentUuid = currentParent?.parentId; + const currentParentUuid = currentParent?.uuid; - if (currentParentUuid === parentUuid) { + if (currentParentUuid === futureParentUuid) { return; } - const parent = - parentUuid && (this.application.findItem(parentUuid) as SNTag); + const futureParent = + futureParentUuid && + (this.application.findItem(futureParentUuid) as SNTag); - if (!parent) { + if (!futureParent) { const futureSiblings = rootTags(this.application); if (!isValidFutureSiblings(this.application, futureSiblings, tag)) { return; } await this.application.unsetTagParent(tag); } else { - const futureSiblings = this.application.getTagChildren(parent); + const futureSiblings = this.application.getTagChildren(futureParent); if (!isValidFutureSiblings(this.application, futureSiblings, tag)) { return; } - await this.application.setTagParent(parent, tag); + await this.application.setTagParent(futureParent, tag); } await this.application.sync(); From e33e377b1417a45fdc8ba5b78b6848d0afbdc480 Mon Sep 17 00:00:00 2001 From: Mo Date: Tue, 11 Jan 2022 13:07:39 -0600 Subject: [PATCH 4/5] feat: use snjs tag notes index for note counts --- .../ui_models/app_state/tags_state.ts | 47 +++++-------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state/tags_state.ts b/app/assets/javascripts/ui_models/app_state/tags_state.ts index 63d3acc1a82..bc077bd0bac 100644 --- a/app/assets/javascripts/ui_models/app_state/tags_state.ts +++ b/app/assets/javascripts/ui_models/app_state/tags_state.ts @@ -126,9 +126,6 @@ export class TagsState { ) as SNTag[]; this.smartTags = this.application.getSmartTags(); - this.tagsCountsState.update(this.tags); - this.allNotesCount_ = this.countAllNotes(); - const selectedTag = this.selected_; if (selectedTag) { const matchingTag = items.find( @@ -150,13 +147,13 @@ export class TagsState { ); appEventListeners.push( - this.application.addEventObserver(async (eventName) => { - switch (eventName) { - case ApplicationEvent.CompletedIncrementalSync: - runInAction(() => { - this.allNotesCount_ = this.countAllNotes(); - }); - break; + this.application.addNoteCountChangeObserver((tagUuid) => { + if (!tagUuid) { + this.allNotesCount_ = this.application.allCountableNotesCount(); + } else { + this.tagsCountsState.update([ + this.application.findItem(tagUuid) as SNTag, + ]); } }) ); @@ -391,23 +388,6 @@ export class TagsState { } } - private countAllNotes(): number { - const allTag = this.application.getSmartTags().find((tag) => tag.isAllTag); - - if (!allTag) { - console.error(STRING_MISSING_SYSTEM_TAG); - return -1; - } - - const notes = this.application - .notesMatchingSmartTag(allTag) - .filter((note) => { - return !note.archived && !note.trashed; - }); - - return notes.length; - } - public onFoldersComponentMessage( action: ComponentAction, data: MessageData @@ -440,9 +420,6 @@ export class TagsState { } } -/** - * Bug fix for issue 1201550111577311, - */ class TagsCountsState { public counts: { [uuid: string]: number } = {}; @@ -454,13 +431,13 @@ class TagsCountsState { } public update(tags: SNTag[]) { - const newCounts: { [uuid: string]: number } = {}; + const newCounts: { [uuid: string]: number } = Object.assign( + {}, + this.counts + ); tags.forEach((tag) => { - newCounts[tag.uuid] = this.application.referencesForItem( - tag, - ContentType.Note - ).length; + newCounts[tag.uuid] = this.application.countableNotesForTag(tag); }); this.counts = newCounts; From 1a8d46b0d89ce1249c595e706098406842bfeb2f Mon Sep 17 00:00:00 2001 From: Mo Date: Mon, 17 Jan 2022 07:29:34 -0600 Subject: [PATCH 5/5] chore: bump deps --- package.json | 4 ++-- yarn.lock | 42 +++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index de06565d024..36108932271 100644 --- a/package.json +++ b/package.json @@ -86,8 +86,8 @@ "@reach/listbox": "^0.16.2", "@reach/tooltip": "^0.16.2", "@standardnotes/components": "1.4.0", - "@standardnotes/features": "1.24.0", - "@standardnotes/snjs": "2.38.0", + "@standardnotes/features": "1.24.3", + "@standardnotes/snjs": "2.40.0", "@standardnotes/settings": "^1.9.0", "@standardnotes/sncrypto-web": "1.6.0", "mobx": "^6.3.5", diff --git a/yarn.lock b/yarn.lock index 3abfae68e0d..90746d9e48d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2597,10 +2597,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@standardnotes/auth@^3.14.1": - version "3.14.1" - resolved "https://registry.yarnpkg.com/@standardnotes/auth/-/auth-3.14.1.tgz#4719dd60590bbf8062aa83a293e1fcd8a616f13e" - integrity sha512-Phnp0FtP11ZhqByRyuIEFJxT0Z20KfcTn2yTwi6XIkPBuQFR152p924pFbv57w9/rVN6Tr10kCZ32Y5rk5owRQ== +"@standardnotes/auth@^3.15.2": + version "3.15.2" + resolved "https://registry.yarnpkg.com/@standardnotes/auth/-/auth-3.15.2.tgz#63a47785191e2a9f6761320375c76d9b3a0caf64" + integrity sha512-fN497p0eyG4mp13vvhRD6ULyPMT7QAl3wRyBZMsNlNBuGQJNMS1rfSsU9u59AeAifkyARnfl+8SzVtwXKHlSSg== dependencies: "@standardnotes/common" "^1.8.0" jsonwebtoken "^8.5.1" @@ -2615,19 +2615,19 @@ resolved "https://registry.yarnpkg.com/@standardnotes/components/-/components-1.4.0.tgz#0bb790965683b3fa56e3231b95cad9871e1db271" integrity sha512-8Zo2WV7Q+pWdmAf+rG3NCNtVM4N1P52T1sDijapz8xqtArT28wxWZkJ+qfBJ0lT5GmXxYZl8rY/tAkx4hQ5zSA== -"@standardnotes/domain-events@^2.16.5": - version "2.16.5" - resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.16.5.tgz#9f7817100885ea55ccc0f49501c4e4c7bf32c649" - integrity sha512-v4r/btJbv1AQ/NLs3AtiEbNKxOyujYmSD/DbUX7F9Td/DqBFNhIzrFQx7GB1hRDvVFwq9iIY3oAIZShEOlLJSg== +"@standardnotes/domain-events@^2.16.8": + version "2.16.8" + resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.16.8.tgz#74e6a9879c9b4476d92a16253ae9d75cab4b8162" + integrity sha512-VHXEtXSNb01ensASq0d1iB4yMUdgBVlfeHp2LQNwK8fwtvdQOyPCfnOFdMaUjW+Y/nBFRz6swDtrLFLeknzlcw== dependencies: - "@standardnotes/auth" "^3.14.1" + "@standardnotes/auth" "^3.15.2" -"@standardnotes/features@1.24.0", "@standardnotes/features@^1.24.0": - version "1.24.0" - resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.24.0.tgz#1d5060971d3cfb19dd44e598aa1f7e2f9800a3a0" - integrity sha512-566hhMohQlH6lLZYlfaI4j2+iGOwZh7DBQ0wC9chdchbJtmzmwA8c7m6d2sHpziM6qj234EO7xbtjE4m8CPQuQ== +"@standardnotes/features@1.24.3", "@standardnotes/features@^1.24.3": + version "1.24.3" + resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.24.3.tgz#f59616b1de7dba30a05e983ac53e6d86e6e2a503" + integrity sha512-WgI+aUcPZgJexir1ceAR5aumsnXUiLL3VtFHPlIOoSKsnfbcTYgizMkdhxI+CeBV+kKCOUGqTGEjXdaXZajO7g== dependencies: - "@standardnotes/auth" "^3.14.1" + "@standardnotes/auth" "^3.15.2" "@standardnotes/common" "^1.8.0" "@standardnotes/settings@^1.9.0": @@ -2649,15 +2649,15 @@ buffer "^6.0.3" libsodium-wrappers "^0.7.9" -"@standardnotes/snjs@2.38.0": - version "2.38.0" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.38.0.tgz#8ed8a43efed40635e92e1f08162b29f59bee5027" - integrity sha512-5O5fNZ1O4u3t1Jjfs54k7bzpxusGXr9+R598OJXk5O4TdFlMxSxIiZReY/SpAq2qUMgUOpyGnsYsYXbxTiQh9A== +"@standardnotes/snjs@2.40.0": + version "2.40.0" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.40.0.tgz#8b4e96bd11bdf4ea7f5c9d1cff869ad1a309245a" + integrity sha512-UBlMFp8Dj88snSKmi9vUVn97/EM5aidIWhZXQcFa1/OZHg7HVUbIPrLSVy8ftY6WNCPDXjNSE0cy2fozN9W2rQ== dependencies: - "@standardnotes/auth" "^3.14.1" + "@standardnotes/auth" "^3.15.2" "@standardnotes/common" "^1.8.0" - "@standardnotes/domain-events" "^2.16.5" - "@standardnotes/features" "^1.24.0" + "@standardnotes/domain-events" "^2.16.8" + "@standardnotes/features" "^1.24.3" "@standardnotes/settings" "^1.9.0" "@standardnotes/sncrypto-common" "^1.6.0"