fix: exclude files from being counted in 'Notes' view (#2062)

This commit is contained in:
Mo
2022-11-28 11:11:55 -06:00
committed by GitHub
parent 4181a4cca0
commit 2b0c9b188c
2 changed files with 17 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import { isNote } from './../../../Syncable/Note/Note'
import { removeFromArray } from '@standardnotes/utils'
import { ContentType, Uuid } from '@standardnotes/common'
import { isTag, SNTag } from '../../../Syncable/Tag/Tag'
@@ -12,6 +13,7 @@ export type TagItemCountChangeObserver = (tagUuid: Uuid | AllNotesUuidSignifier)
export class TagItemsIndex implements SNIndex {
private tagToItemsMap: Partial<Record<Uuid, Set<Uuid>>> = {}
private allCountableItems = new Set<Uuid>()
private allCountableNotes = new Set<Uuid>()
constructor(private collection: ItemCollection, public observers: TagItemCountChangeObserver[] = []) {}
@@ -41,6 +43,10 @@ export class TagItemsIndex implements SNIndex {
return this.allCountableItems.size
}
public allCountableNotesCount(): number {
return this.allCountableNotes.size
}
public countableItemsForTag(tag: SNTag): number {
return this.tagToItemsMap[tag.uuid]?.size || 0
}
@@ -75,10 +81,19 @@ export class TagItemsIndex implements SNIndex {
for (const item of items) {
const isCountable = this.isItemCountable(item)
if (isCountable) {
this.allCountableItems.add(item.uuid)
if (isNote(item)) {
this.allCountableNotes.add(item.uuid)
}
} else {
this.allCountableItems.delete(item.uuid)
if (isNote(item)) {
this.allCountableNotes.delete(item.uuid)
}
}
const associatedTagUuids = this.collection.uuidsThatReferenceUuid(item.uuid)

View File

@@ -289,13 +289,13 @@ export class ItemManager
}
public allCountableNotesCount(): number {
return this.tagItemsIndex.allCountableItemsCount()
return this.tagItemsIndex.allCountableNotesCount()
}
public countableNotesForTag(tag: Models.SNTag | Models.SmartView): number {
if (tag instanceof Models.SmartView) {
if (tag.uuid === Models.SystemViewId.AllNotes) {
return this.tagItemsIndex.allCountableItemsCount()
return this.tagItemsIndex.allCountableNotesCount()
}
throw Error('countableItemsForTag is not meant to be used for smart views.')