From bba1d089bf60d5bfd0b91913e421cc94eab5c721 Mon Sep 17 00:00:00 2001 From: VardanHakobyan Date: Thu, 17 Jun 2021 17:51:45 +0400 Subject: [PATCH] refactor: set initial value of `server` on `Application.Launched` event --- .../ui_models/app_state/account_menu_state.ts | 17 +++++++++++------ .../ui_models/app_state/app_state.ts | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state/account_menu_state.ts b/app/assets/javascripts/ui_models/app_state/account_menu_state.ts index c3e58baa4..cf354e884 100644 --- a/app/assets/javascripts/ui_models/app_state/account_menu_state.ts +++ b/app/assets/javascripts/ui_models/app_state/account_menu_state.ts @@ -1,5 +1,5 @@ import { action, computed, makeObservable, observable, runInAction } from 'mobx'; -import { ContentType } from '@standardnotes/snjs'; +import { ApplicationEvent, ContentType } from '@standardnotes/snjs'; import { WebApplication } from '@/ui_models/application'; import { SNItem } from '@standardnotes/snjs/dist/@types/models/core/item'; @@ -16,6 +16,7 @@ export class AccountMenuState { constructor( private application: WebApplication, + appObservers: (() => void)[], appEventListeners: (() => void)[] ) { makeObservable(this, { @@ -39,16 +40,20 @@ export class AccountMenuState { notesAndTagsCount: computed }); + appObservers.push( + application.addEventObserver(async () => { + runInAction(() => { + this.setServer(this.application.getHost()); + }); + }, ApplicationEvent.Launched) + ); + appEventListeners.push( this.application.streamItems( - [ - ContentType.Note, ContentType.Tag, - ContentType.Component // TODO: is this correct for streaming `server`? - ], + [ContentType.Note, ContentType.Tag], () => { runInAction(() => { this.notesAndTags = this.application.getItems([ContentType.Note, ContentType.Tag]); - this.setServer(this.application.getHost()); }); } ) diff --git a/app/assets/javascripts/ui_models/app_state/app_state.ts b/app/assets/javascripts/ui_models/app_state/app_state.ts index 91330d101..5818fe1c2 100644 --- a/app/assets/javascripts/ui_models/app_state/app_state.ts +++ b/app/assets/javascripts/ui_models/app_state/app_state.ts @@ -106,6 +106,7 @@ export class AppState { ); this.accountMenu = new AccountMenuState( application, + this.appEventObserverRemovers, this.appEventObserverRemovers ); this.searchOptions = new SearchOptionsState(