aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/stores/ui.svelte.ts
blob: e88f6b4d87b020732914b021d4f453807aa34bf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { type ViewType } from "../types";

export class UIState {
  currentView: ViewType = $state("home");
  status = $state("Ready");
  showConsole = $state(false);
  appVersion = $state("...");

  private statusTimeout: ReturnType<typeof setTimeout> | null = null;

  setStatus(msg: string) {
    if (this.statusTimeout) clearTimeout(this.statusTimeout);

    this.status = msg;

    if (msg !== "Ready") {
      this.statusTimeout = setTimeout(() => {
        this.status = "Ready";
      }, 5000);
    }
  }

  toggleConsole() {
    this.showConsole = !this.showConsole;
  }

  setView(view: ViewType) {
    this.currentView = view;
  }
}

export const uiState = new UIState();