-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: system theme resolves as dark or light
- Loading branch information
1 parent
4117d41
commit 600a7b6
Showing
2 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useTheme } from 'next-themes'; | ||
import { ReactNode, useEffect } from 'react'; | ||
|
||
import { trpc } from '../utils/trpcClient'; | ||
|
||
export const ThemeSetter = ({ children }: { children: ReactNode }) => { | ||
const updateSettingsMutation = trpc.user.updateSettings.useMutation(); | ||
const { resolvedTheme, theme } = useTheme(); | ||
|
||
useEffect(() => { | ||
if (theme !== 'system' || resolvedTheme === 'system') return; | ||
updateSettingsMutation.mutateAsync({ theme: resolvedTheme }); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [resolvedTheme]); | ||
|
||
return children; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters