aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/ui/src/stores/ui-store.ts
blob: 89b9191d1bb094c277a0ffeccabf11acf118dc20 (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
33
34
35
36
37
38
39
40
41
42
import { create } from "zustand";

export type ViewType = "home" | "versions" | "settings" | "guide" | "instances";

interface UIState {
  // State
  currentView: ViewType;
  showConsole: boolean;
  appVersion: string;

  // Actions
  toggleConsole: () => void;
  setView: (view: ViewType) => void;
  setAppVersion: (version: string) => void;
}

export const useUIStore = create<UIState>((set) => ({
  // Initial state
  currentView: "home",
  showConsole: false,
  appVersion: "...",

  // Actions
  toggleConsole: () => {
    set((state) => ({ showConsole: !state.showConsole }));
  },

  setView: (view: ViewType) => {
    set({ currentView: view });
  },

  setAppVersion: (version: string) => {
    set({ appVersion: version });
  },
}));

// Provide lowercase alias for compatibility with existing imports.
// Use a function wrapper to ensure the named export exists as a callable value
// at runtime (some bundlers/tree-shakers may remove simple aliases).
export function useUiStore() {
  return useUIStore();
}