Skip to content

Commit

Permalink
add mode to query params
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsnes committed Jun 4, 2024
1 parent 51729f4 commit 10462cb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/theme/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export default function Home() {
const params = new URLSearchParams(searchParams);
const colorModalRef = useRef<HTMLDialogElement>(null);

/* get theme from query on initial load */
useEffect(() => {
const theme = params.get('theme') as ThemeMode;
if (theme) {
setThemeMode(theme);
}
}, []);

useEffect(() => {
mapTokens();

Expand Down Expand Up @@ -189,6 +197,11 @@ export default function Home() {
}
};

const themeQuerySetter = (themeMode: ThemeMode) => {
params.set('theme', themeMode);
replace(`${pathname}?${params.toString()}`, { scroll: false });
};

/**
* Get the color error for a color
*
Expand Down Expand Up @@ -254,6 +267,7 @@ export default function Home() {
themeMode={themeMode}
onThemeModeChange={(themeMode: ThemeMode) => {
setThemeMode(themeMode);
themeQuerySetter(themeMode);
}}
/>
</Container>
Expand Down

0 comments on commit 10462cb

Please sign in to comment.