diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-12-09 15:01:43 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-12-09 15:01:43 +0700 |
| commit | cecccfaf318e0e7c52132cf1d04c90c0df745d14 (patch) | |
| tree | 6828e39e974478995244558ff81d11eac357c026 /src/core/components/elements/Navbar/NavbarMobile.jsx | |
| parent | f2451beed670dc697aa2026b2df6ad1ad1e90da2 (diff) | |
| parent | bb118223e541504262da4509e9188610539702fe (diff) | |
Merge branch 'new-release' into Feature/pengajuan-tempo
Diffstat (limited to 'src/core/components/elements/Navbar/NavbarMobile.jsx')
| -rw-r--r-- | src/core/components/elements/Navbar/NavbarMobile.jsx | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/core/components/elements/Navbar/NavbarMobile.jsx b/src/core/components/elements/Navbar/NavbarMobile.jsx index 90314671..47182a47 100644 --- a/src/core/components/elements/Navbar/NavbarMobile.jsx +++ b/src/core/components/elements/Navbar/NavbarMobile.jsx @@ -12,30 +12,44 @@ 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(); + // useEffect(() => { + // const handleCartChange = () => { + // const cart = async () => { + // const listCart = await getCountCart(); + // setCartCount(listCart); + // }; + // cart(); + // }; + // handleCartChange(); + + // window.addEventListener('localStorageChange', handleCartChange); - window.addEventListener('localStorageChange', handleCartChange); + // return () => { + // window.removeEventListener('localStorageChange', handleCartChange); + // }; + // }, []); - return () => { - window.removeEventListener('localStorageChange', handleCartChange); - }; - }, []); + useEffect(() => { + if(auth){ + loadCart(auth?.id); + } + }, [auth]); + + useEffect(() => { + setCartCount(cart?.products?.length); + }, [cart]); return ( <MobileView> @@ -48,6 +62,7 @@ const NavbarMobile = () => { alt='Indoteknik Logo' width={120} height={40} + loading='eager' /> </Link> <div className='flex gap-x-3'> |
