mirror of
http://88.130.71.182:3000/BlitTech/contexta_fe.git
synced 2026-06-13 11:55:28 +00:00
Updates Apr3: new pages, components, and widespread UI/API improvements
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
32
src/store/themeStore.ts
Normal file
32
src/store/themeStore.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
|
||||
interface ThemeState {
|
||||
isDark: boolean
|
||||
toggle: () => void
|
||||
}
|
||||
|
||||
export const useThemeStore = create<ThemeState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
isDark: false,
|
||||
toggle: () => set((s) => {
|
||||
const next = !s.isDark
|
||||
document.documentElement.classList.toggle('dark', next)
|
||||
return { isDark: next }
|
||||
}),
|
||||
}),
|
||||
{ name: 'theme' }
|
||||
)
|
||||
)
|
||||
|
||||
/** Call once at app startup to apply persisted theme class */
|
||||
export function initTheme() {
|
||||
const raw = localStorage.getItem('theme')
|
||||
if (raw) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as { state?: { isDark?: boolean } }
|
||||
document.documentElement.classList.toggle('dark', !!parsed.state?.isDark)
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user