diff --git a/src/components/Header.tsx b/src/components/Header.tsx index a0e81212..9af155dc 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,10 +1,12 @@ 'use client'; import FancyRectangle from '@/components/FancyRectangle'; +import { BREAKPOINTS } from '@/constants/breakpoints'; +import { useMount } from '@/hooks/use-mount'; import { useUser } from '@clerk/nextjs'; import Image from 'next/image'; import Link from 'next/link'; -import { useEffect, useRef, useState } from 'react'; +import { useRef, useState } from 'react'; import { IoMdClose, IoMdMenu } from 'react-icons/io'; import Button from './Button'; import UserButton from './UserButton'; @@ -19,13 +21,25 @@ export default function Header() { setIsMenuOpen(!isMenuOpen); }; - useEffect(() => { + useMount(() => { window.addEventListener('scroll', handleScroll); + window.addEventListener('resize', handleResize); return () => { window.removeEventListener('scroll', handleScroll); + window.removeEventListener('resize', handleResize); }; - }, []); + }); + + const closeMenu = () => { + setIsMenuOpen(false); + }; + + const handleResize = () => { + if (window.innerWidth >= BREAKPOINTS.md) { + setIsMenuOpen(false); + } + }; const handleScroll = () => { const scrollPosition = window.scrollY; @@ -108,16 +122,16 @@ export default function Header() { isMenuOpen ? 'mt-12 space-y-8' : 'hidden' } mb-4 text-4xl md:mb-0 md:flex md:flex-row md:space-x-4 md:space-y-0 md:text-base lg:space-x-8`} > - + About - + Events - + Sponsors - + Contact
{isSignedIn ? ( <> - ) : ( <> - - diff --git a/src/constants/breakpoints.ts b/src/constants/breakpoints.ts new file mode 100644 index 00000000..c56b666e --- /dev/null +++ b/src/constants/breakpoints.ts @@ -0,0 +1,6 @@ +export const BREAKPOINTS = { + sm: 640, + md: 768, + lg: 1024, + xl: 1280, +} as const;