-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy paththeme-store.ts
More file actions
38 lines (30 loc) · 1.17 KB
/
theme-store.ts
File metadata and controls
38 lines (30 loc) · 1.17 KB
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
import { create } from 'zustand'
import { chatThemes, cloneChatTheme, detectSystemTheme, initializeThemeWatcher } from '../utils/theme-system'
import type { ChatTheme, ThemeName } from '../types/theme-system'
export type ThemeStoreState = {
/** Current theme name (dark or light) */
themeName: ThemeName
/** Palette for the active theme */
theme: ChatTheme
}
type ThemeStoreActions = {
/** Update theme to a specific mode (dark or light) */
setThemeName: (name: ThemeName) => void
}
type ThemeStore = ThemeStoreState & ThemeStoreActions
// Build initial theme
const initialThemeName = detectSystemTheme()
const initialTheme = cloneChatTheme(chatThemes[initialThemeName])
export const useThemeStore = create<ThemeStore>((set) => ({
themeName: initialThemeName,
theme: initialTheme,
setThemeName: (name: ThemeName) => {
const theme = cloneChatTheme(chatThemes[name])
set({ themeName: name, theme })
},
}))
// Initialize theme watcher to enable reactive updates from system theme changes
initializeThemeWatcher((name: ThemeName) => {
// Always call setThemeName - it will handle building and updating the theme
useThemeStore.getState().setThemeName(name)
})