nanobot-voice-interface/frontend/src/theme/useThemePreference.ts
kacper 4dfb7ca3cc
Some checks failed
CI / Backend Checks (push) Failing after 36s
CI / Frontend Checks (push) Failing after 40s
feat: unify card runtime and event-driven web ui
2026-04-06 15:42:53 -04:00

30 lines
688 B
TypeScript

import { useEffect, useMemo, useState } from "preact/hooks";
import {
applyThemeToDocument,
DEFAULT_THEME,
getStoredThemeName,
THEME_OPTIONS,
THEME_STORAGE_KEY,
type ThemeName,
} from "./themes";
export function useThemePreference() {
const [themeName, setThemeName] = useState<ThemeName>(() => {
if (typeof window === "undefined") return DEFAULT_THEME;
return getStoredThemeName();
});
useEffect(() => {
applyThemeToDocument(themeName);
window.localStorage.setItem(THEME_STORAGE_KEY, themeName);
}, [themeName]);
return useMemo(
() => ({
themeName,
themeOptions: THEME_OPTIONS,
setThemeName,
}),
[themeName],
);
}