@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 55 lines 1.47 KB
Raw
1 import { create } from "zustand";
2
3 import {
4 getThemeDefinition,
5 type ThemeAppearance,
6 type ThemeHalves,
7 type ThemePreference,
8 } from "../../themePalette";
9
10 export type ThemeEditorSessionInput = {
11 editingThemeId: string | null;
12 seedThemeId: string | null;
13 seedName: string | null;
14 initialAppearance: ThemeAppearance;
15 };
16
17 export type ThemeEditorSession = ThemeEditorSessionInput & {
18 id: number;
19 };
20
21 type ThemeEditorStore = {
22 session: ThemeEditorSession | null;
23 openThemeEditor: (session: ThemeEditorSessionInput) => void;
24 closeThemeEditor: () => void;
25 };
26
27 let nextSessionId = 0;
28
29 export const useThemeEditorStore = create<ThemeEditorStore>((set) => ({
30 session: null,
31 openThemeEditor: (session) => set({ session: { ...session, id: ++nextSessionId } }),
32 closeThemeEditor: () => set({ session: null }),
33 }));
34
35 export function toggleThemeEditorForTheme(input: {
36 theme: ThemePreference;
37 themeHalves: ThemeHalves | null;
38 initialAppearance: ThemeAppearance;
39 }): void {
40 const store = useThemeEditorStore.getState();
41 if (store.session) {
42 store.closeThemeEditor();
43 return;
44 }
45
46 const baseThemeId = getThemeDefinition(input.theme)?.id ?? null;
47 const activeThemeId = input.themeHalves?.[input.initialAppearance] ?? baseThemeId;
48 const seedThemeId = activeThemeId ? (getThemeDefinition(activeThemeId)?.id ?? null) : null;
49 store.openThemeEditor({
50 editingThemeId: null,
51 seedThemeId,
52 seedName: null,
53 initialAppearance: input.initialAppearance,
54 });
55 }