fix: exclude files from being counted in 'Notes' view (#2062)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { isNote } from './../../../Syncable/Note/Note'
|
||||||
import { removeFromArray } from '@standardnotes/utils'
|
import { removeFromArray } from '@standardnotes/utils'
|
||||||
import { ContentType, Uuid } from '@standardnotes/common'
|
import { ContentType, Uuid } from '@standardnotes/common'
|
||||||
import { isTag, SNTag } from '../../../Syncable/Tag/Tag'
|
import { isTag, SNTag } from '../../../Syncable/Tag/Tag'
|
||||||
@@ -12,6 +13,7 @@ export type TagItemCountChangeObserver = (tagUuid: Uuid | AllNotesUuidSignifier)
|
|||||||
export class TagItemsIndex implements SNIndex {
|
export class TagItemsIndex implements SNIndex {
|
||||||
private tagToItemsMap: Partial<Record<Uuid, Set<Uuid>>> = {}
|
private tagToItemsMap: Partial<Record<Uuid, Set<Uuid>>> = {}
|
||||||
private allCountableItems = new Set<Uuid>()
|
private allCountableItems = new Set<Uuid>()
|
||||||
|
private allCountableNotes = new Set<Uuid>()
|
||||||
|
|
||||||
constructor(private collection: ItemCollection, public observers: TagItemCountChangeObserver[] = []) {}
|
constructor(private collection: ItemCollection, public observers: TagItemCountChangeObserver[] = []) {}
|
||||||
|
|
||||||
@@ -41,6 +43,10 @@ export class TagItemsIndex implements SNIndex {
|
|||||||
return this.allCountableItems.size
|
return this.allCountableItems.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public allCountableNotesCount(): number {
|
||||||
|
return this.allCountableNotes.size
|
||||||
|
}
|
||||||
|
|
||||||
public countableItemsForTag(tag: SNTag): number {
|
public countableItemsForTag(tag: SNTag): number {
|
||||||
return this.tagToItemsMap[tag.uuid]?.size || 0
|
return this.tagToItemsMap[tag.uuid]?.size || 0
|
||||||
}
|
}
|
||||||
@@ -75,10 +81,19 @@ export class TagItemsIndex implements SNIndex {
|
|||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const isCountable = this.isItemCountable(item)
|
const isCountable = this.isItemCountable(item)
|
||||||
|
|
||||||
if (isCountable) {
|
if (isCountable) {
|
||||||
this.allCountableItems.add(item.uuid)
|
this.allCountableItems.add(item.uuid)
|
||||||
|
|
||||||
|
if (isNote(item)) {
|
||||||
|
this.allCountableNotes.add(item.uuid)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.allCountableItems.delete(item.uuid)
|
this.allCountableItems.delete(item.uuid)
|
||||||
|
|
||||||
|
if (isNote(item)) {
|
||||||
|
this.allCountableNotes.delete(item.uuid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const associatedTagUuids = this.collection.uuidsThatReferenceUuid(item.uuid)
|
const associatedTagUuids = this.collection.uuidsThatReferenceUuid(item.uuid)
|
||||||
|
|||||||
@@ -289,13 +289,13 @@ export class ItemManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
public allCountableNotesCount(): number {
|
public allCountableNotesCount(): number {
|
||||||
return this.tagItemsIndex.allCountableItemsCount()
|
return this.tagItemsIndex.allCountableNotesCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
public countableNotesForTag(tag: Models.SNTag | Models.SmartView): number {
|
public countableNotesForTag(tag: Models.SNTag | Models.SmartView): number {
|
||||||
if (tag instanceof Models.SmartView) {
|
if (tag instanceof Models.SmartView) {
|
||||||
if (tag.uuid === Models.SystemViewId.AllNotes) {
|
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.')
|
throw Error('countableItemsForTag is not meant to be used for smart views.')
|
||||||
|
|||||||
Reference in New Issue
Block a user