Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
fix theme
Browse files Browse the repository at this point in the history
  • Loading branch information
EugenWay committed Sep 19, 2023
1 parent 493ec9e commit 19a4948
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Themes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ThemedRouter = () => {

return (
<ThemeProvider theme={{ mode }}>
<Entry mode='light' theme={`${network.name}-relay`}>
<Entry mode={mode} theme={`${network.name}-relay`}>
<Router />
</Entry>
</ThemeProvider>
Expand Down
13 changes: 2 additions & 11 deletions src/contexts/Themes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ThemesProvider = ({ children }: { children: React.ReactNode }) => {
if (!['light', 'dark'].includes(localThemeRaw)) {
const systemTheme =
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
window.matchMedia('(prefers-color-scheme: light)').matches
? 'dark'
: 'light';

Expand All @@ -31,15 +31,6 @@ export const ThemesProvider = ({ children }: { children: React.ReactNode }) => {
const [theme, setTheme] = React.useState<Theme>(initialTheme);
const themeRef = useRef(theme);

// Automatically change theme on system change.
window
.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', (event) => {
const newTheme = event.matches ? 'dark' : 'light';
localStorage.setItem('theme', newTheme);
setStateWithRef(newTheme, setTheme, themeRef);
});

const toggleTheme = (maybeTheme: Theme | null = null): void => {
const newTheme =
maybeTheme || (themeRef.current === 'dark' ? 'light' : 'dark');
Expand All @@ -52,7 +43,7 @@ export const ThemesProvider = ({ children }: { children: React.ReactNode }) => {
<ThemeContext.Provider
value={{
toggleTheme,
mode: initialTheme,
mode: themeRef.current,
}}
>
{children}
Expand Down

0 comments on commit 19a4948

Please sign in to comment.