Skip to content

Commit

Permalink
Load profile theme from preset (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Dec 19, 2024
1 parent 0dadaa9 commit 9ff5a88
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/profile/src/components/context/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,26 @@ export function ThemeProvider({
);
const [theme, setTheme] = useState<ControllerTheme>(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 });

Expand Down

0 comments on commit 9ff5a88

Please sign in to comment.