11'use client'
22
33import { useContext , useRef , useState } from 'react'
4+ import NavigationButton from './NavigationButton'
45import NavigationLogo from './NavigationLogo'
56import { ContextQuote } from '@/context/ContextQuote'
67import { ContextTopTenPosts } from '@/context/ContextTopTenPosts'
78import { ContextTopUsers } from '@/context/ContextTopUsers'
9+ import { setWindowScrollTo } from '@/utils/setWindowScrollTo'
810import { useNavigationOpacity } from '@/hooks/useNavigationOpacity'
9- import NavigationButton from './NavigationButton '
11+ import { useScreenWidth } from '@/hooks/useScreenWidth '
1012
1113const Navigation = ( ) => {
1214 const contextQuote = useContext ( ContextQuote )
@@ -33,45 +35,23 @@ const Navigation = () => {
3335 }
3436 const topUsersRef = contextTopUsers
3537
38+ const SCREEN_WIDTH = useScreenWidth ( )
39+
3640 const [ navOpacity , setNavOpacity ] = useState < string > ( 'opacity-100' )
3741 const timerRef = useRef < ReturnType < typeof setTimeout > | null > ( null )
3842
3943 useNavigationOpacity ( { setNavOpacity, timerRef } )
4044
4145 const handleScrollToQuote = ( ) => {
42- if ( quoteRef . current ) {
43- const OFFSET = 96
44- const top =
45- quoteRef . current . getBoundingClientRect ( ) . top +
46- window . scrollY -
47- OFFSET
48-
49- window . scrollTo ( { top, behavior : 'smooth' } )
50- }
46+ setWindowScrollTo ( 96 , quoteRef )
5147 }
5248
5349 const handleScrollToTopUsers = ( ) => {
54- if ( topUsersRef . current ) {
55- const OFFSET = 64
56- const top =
57- topUsersRef . current . getBoundingClientRect ( ) . top +
58- window . scrollY -
59- OFFSET
60-
61- window . scrollTo ( { top, behavior : 'smooth' } )
62- }
50+ setWindowScrollTo ( 64 , topUsersRef )
6351 }
6452
6553 const handleScrollToTopTenPosts = ( ) => {
66- if ( topTenPostsRef . current ) {
67- const OFFSET = 96
68- const top =
69- topTenPostsRef . current . getBoundingClientRect ( ) . top +
70- window . scrollY -
71- OFFSET
72-
73- window . scrollTo ( { top, behavior : 'smooth' } )
74- }
54+ setWindowScrollTo ( 96 , topTenPostsRef )
7555 }
7656
7757 return (
@@ -80,7 +60,7 @@ const Navigation = () => {
8060 bg-stone-800 text-zinc-100 shadow-md shadow-stone-600/80` }
8161 data-testid = "navigation"
8262 >
83- < div className = "max-w-7xl flex items-center justify-between m-auto h-16 px-2 sm:px-4 py-1 md:py-2" >
63+ < div className = "max-w-7xl flex items-center justify-between m-auto h-16 px-2 py-1 md:py-2" >
8464 < NavigationLogo />
8565 < div >
8666 < NavigationButton
0 commit comments