import useSidebar from '@/core/hooks/useSidebar'; import { getCountCart } from '@/core/utils/cart'; import IndoteknikLogo from '@/images/logo.png'; import { Bars3Icon, HeartIcon, ShoppingCartIcon, } from '@heroicons/react/24/outline'; import dynamic from 'next/dynamic'; import Image from 'next/image'; import { useEffect, useState } from 'react'; import MobileView from '../../views/MobileView'; import Link from '../Link/Link'; import TopBanner from './TopBanner'; import { useCartStore } from '~/modules/cart/stores/useCartStore'; import useAuth from '@/core/hooks/useAuth'; const Search = dynamic(() => import('./Search')); const NavbarMobile = () => { const { Sidebar, open } = useSidebar(); const auth = useAuth(); const [cartCount, setCartCount] = useState(0); const { loadCart, cart, summary, updateCartItem } = useCartStore(); // useEffect(() => { // const handleCartChange = () => { // const cart = async () => { // const listCart = await getCountCart(); // setCartCount(listCart); // }; // cart(); // }; // handleCartChange(); // window.addEventListener('localStorageChange', handleCartChange); // return () => { // window.removeEventListener('localStorageChange', handleCartChange); // }; // }, []); useEffect(() => { if(auth){ loadCart(auth?.id); } }, [auth]); useEffect(() => { setCartCount(cart?.products?.length); }, [cart]); return ( {Sidebar} ); }; export default NavbarMobile;