diff --git a/app/Cart/page.jsx b/app/Cart/page.jsx index 3dca2b3..b97dff4 100644 --- a/app/Cart/page.jsx +++ b/app/Cart/page.jsx @@ -8,12 +8,13 @@ import { useCartProducts } from '../Domain/cartContext' import Image from 'next/image'; import emptyCart from '../images/empty-cart.png' import Link from 'next/link'; +import Loading from '../components/loading'; export default function CartPage() { const { isDarkMode } = useTheme(); const [subTotal, setSubTotal] = useState(0) const [showModal, setShowModal] = useState(false) - const { cartProducts } = useCartProducts(); + const { cartProducts, cartLoading } = useCartProducts(); useEffect(() => { let newSubtotal = 0 @@ -30,35 +31,37 @@ export default function CartPage() {

Shopping Cart

- {cartProducts.length === 0 ? -
-
- Empty Cart Image -
-

Your Cart is currently empty

-

Looks Like you haven't add anything to your cart yet

- Continue Shopping -
- : <> -
- {cartProducts && cartProducts.map((product) => { - return ( - - ) - })} -
-
-
-

SubTotal

-

${subTotal}

+ {cartLoading ? : (<> + {cartProducts.length === 0 ? +
+
+ Empty Cart Image
- +

Your Cart is currently empty

+

Looks Like you haven't add anything to your cart yet

+ Continue Shopping
- } + : <> +
+ {cartProducts && cartProducts.map((product) => { + return ( + + ) + })} +
+
+
+

SubTotal

+

${subTotal}

+
+ +
+ } + )}
diff --git a/app/Domain/cartContext.jsx b/app/Domain/cartContext.jsx index f047add..6874ede 100644 --- a/app/Domain/cartContext.jsx +++ b/app/Domain/cartContext.jsx @@ -4,6 +4,7 @@ const CartContext = createContext(); export function CartContextProvider({ children }) { const [cartProducts, setCartProducts] = useState([]); + const [cartLoading , setCarLoading] = useState(true) const saveStateToLocalStorage = (state) => { const serializedState = JSON.stringify(state); @@ -22,6 +23,7 @@ export function CartContextProvider({ children }) { useEffect(() => { const loadedCartState = loadStateFromLocalStorage(); setCartProducts(loadedCartState); + setCarLoading(false) }, []); useEffect(() => { @@ -82,7 +84,7 @@ export function CartContextProvider({ children }) { } return ( - + {children} ); diff --git a/app/components/ProductDescription.jsx b/app/components/ProductDescription.jsx index 80a7a65..6964cbe 100644 --- a/app/components/ProductDescription.jsx +++ b/app/components/ProductDescription.jsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { useCartProducts } from "../Domain/cartContext"; import { useRouter } from "next/navigation"; -export default function ProductDescription({product ,title, description, quantity, price }) { +export default function ProductDescription({product ,title, description, quantity, price,setShowNotification }) { const { addToCart } = useCartProducts(); const [selectedQuantity, setSelectedQuantity] = useState(0); const router = useRouter(); @@ -23,6 +23,7 @@ export default function ProductDescription({product ,title, description, quantit function handleAddToCart() { addToCart(product,selectedQuantity) + setShowNotification(true) } @@ -32,8 +33,8 @@ export default function ProductDescription({product ,title, description, quantit } return ( -
-
+
+

{title}

@@ -41,7 +42,7 @@ export default function ProductDescription({product ,title, description, quantit

${price}

-

{description}

+

{description}