<commit_before>import {
  action,
  computed,
  makeObservable,
  observable,
  runInAction,
} from 'mobx';
import { ApplicationEvent, ContentType } from '@standardnotes/snjs';
import { WebApplication } from '@/ui_models/application';
import { SNItem } from '@standardnotes/snjs/dist/@types/models/core/item';
import { AccountMenuPane } from '@/components/AccountMenu';

type StructuredItemsCount = {
  notes: number;
  tags: number;
  deleted: number;
  archived: number;
};

export class AccountMenuState {
  show = false;
  signingOut = false;
  otherSessionsSignOut = false;
  server: string | undefined = undefined;
  enableServerOption = false;
  notesAndTags: SNItem[] = [];
  isEncryptionEnabled = false;
  encryptionStatusString = '';
  isBackupEncrypted = false;
  showSignIn = false;
  showRegister = false;
  shouldAnimateCloseMenu = false;
  currentPane = AccountMenuPane.GeneralMenu;

  constructor(
    private application: WebApplication,
    private appEventListeners: (() => void)[]
  ) {
    makeObservable(this, {
      show: observable,
      signingOut: observable,
      otherSessionsSignOut: observable,
      server: observable,
      enableServerOption: observable,
      notesAndTags: observable,
      isEncryptionEnabled: observable,
      encryptionStatusString: observable,
      isBackupEncrypted: observable,
      showSignIn: observable,
      showRegister: observable,
      currentPane: observable,
      shouldAnimateCloseMenu: observable,

      setShow: action,
      setShouldAnimateClose: action,
      toggleShow: action,
      setSigningOut: action,
      setIsEncryptionEnabled: action,
      setEncryptionStatusString: action,
      setIsBackupEncrypted: action,
      setOtherSessionsSignOut: action,
      setCurrentPane: action,
      setEnableServerOption: action,

      notesAndTagsCount: computed,
    });

    this.addAppLaunchedEventObserver();
    this.streamNotesAndTags();
  }

  addAppLaunchedEventObserver = (): void => {
    this.appEventListeners.push(
      this.application.addEventObserver(async () => {
        runInAction(() => {
          this.setServer(this.application.getHost());
        });
      }, ApplicationEvent.Launched)
    );
  };

  streamNotesAndTags = (): void => {
    this.appEventListeners.push(
      this.application.streamItems([ContentType.Note, ContentType.Tag], () => {
        runInAction(() => {
          this.notesAndTags = this.application.getItems([
            ContentType.Note,
            ContentType.Tag,
          ]);
        });
      })
    );
  };
<commit_msg>fix: Make setServer function an action (#704)<commit_after>import {
  action,
  computed,
  makeObservable,
  observable,
  runInAction,
} from 'mobx';
import { ApplicationEvent, ContentType } from '@standardnotes/snjs';
import { WebApplication } from '@/ui_models/application';
import { SNItem } from '@standardnotes/snjs/dist/@types/models/core/item';
import { AccountMenuPane } from '@/components/AccountMenu';

type StructuredItemsCount = {
  notes: number;
  tags: number;
  deleted: number;
  archived: number;
};

export class AccountMenuState {
  show = false;
  signingOut = false;
  otherSessionsSignOut = false;
  server: string | undefined = undefined;
  enableServerOption = false;
  notesAndTags: SNItem[] = [];
  isEncryptionEnabled = false;
  encryptionStatusString = '';
  isBackupEncrypted = false;
  showSignIn = false;
  showRegister = false;
  shouldAnimateCloseMenu = false;
  currentPane = AccountMenuPane.GeneralMenu;

  constructor(
    private application: WebApplication,
    private appEventListeners: (() => void)[]
  ) {
    makeObservable(this, {
      show: observable,
      signingOut: observable,
      otherSessionsSignOut: observable,
      server: observable,
      enableServerOption: observable,
      notesAndTags: observable,
      isEncryptionEnabled: observable,
      encryptionStatusString: observable,
      isBackupEncrypted: observable,
      showSignIn: observable,
      showRegister: observable,
      currentPane: observable,
      shouldAnimateCloseMenu: observable,

      setShow: action,
      setShouldAnimateClose: action,
      toggleShow: action,
      setSigningOut: action,
      setIsEncryptionEnabled: action,
      setEncryptionStatusString: action,
      setIsBackupEncrypted: action,
      setOtherSessionsSignOut: action,
      setCurrentPane: action,
      setEnableServerOption: action,
      setServer: action,

      notesAndTagsCount: computed,
    });

    this.addAppLaunchedEventObserver();
    this.streamNotesAndTags();
  }

  addAppLaunchedEventObserver = (): void => {
    this.appEventListeners.push(
      this.application.addEventObserver(async () => {
        runInAction(() => {
          this.setServer(this.application.getHost());
        });
      }, ApplicationEvent.Launched)
    );
  };

  streamNotesAndTags = (): void => {
    this.appEventListeners.push(
      this.application.streamItems([ContentType.Note, ContentType.Tag], () => {
        runInAction(() => {
          this.notesAndTags = this.application.getItems([
            ContentType.Note,
            ContentType.Tag,
          ]);
        });
      })
    );
  };

{'fraction_non_alphanumeric': 0.1056487372276846, 'fraction_numerical': 0.000578368999421631, 'mean_word_length': 3.2840627580511974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5935625', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1466, 'n_words': 288}