Skip to content

Commit

Permalink
client: fix close menu bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Lal committed Dec 16, 2023
1 parent 86fb3c0 commit c98f8c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions client/src/components/MobileMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Link } from 'react-router-dom'
import { useAnimStore } from '../store/useAnimStore'
import { useEffect, useRef, useState } from 'react'

export default function MobileMenu ({ menuLinks }) {
export default function MobileMenu({ menuLinks }) {
const { mobileMenu, setMobileMenu, closeMenu } = useAnimStore()
const [animClass, setAnimClass] = useState('')
const [width, setWidth] = useState(null)
const menuRef = useRef(null)
const linkRef = useRef(null)

function handleButtonClick () {
function handleCloseButton() {
setAnimClass('normal')
closeMenu()
setMobileMenu(false)
Expand All @@ -18,7 +18,7 @@ export default function MobileMenu ({ menuLinks }) {
const updateDimensions = () => {
setWidth(window.innerWidth)
if (width > 650) {
handleButtonClick()
handleCloseButton()
}
}
window.addEventListener('resize', updateDimensions)
Expand All @@ -37,7 +37,6 @@ export default function MobileMenu ({ menuLinks }) {
<div ref={linkRef} className={`mobile-menu-links ${animClass}`}>
{menuLinks.map(item => (
<Link
onClick={() => handleButtonClick()}
to={item.link}
className='mobile-menu-link'
key={item.id}
Expand All @@ -47,7 +46,7 @@ export default function MobileMenu ({ menuLinks }) {
))}
<button
onClick={() => {
handleButtonClick()
handleCloseButton()
}}
className='mobile-menu-close-btn'
>
Expand Down
2 changes: 2 additions & 0 deletions client/src/store/useAnimStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { create } from 'zustand'

export const useAnimStore = create(set => ({
toggleDisable: false,

mobileMenu: false,
setMobileMenu: verifyState => {
set({ mobileMenu: verifyState })
Expand All @@ -10,6 +11,7 @@ export const useAnimStore = create(set => ({
set({ toggleDisable: false })
}, 1000)
},

menuPopup: false,
openMenu: () => {
set({ menuPopup: true })
Expand Down

0 comments on commit c98f8c4

Please sign in to comment.