mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 13:38:15 -08:00
fix: revert to default theme if saved theme is invalid
This commit is contained in:
parent
682e543aa5
commit
e69ef0cb01
1 changed files with 5 additions and 1 deletions
|
|
@ -53,7 +53,9 @@ function getStoredCustomTheme(): Theme | undefined {
|
|||
export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||
let defaultTheme = useAppContext().defaultTheme;
|
||||
let initialTheme = localStorage.getItem("theme") ?? defaultTheme;
|
||||
const [themeName, setThemeName] = useState(initialTheme);
|
||||
const [themeName, setThemeName] = useState(
|
||||
themes[initialTheme] ? initialTheme : defaultTheme
|
||||
);
|
||||
const [currentTheme, setCurrentTheme] = useState<Theme>(() => {
|
||||
if (initialTheme === "custom") {
|
||||
const customTheme = getStoredCustomTheme();
|
||||
|
|
@ -78,6 +80,8 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
|||
if (foundTheme) {
|
||||
localStorage.setItem("theme", newThemeName);
|
||||
setCurrentTheme(foundTheme);
|
||||
} else {
|
||||
setTheme(defaultTheme);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue