From 9ff5a885c9aacc83e09166c483436b7faffd7970 Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Thu, 19 Dec 2024 12:28:09 -0500 Subject: [PATCH] Load profile theme from preset (#1194) --- .../profile/src/components/context/theme.tsx | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/profile/src/components/context/theme.tsx b/packages/profile/src/components/context/theme.tsx index a8a750ef8..f2d7c76e9 100644 --- a/packages/profile/src/components/context/theme.tsx +++ b/packages/profile/src/components/context/theme.tsx @@ -65,23 +65,26 @@ export function ThemeProvider({ ); const [theme, setTheme] = useState(initialState.theme); const themeParam = searchParams.get("theme"); + const presetParam = searchParams.get("preset"); const { origin } = useConnection(); useEffect(() => { - if (!themeParam) return; - const val = decodeURIComponent(themeParam); - - if ( - typeof val === "string" && - val in controllerConfigs && - controllerConfigs[val].theme - ) { - setTheme(controllerConfigs[val].theme); - return; + // Handle theme from URL param + if (themeParam) { + const decodedPreset = decodeURIComponent(themeParam); + try { + const parsedTheme = JSON.parse(decodedPreset) as ControllerTheme; + setTheme(parsedTheme); + } catch { + setTheme(controllerConfigs[decodedPreset].theme || defaultTheme); + } } - setTheme(JSON.parse(val)); - }, [themeParam, origin]); + // Handle theme from preset param + if (presetParam && presetParam in controllerConfigs) { + setTheme(controllerConfigs[presetParam].theme || defaultTheme); + } + }, [themeParam, presetParam, origin]); useThemeEffect({ theme, assetUrl: import.meta.env.VITE_KEYCHAIN_URL });