From 3a8ff23a451d16ca96668b15dc541fefd10af628 Mon Sep 17 00:00:00 2001 From: dharshib Date: Tue, 4 Jun 2024 08:22:39 +0530 Subject: [PATCH] added wishlist empty message wrapper --- src/Components/SavedItems.jsx | 163 ++++++++++++++-------------------- 1 file changed, 68 insertions(+), 95 deletions(-) diff --git a/src/Components/SavedItems.jsx b/src/Components/SavedItems.jsx index 15eb4cc..c3590f3 100644 --- a/src/Components/SavedItems.jsx +++ b/src/Components/SavedItems.jsx @@ -1,109 +1,82 @@ import React from "react" -import {useContext} from "react" -import {SavedContext} from "../Context/SavedContext" +import { useContext } from "react" +import { SavedContext } from "../Context/SavedContext" import { ShopContext } from "../Context/ShopContext"; +import { Link } from "react-router-dom"; -const SavedItems=()=>{ - const {all_products,listItem,AddToList,RemoveFromList,getListQuantity}=useContext(SavedContext) - const {AddToCart}=useContext(ShopContext) +const SavedItems = () => { + const { all_products, listItem, AddToList, RemoveFromList, getListQuantity } = useContext(SavedContext) + const { AddToCart } = useContext(ShopContext) - return( - <> - -

Total products Wishlisted:

{getListQuantity()}

- -
- { - all_products.map((item) => { - if (listItem[item.id] > 0) { - return( -
- {item.name} -
-

- {(item.name.length > 40) ? ( - // Truncate the name to the maximum length - item.name.substring(0, 40) + "..." - ): (item.name) - } -

-

Category: {item.category}

-
-

${item.new_price}

-

${item.old_price}

- -
-
- -
-
- -
-
- - -
- ) - } - }) - } - - - -
- - - ) -} - -export default SavedItems; + const wishlistItems = all_products.filter(item => listItem[item.id] > 0) + console.log(wishlistItems) -/*function CardComponent(item){ - return( - -
- {item.name} -

{item.name}

-

#Category:{item.category}

-
-

${item.new_price}

-

${item.old_price}

- -
- - -
- ) -}*/ + return ( + <> + { + wishlistItems.length === 0 ? ( +
+

Your wishlist is empty!

+

Seems like you do not have any wishes here.
Make a wish!

+ +
+ ) : <> +
+

Total products Wishlisted:

{getListQuantity()}

+
+
+ { + wishlistItems.map((item) => { + return ( +
+ {item.name} +
+

+ {(item.name.length > 40) ? ( + // Truncate the name to the maximum length + item.name.substring(0, 40) + "..." + ) : (item.name) + } +

+

Category: {item.category}

+
+

${item.new_price}

+

${item.old_price}

+ +
+
+ +
+
+ +
+
+ + +
+ ) + }) + } + + + +
+ + } -/*
- { - all_products.map((item) => { - if (listItem[item.id] > 0) { - return( - - ) - } - }) - } - - -
*/ + + ) +} -/*
- - -
*/ +export default SavedItems;