refactor: reviewer's comments
- don't pass `closeAccountMenu` to AccountMenu, instead create it in Account menu state and use it - add event observers as per original code - move some variables into component's state (even if they don't need to have setters sometimes)
This commit is contained in:
@@ -1,29 +1,58 @@
|
||||
import { action, makeObservable, observable } from "mobx";
|
||||
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
|
||||
import { ContentType } from '@node_modules/@standardnotes/snjs';
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
import { SNItem } from '@node_modules/@standardnotes/snjs/dist/@types/models/core/item';
|
||||
|
||||
export class AccountMenuState {
|
||||
show = false;
|
||||
signingOut = false;
|
||||
notesAndTags: SNItem[] = [];
|
||||
|
||||
constructor() {
|
||||
constructor(
|
||||
private application: WebApplication,
|
||||
appEventListeners: (() => void)[]
|
||||
) {
|
||||
makeObservable(this, {
|
||||
show: observable,
|
||||
signingOut: observable,
|
||||
notesAndTags: observable,
|
||||
|
||||
setShow: action,
|
||||
toggleShow: action,
|
||||
setSigningOut: action,
|
||||
|
||||
notesAndTagsCount: computed,
|
||||
});
|
||||
|
||||
appEventListeners.push(
|
||||
this.application.streamItems(
|
||||
[ContentType.Note, ContentType.Tag],
|
||||
() => {
|
||||
runInAction(() => {
|
||||
this.notesAndTags = this.application.getItems([ContentType.Note, ContentType.Tag]);
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
setShow = (show: boolean): void => {
|
||||
this.show = show;
|
||||
}
|
||||
};
|
||||
|
||||
closeAccountMenu = (): void => {
|
||||
this.setShow(false);
|
||||
};
|
||||
|
||||
setSigningOut = (signingOut: boolean): void => {
|
||||
this.signingOut = signingOut;
|
||||
}
|
||||
};
|
||||
|
||||
toggleShow = (): void => {
|
||||
this.show = !this.show;
|
||||
};
|
||||
|
||||
get notesAndTagsCount(): number {
|
||||
return this.notesAndTags.length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,10 @@ export class AppState {
|
||||
application,
|
||||
this.appEventObserverRemovers
|
||||
);
|
||||
this.accountMenu = new AccountMenuState();
|
||||
this.accountMenu = new AccountMenuState(
|
||||
application,
|
||||
this.appEventObserverRemovers
|
||||
);
|
||||
this.searchOptions = new SearchOptionsState(
|
||||
application,
|
||||
this.appEventObserverRemovers
|
||||
|
||||
Reference in New Issue
Block a user