feat: display number of files for 'Files' view (#2065)

* feat: display number of files for 'Files' view

* feat: include files count in Preferences > Security
This commit is contained in:
Mo
2022-11-28 15:38:50 -06:00
committed by GitHub
parent 052e7d2f90
commit 767d354780
25 changed files with 69 additions and 91 deletions

View File

@@ -1,4 +1,3 @@
import { isNote } from './../../../Syncable/Note/Note'
import { removeFromArray } from '@standardnotes/utils'
import { ContentType, Uuid } from '@standardnotes/common'
import { isTag, SNTag } from '../../../Syncable/Tag/Tag'
@@ -13,7 +12,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>()
private countableItemsByType = new Map<ContentType, Set<Uuid>>()
constructor(private collection: ItemCollection, public observers: TagItemCountChangeObserver[] = []) {}
@@ -44,7 +43,11 @@ export class TagItemsIndex implements SNIndex {
}
public allCountableNotesCount(): number {
return this.allCountableNotes.size
return this.countableItemsByType.get(ContentType.Note)?.size || 0
}
public allCountableFilesCount(): number {
return this.countableItemsByType.get(ContentType.File)?.size || 0
}
public countableItemsForTag(tag: SNTag): number {
@@ -85,15 +88,14 @@ export class TagItemsIndex implements SNIndex {
if (isCountable) {
this.allCountableItems.add(item.uuid)
if (isNote(item)) {
this.allCountableNotes.add(item.uuid)
if (!this.countableItemsByType.has(item.content_type)) {
this.countableItemsByType.set(item.content_type, new Set())
}
this.countableItemsByType.get(item.content_type)?.add(item.uuid)
} else {
this.allCountableItems.delete(item.uuid)
if (isNote(item)) {
this.allCountableNotes.delete(item.uuid)
}
this.countableItemsByType.get(item.content_type)?.delete(item.uuid)
}
const associatedTagUuids = this.collection.uuidsThatReferenceUuid(item.uuid)

View File

@@ -12,10 +12,7 @@ import { PayloadTimestampDefaults } from '../../Abstract/Payload'
import { FilterDisplayOptions } from '../../Runtime/Display'
import { FileItem } from '../File'
export function BuildSmartViews(
options: FilterDisplayOptions,
{ supportsFileNavigation = false }: { supportsFileNavigation: boolean },
): SmartView[] {
export function BuildSmartViews(options: FilterDisplayOptions): SmartView[] {
const notes = new SmartView(
new DecryptedPayload({
uuid: SystemViewId.AllNotes,
@@ -88,11 +85,7 @@ export function BuildSmartViews(
}),
)
if (supportsFileNavigation) {
return [notes, starred, files, archived, trash, untagged]
} else {
return [notes, starred, archived, trash, untagged]
}
return [notes, files, starred, archived, trash, untagged]
}
function allNotesPredicate(options: FilterDisplayOptions) {