@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
44import Link from 'next/link' ;
55import { Menu , X , Activity , Moon , Sun } from 'lucide-react' ;
66import { useGlowEffect } from '@/hooks/useGlowEffect' ;
7+ import { useThemeToggle } from './theme-switch' ;
78
89function GithubMark ( ) {
910 return (
@@ -28,31 +29,13 @@ const NAV_LINKS = [
2829
2930export default function Navbar ( ) {
3031 const [ open , setOpen ] = useState ( false ) ;
31- const [ mounted , setMounted ] = useState ( false ) ;
32-
33- const [ isDark , setIsDark ] = useState ( ( ) => {
34- if ( typeof window === 'undefined' || ! window . localStorage ) return true ;
35- return window . localStorage . getItem ( 'theme' ) !== 'light' ;
36- } ) ;
3732
3833 const { shellRef, shellVars, handleMouseEnter, handleMouseMove, handleMouseLeave } =
3934 useGlowEffect ( ) ;
40-
41- useEffect ( ( ) => {
42- // eslint-disable-next-line react-hooks/set-state-in-effect
43- setMounted ( true ) ;
44- } , [ ] ) ;
45-
46- useEffect ( ( ) => {
47- document . documentElement . classList . toggle ( 'dark' , isDark ) ;
48- if ( typeof window !== 'undefined' && window . localStorage ) {
49- window . localStorage . setItem ( 'theme' , isDark ? 'dark' : 'light' ) ;
50- }
51- } , [ isDark ] ) ;
52-
53- const toggleTheme = ( ) => {
54- setIsDark ( ( prev ) => ! prev ) ;
55- } ;
35+ const { isDark, mounted, toggleTheme } = useThemeToggle ( {
36+ variant : 'circle' ,
37+ start : 'top-right' ,
38+ } ) ;
5639
5740 useEffect ( ( ) => {
5841 const mediaQuery = window . matchMedia ( '(min-width: 768px)' ) ;
0 commit comments