summaryrefslogtreecommitdiff
path: root/src/core/components/elements/Navbar/NavbarMobile.jsx
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-12-23 11:20:56 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-12-23 11:20:56 +0700
commit21f3d78e6c58d9b509f3ea234af462807ef1301d (patch)
tree9bad9467325819888b73a86804222e313c6c9504 /src/core/components/elements/Navbar/NavbarMobile.jsx
parentd1592286eef165533c21d52aec70dbb703cdcfd3 (diff)
parent9962d114e590bfc5e6c865489ab4dcd84de81ad9 (diff)
Merge branch 'new-release' into feature/integrasi_biteship
Diffstat (limited to 'src/core/components/elements/Navbar/NavbarMobile.jsx')
-rw-r--r--src/core/components/elements/Navbar/NavbarMobile.jsx43
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'>