refactor: rename states to view controllers (#1060)

This commit is contained in:
Mo
2022-06-01 10:15:45 -05:00
committed by GitHub
parent 78f39ec85d
commit 54125cec21
177 changed files with 1518 additions and 1365 deletions

View File

@@ -0,0 +1,57 @@
import { ApplicationEvent } from '@standardnotes/snjs'
import { makeObservable, observable, action, runInAction } from 'mobx'
import { WebApplication } from '../Application/Application'
import { AbstractViewController } from './Abstract/AbstractViewController'
export class SearchOptionsController extends AbstractViewController {
includeProtectedContents = false
includeArchived = false
includeTrashed = false
constructor(application: WebApplication, appObservers: (() => void)[]) {
super(application)
makeObservable(this, {
includeProtectedContents: observable,
includeTrashed: observable,
includeArchived: observable,
toggleIncludeArchived: action,
toggleIncludeTrashed: action,
toggleIncludeProtectedContents: action,
refreshIncludeProtectedContents: action,
})
appObservers.push(
this.application.addEventObserver(async () => {
this.refreshIncludeProtectedContents()
}, ApplicationEvent.UnprotectedSessionBegan),
this.application.addEventObserver(async () => {
this.refreshIncludeProtectedContents()
}, ApplicationEvent.UnprotectedSessionExpired),
)
}
toggleIncludeArchived = (): void => {
this.includeArchived = !this.includeArchived
}
toggleIncludeTrashed = (): void => {
this.includeTrashed = !this.includeTrashed
}
refreshIncludeProtectedContents = (): void => {
this.includeProtectedContents = this.application.hasUnprotectedAccessSession()
}
toggleIncludeProtectedContents = async (): Promise<void> => {
if (this.includeProtectedContents) {
this.includeProtectedContents = false
} else {
await this.application.authorizeSearchingProtectedNotesText()
runInAction(() => {
this.refreshIncludeProtectedContents()
})
}
}
}