From 033959cb826d3b31d46f629e20afb1b9c9cbbf0e Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Tue, 15 Oct 2024 01:46:05 +0100 Subject: [PATCH] fix: theme undefined prevents settings page from loading --- .../lib/components/Org/Settings/OrgSettings.svelte | 4 ++-- apps/dashboard/src/lib/utils/functions/theme.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/dashboard/src/lib/components/Org/Settings/OrgSettings.svelte b/apps/dashboard/src/lib/components/Org/Settings/OrgSettings.svelte index f0985ae0..748d2e23 100644 --- a/apps/dashboard/src/lib/components/Org/Settings/OrgSettings.svelte +++ b/apps/dashboard/src/lib/components/Org/Settings/OrgSettings.svelte @@ -142,8 +142,8 @@ goto(`${$currentOrgPath}/settings${pathname}`); } - function setHex(theme: string) { - if (hex || theme.includes('theme-')) return; + function setHex(theme?: string) { + if (!theme || hex || theme.includes('theme-')) return; hex = theme; } diff --git a/apps/dashboard/src/lib/utils/functions/theme.ts b/apps/dashboard/src/lib/utils/functions/theme.ts index fa87e56f..ad1fd335 100644 --- a/apps/dashboard/src/lib/utils/functions/theme.ts +++ b/apps/dashboard/src/lib/utils/functions/theme.ts @@ -6,8 +6,8 @@ function updateThemeClassInBody(newClass: string, customRegex?: string) { document.body.className = document.body.className.replace(customRegex ?? regex, newClass); } -export function setTheme(theme: string) { - const _theme = theme || ''; +export function setTheme(_theme?: string) { + const theme = _theme || ''; // this condition checks if it's a hex code from the db or a specified theme if (theme && !theme.includes('theme-')) { @@ -18,17 +18,17 @@ export function setTheme(theme: string) { setCustomTheme('theme-custom'); } else if (!theme && document.body.className.includes('theme-')) { // if no theme and a theme is already applied, remove it - updateThemeClassInBody(_theme); + updateThemeClassInBody(theme); return; } // 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 - localStorage.setItem('theme', _theme); - document.body.className = document.body.className.concat(' ', _theme); + localStorage.setItem('theme', theme); + document.body.className = document.body.className.concat(' ', theme); } export function setCustomTheme(theme?: string) {