1- import { OffsetTransition } from "../Motion"
21import { Icon } from "@twilight-toolkit/ui"
3- import { useTheme } from "next-themes"
42import { useRouter } from "next/router"
3+ import { useTheme } from "next-themes"
54import { useEffect , useRef , useState } from "react"
65import smoothScroll from "smoothscroll-polyfill"
76import { useDispatch , useSelector } from "~/hooks"
87import { deactivateKbar } from "~/store/kbar/actions"
98import { selectKbar } from "~/store/kbar/selectors"
9+ import { OffsetTransition } from "../Motion"
1010
1111const themes = [ "system" , "dark" , "light" ]
1212const icons = [
@@ -23,67 +23,72 @@ export default function Footer() {
2323 const { pathname } = useRouter ( )
2424 const [ mounted , setMounted ] = useState ( false )
2525 const backToTopRef = useRef < HTMLButtonElement > ( null )
26+ const previousPathnameRef = useRef ( pathname )
2627
2728 useEffect ( ( ) => {
2829 smoothScroll . polyfill ( )
2930 setMounted ( true )
3031 } , [ ] )
3132
3233 useEffect ( ( ) => {
33- // Cursor glowing effect
34- if ( mounted && resolvedTheme === "dark" ) {
35- const glowingArea = document . querySelector ( ".glowing-area" )
36- const glowingDivs = document . querySelectorAll ( ".glowing-div" )
34+ if ( ! mounted || resolvedTheme !== "dark" ) return
35+
36+ const glowingArea = document . querySelector < HTMLElement > ( ".glowing-area" )
37+ const glowingDivs = document . querySelectorAll < HTMLElement > ( ".glowing-div" )
3738
38- if ( glowingArea ) {
39- const handler = ( ev : any ) => {
40- glowingDivs . forEach ( ( featureEl : any ) => {
41- const rect = featureEl . getBoundingClientRect ( )
42- featureEl . style . setProperty ( "--x" , ev . clientX - rect . left )
43- featureEl . style . setProperty ( "--y" , ev . clientY - rect . top )
44- } )
45- }
46- glowingArea . addEventListener ( "pointermove" , handler )
39+ if ( ! glowingArea ) return
4740
48- return ( ) => {
49- glowingArea . removeEventListener ( "pointermove" , handler )
50- }
51- }
41+ const handler = ( ev : PointerEvent ) => {
42+ glowingDivs . forEach ( ( featureEl ) => {
43+ const rect = featureEl . getBoundingClientRect ( )
44+ featureEl . style . setProperty ( "--x" , `${ ev . clientX - rect . left } ` )
45+ featureEl . style . setProperty ( "--y" , `${ ev . clientY - rect . top } ` )
46+ } )
5247 }
53- // Hide kbar on route change
54- visible && dispatch ( deactivateKbar ( ) )
55- } , [ resolvedTheme , mounted , pathname ] )
48+ glowingArea . addEventListener ( "pointermove" , handler )
49+
50+ return ( ) => {
51+ glowingArea . removeEventListener ( "pointermove" , handler )
52+ }
53+ } , [ mounted , pathname , resolvedTheme ] )
54+
55+ useEffect ( ( ) => {
56+ if ( previousPathnameRef . current === pathname ) return
57+
58+ previousPathnameRef . current = pathname
59+ if ( visible ) dispatch ( deactivateKbar ( ) )
60+ } , [ dispatch , pathname , visible ] )
5661
5762 if ( ! mounted ) return null
5863
5964 return (
60- < footer className = "mt-20 border-b border-t border-gray-200 bg-white py-4 text-center dark:border-gray-700 dark:bg-gray-800" >
65+ < footer className = "mt-20 border-gray-200 border-t border-b bg-white py-4 text-center dark:border-gray-700 dark:bg-gray-800" >
6166 < div className = "fixed bottom-8 left-8 text-gray-500 dark:text-gray-300" >
6267 < button
6368 aria-label = "change theme"
6469 onClick = { ( ) => {
6570 setTheme ( targetThemes [ themes . indexOf ( theme ) ] )
6671 } }
67- className = "effect-pressing p-3! shadow-xs focus:outline-hidden flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white text-xl tracking-wider hover:shadow-inner dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700" >
72+ className = "effect-pressing flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white p-3! text-xl tracking-wider shadow-xs hover:shadow-inner focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700" >
6873 < span className = "h-7 w-7" > { icons [ themes . indexOf ( theme ) ] } </ span >
6974 </ button >
7075 </ div >
71- < div className = "fixed bottom -8 right -8 text-gray-500 dark:text-gray-300" >
76+ < div className = "fixed right -8 bottom -8 text-gray-500 dark:text-gray-300" >
7277 < OffsetTransition componentRef = { backToTopRef } >
7378 < button
7479 ref = { backToTopRef }
7580 aria-label = "change theme"
7681 onClick = { ( ) => {
7782 window . scrollTo ( { top : 0 , behavior : "smooth" } )
7883 } }
79- className = "effect-pressing shadow-xs focus:outline-hidden flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white p-3 text-xl tracking-wider opacity-0 hover:shadow-inner dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700" >
84+ className = "effect-pressing flex w-full cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white p-3 text-xl tracking-wider opacity-0 shadow-xs hover:shadow-inner focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700" >
8085 < span className = "h-7 w-7" >
8186 < Icon name = "arrowUp" />
8287 </ span >
8388 </ button >
8489 </ OffsetTransition >
8590 </ div >
86- < p className = "text-4 tracking-wide text-gray-500 dark:text-gray-400" >
91+ < p className = "text-4 text-gray-500 tracking-wide dark:text-gray-400" >
8792 < a
8893 href = "https://creativecommons.org/licenses/by-nc-sa/4.0/"
8994 target = "_blank"
0 commit comments