Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/snjs.pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: actions/checkout@v3
- name: Install dependencies
run: yarn install --immutable
- name: Build
run: yarn build:snjs
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type StructuredItemsCount = {
export type ItemCounts = {
notes: number
tags: number
deleted: number
Expand Down
1 change: 1 addition & 0 deletions packages/models/src/Domain/Abstract/Item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export * from './Mutator/TransactionalMutation'
export * from './Types/AppDataField'
export * from './Types/ConflictStrategy'
export * from './Types/DefaultAppDomain'
export * from './Types/ItemCounts'
export * from './Types/ItemStream'
export * from './Types/MutationType'
export * from './Types/SingletonStrategy'
31 changes: 31 additions & 0 deletions packages/services/src/Domain/Item/ItemCounter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ContentType } from '@standardnotes/common'
import { SNNote, SNTag } from '@standardnotes/models'
import { ItemCounter } from './ItemCounter'

describe('ItemCounter', () => {
const createCounter = () => new ItemCounter()

it('should count distinct item counts', () => {
const items = [
{
archived: true,
} as jest.Mocked<SNNote>,
{
trashed: true,
} as jest.Mocked<SNNote>,
{
content_type: ContentType.Note,
} as jest.Mocked<SNNote>,
{
content_type: ContentType.Tag,
} as jest.Mocked<SNTag>,
]

expect(createCounter().countNotesAndTags(items)).toEqual({
archived: 1,
deleted: 1,
notes: 1,
tags: 1,
})
})
})
40 changes: 40 additions & 0 deletions packages/services/src/Domain/Item/ItemCounter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ContentType } from '@standardnotes/common'
import { SNNote, SNTag, ItemCounts } from '@standardnotes/models'

import { ItemCounterInterface } from './ItemCounterInterface'

export class ItemCounter implements ItemCounterInterface {
countNotesAndTags(items: Array<SNNote | SNTag>): ItemCounts {
const counts: ItemCounts = {
notes: 0,
archived: 0,
deleted: 0,
tags: 0,
}

for (const item of items) {
if (item.archived) {
counts.archived++

continue
}
if (item.trashed) {
counts.deleted++

continue
}
if (item.content_type === ContentType.Note) {
counts.notes++

continue
}
if (item.content_type === ContentType.Tag) {
counts.tags++

continue
}
}

return counts
}
}
5 changes: 5 additions & 0 deletions packages/services/src/Domain/Item/ItemCounterInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SNNote, SNTag, ItemCounts } from '@standardnotes/models'

export interface ItemCounterInterface {
countNotesAndTags(items: Array<SNNote | SNTag>): ItemCounts
}
2 changes: 2 additions & 0 deletions packages/services/src/Domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export * from './Internal/InternalEventHandlerInterface'
export * from './Internal/InternalEventInterface'
export * from './Internal/InternalEventPublishStrategy'
export * from './Internal/InternalEventType'
export * from './Item/ItemCounter'
export * from './Item/ItemCounterInterface'
export * from './Item/ItemManagerInterface'
export * from './Item/ItemsClientInterface'
export * from './Item/ItemsServerInterface'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { destroyAllObjectProperties, isDev } from '@/Utils'
import { action, computed, makeObservable, observable, runInAction } from 'mobx'
import { ApplicationEvent, ContentType, InternalEventBus, SNNote, SNTag } from '@standardnotes/snjs'
import {
ApplicationEvent,
ContentType,
InternalEventBus,
SNNote,
SNTag,
ItemCounterInterface,
ItemCounts,
} from '@standardnotes/snjs'
import { WebApplication } from '@/Application/Application'
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane'
import { AbstractViewController } from '../Abstract/AbstractViewController'
import { StructuredItemsCount } from './StructuredItemsCount'

export class AccountMenuController extends AbstractViewController {
show = false
Expand All @@ -28,7 +35,7 @@ export class AccountMenuController extends AbstractViewController {
destroyAllObjectProperties(this)
}

constructor(application: WebApplication, eventBus: InternalEventBus) {
constructor(application: WebApplication, eventBus: InternalEventBus, private itemCounter: ItemCounterInterface) {
super(application, eventBus)

makeObservable(this, {
Expand Down Expand Up @@ -152,30 +159,7 @@ export class AccountMenuController extends AbstractViewController {
return this.notesAndTags.length
}

get structuredNotesAndTagsCount(): StructuredItemsCount {
const count: StructuredItemsCount = {
notes: 0,
archived: 0,
deleted: 0,
tags: 0,
}
for (const item of this.notesAndTags) {
if (item.archived) {
count.archived++
}

if (item.trashed) {
count.deleted++
}

if (item.content_type === ContentType.Note) {
count.notes++
}

if (item.content_type === ContentType.Tag) {
count.tags++
}
}
return count
get structuredNotesAndTagsCount(): ItemCounts {
return this.itemCounter.countNotesAndTags(this.notesAndTags)
}
}
14 changes: 12 additions & 2 deletions packages/web/src/javascripts/Controllers/ViewControllerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { storage, StorageKey } from '@standardnotes/ui-services'
import { WebApplication } from '@/Application/Application'
import { AccountMenuController } from '@/Controllers/AccountMenu/AccountMenuController'
import { destroyAllObjectProperties } from '@/Utils'
import { ApplicationEvent, DeinitSource, WebOrDesktopDeviceInterface, InternalEventBus } from '@standardnotes/snjs'
import {
ApplicationEvent,
DeinitSource,
WebOrDesktopDeviceInterface,
InternalEventBus,
ItemCounterInterface,
ItemCounter,
} from '@standardnotes/snjs'
import { action, makeObservable, observable } from 'mobx'
import { ActionsMenuController } from './ActionsMenuController'
import { FeaturesController } from './FeaturesController'
Expand Down Expand Up @@ -52,10 +59,13 @@ export class ViewControllerManager {

private appEventObserverRemovers: (() => void)[] = []
private eventBus: InternalEventBus
private itemCounter: ItemCounterInterface

constructor(public application: WebApplication, private device: WebOrDesktopDeviceInterface) {
this.eventBus = new InternalEventBus()

this.itemCounter = new ItemCounter()

this.selectionController = new SelectedItemsController(application, this.eventBus)

this.noteTagsController = new NoteTagsController(application, this.eventBus)
Expand Down Expand Up @@ -90,7 +100,7 @@ export class ViewControllerManager {

this.noAccountWarningController = new NoAccountWarningController(application, this.eventBus)

this.accountMenuController = new AccountMenuController(application, this.eventBus)
this.accountMenuController = new AccountMenuController(application, this.eventBus, this.itemCounter)

this.subscriptionController = new SubscriptionController(application, this.eventBus)

Expand Down