feat: unify card runtime and event-driven web ui
This commit is contained in:
parent
0edf8c3fef
commit
4dfb7ca3cc
105 changed files with 17382 additions and 8505 deletions
30
frontend/src/theme/useThemePreference.ts
Normal file
30
frontend/src/theme/useThemePreference.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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],
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue