mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-15 02:15:55 -07: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 }) {
|
export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||||
let defaultTheme = useAppContext().defaultTheme;
|
let defaultTheme = useAppContext().defaultTheme;
|
||||||
let initialTheme = localStorage.getItem("theme") ?? 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>(() => {
|
const [currentTheme, setCurrentTheme] = useState<Theme>(() => {
|
||||||
if (initialTheme === "custom") {
|
if (initialTheme === "custom") {
|
||||||
const customTheme = getStoredCustomTheme();
|
const customTheme = getStoredCustomTheme();
|
||||||
|
|
@ -78,6 +80,8 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||||
if (foundTheme) {
|
if (foundTheme) {
|
||||||
localStorage.setItem("theme", newThemeName);
|
localStorage.setItem("theme", newThemeName);
|
||||||
setCurrentTheme(foundTheme);
|
setCurrentTheme(foundTheme);
|
||||||
|
} else {
|
||||||
|
setTheme(defaultTheme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue