fix: theme undefined prevents settings page from loading

This commit is contained in:
Rotimi Best
2024-10-15 01:46:05 +01:00
parent 48a52af1c6
commit 033959cb82
2 changed files with 8 additions and 8 deletions
@@ -142,8 +142,8 @@
goto(`${$currentOrgPath}/settings${pathname}`); goto(`${$currentOrgPath}/settings${pathname}`);
} }
function setHex(theme: string) { function setHex(theme?: string) {
if (hex || theme.includes('theme-')) return; if (!theme || hex || theme.includes('theme-')) return;
hex = theme; hex = theme;
} }
@@ -6,8 +6,8 @@ function updateThemeClassInBody(newClass: string, customRegex?: string) {
document.body.className = document.body.className.replace(customRegex ?? regex, newClass); document.body.className = document.body.className.replace(customRegex ?? regex, newClass);
} }
export function setTheme(theme: string) { export function setTheme(_theme?: string) {
const _theme = theme || ''; const theme = _theme || '';
// this condition checks if it's a hex code from the db or a specified theme // this condition checks if it's a hex code from the db or a specified theme
if (theme && !theme.includes('theme-')) { if (theme && !theme.includes('theme-')) {
@@ -18,17 +18,17 @@ export function setTheme(theme: string) {
setCustomTheme('theme-custom'); setCustomTheme('theme-custom');
} else if (!theme && document.body.className.includes('theme-')) { } else if (!theme && document.body.className.includes('theme-')) {
// if no theme and a theme is already applied, remove it // if no theme and a theme is already applied, remove it
updateThemeClassInBody(_theme); updateThemeClassInBody(theme);
return; return;
} }
// In case theme already exists in dom, don't add // In case theme already exists in dom, don't add
if (document.body.className.includes(_theme)) return; if (document.body.className.includes(theme)) return;
// set the new theme // set the new theme
localStorage.setItem('theme', _theme); localStorage.setItem('theme', theme);
document.body.className = document.body.className.concat(' ', _theme); document.body.className = document.body.className.concat(' ', theme);
} }
export function setCustomTheme(theme?: string) { export function setCustomTheme(theme?: string) {