refactor(web): dependency management (#2386)

This commit is contained in:
Mo
2023-08-05 12:48:39 -05:00
committed by GitHub
parent b07da5b663
commit d8d4052a52
274 changed files with 4065 additions and 3873 deletions

View File

@@ -1,34 +1,27 @@
import { storage, StorageKey } from '@standardnotes/ui-services'
import { ApplicationEvent, InternalEventBusInterface } from '@standardnotes/snjs'
import {
ApplicationEvent,
InternalEventBusInterface,
InternalEventHandlerInterface,
InternalEventInterface,
SessionsClientInterface,
} from '@standardnotes/snjs'
import { runInAction, makeObservable, observable, action } from 'mobx'
import { WebApplication } from '../Application/WebApplication'
import { AbstractViewController } from './Abstract/AbstractViewController'
export class NoAccountWarningController extends AbstractViewController {
export class NoAccountWarningController extends AbstractViewController implements InternalEventHandlerInterface {
show: boolean
constructor(application: WebApplication, eventBus: InternalEventBusInterface) {
super(application, eventBus)
constructor(
private sessions: SessionsClientInterface,
eventBus: InternalEventBusInterface,
) {
super(eventBus)
this.show = application.hasAccount() ? false : storage.get(StorageKey.ShowNoAccountWarning) ?? true
this.show = sessions.isSignedIn() ? false : storage.get(StorageKey.ShowNoAccountWarning) ?? true
this.disposers.push(
application.addEventObserver(async () => {
runInAction(() => {
this.show = false
})
}, ApplicationEvent.SignedIn),
)
this.disposers.push(
application.addEventObserver(async () => {
if (application.hasAccount()) {
runInAction(() => {
this.show = false
})
}
}, ApplicationEvent.Started),
)
eventBus.addEventHandler(this, ApplicationEvent.SignedIn)
eventBus.addEventHandler(this, ApplicationEvent.Started)
makeObservable(this, {
show: observable,
@@ -36,6 +29,23 @@ export class NoAccountWarningController extends AbstractViewController {
})
}
async handleEvent(event: InternalEventInterface): Promise<void> {
switch (event.type) {
case ApplicationEvent.SignedIn:
runInAction(() => {
this.show = false
})
break
case ApplicationEvent.Started:
if (this.sessions.isSignedIn()) {
runInAction(() => {
this.show = false
})
}
break
}
}
hide = (): void => {
this.show = false
storage.set(StorageKey.ShowNoAccountWarning, false)