From 2fda84d5ddb3df4be17ac2a7e5a188980bb6a042 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 17 Jan 2022 10:33:12 +0100 Subject: [PATCH] refactor: allow countable over smarttags --- packages/snjs/lib/application.ts | 2 +- packages/snjs/lib/services/item_manager.ts | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/snjs/lib/application.ts b/packages/snjs/lib/application.ts index 2a75b5e0c..ce7c7a3cb 100644 --- a/packages/snjs/lib/application.ts +++ b/packages/snjs/lib/application.ts @@ -868,7 +868,7 @@ export class SNApplication { return this.itemManager.allCountableNotesCount(); } - public countableNotesForTag(tag: SNTag): number { + public countableNotesForTag(tag: SNTag | SNSmartTag): number { return this.itemManager.countableNotesForTag(tag); } diff --git a/packages/snjs/lib/services/item_manager.ts b/packages/snjs/lib/services/item_manager.ts index 564514d05..1ee4514bb 100644 --- a/packages/snjs/lib/services/item_manager.ts +++ b/packages/snjs/lib/services/item_manager.ts @@ -14,34 +14,35 @@ import { CreateMaxPayloadFromAnyObject } from '@Payloads/generator'; import { CollectionSort, ItemCollection, - SortDirection + SortDirection, } from '@Protocol/collection/item_collection'; -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/common'; import { ComponentMutator } from './../models/app/component'; import { ActionsExtensionMutator, - SNActionsExtension + SNActionsExtension, } from './../models/app/extension'; import { FeatureRepoMutator, - SNFeatureRepo + SNFeatureRepo, } from './../models/app/feature_repo'; import { ItemsKeyMutator } from './../models/app/items_key'; import { NoteMutator, SNNote } from './../models/app/note'; import { SmartTagPredicateContent, SMART_TAG_DSL_PREFIX, - SNSmartTag + SNSmartTag, } from './../models/app/smartTag'; import { TagMutator } from './../models/app/tag'; import { ItemMutator, MutationType, SNItem } from './../models/core/item'; import { SNPredicate } from './../models/core/predicate'; import { - TagNoteCountChangeObserver, TagNotesIndex + TagNoteCountChangeObserver, + TagNotesIndex, } from './../protocol/collection/tag_notes_index'; import { PayloadContent, - PayloadOverride + PayloadOverride, } from './../protocol/payloads/generator'; import { PurePayload } from './../protocol/payloads/pure_payload'; import { PayloadSource } from './../protocol/payloads/sources'; @@ -272,8 +273,12 @@ export class ItemManager extends PureService { return this.tagNotesIndex.allCountableNotesCount(); } - public countableNotesForTag(tag: SNTag): number { + public countableNotesForTag(tag: SNTag | SNSmartTag): number { if (tag.isSmartTag) { + if (tag.isAllTag) { + return this.tagNotesIndex.allCountableNotesCount(); + } + throw Error( 'countableNotesForTag is not meant to be used for smart tags.' );