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;