Skip to content

Commit

Permalink
Merge pull request umami-software#1446 from AkashRajpurohit/master
Browse files Browse the repository at this point in the history
feat: ✨ customize theme and locale based on query params
  • Loading branch information
mikecao authored Aug 25, 2022
2 parents 9fea2fc + ec7bc92 commit 7ef4718
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hooks/useLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,14 @@ export default function useLocale() {
}
}, [locale]);

useEffect(() => {
const url = new URL(window.location.href);
const locale = url.searchParams.get('locale');

if (locale) {
saveLocale(locale);
}
}, []);

return { locale, saveLocale, messages, dir, dateLocale };
}
9 changes: 9 additions & 0 deletions hooks/useTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ export default function useTheme() {
document.body.setAttribute('data-theme', theme);
}, [theme]);

useEffect(() => {
const url = new URL(window.location.href);
const theme = url.searchParams.get('theme');

if (['light', 'dark'].includes(theme)) {
saveTheme(theme);
}
}, []);

return [theme, saveTheme];
}

0 comments on commit 7ef4718

Please sign in to comment.