diff --git a/src/ProductList.jsx b/src/ProductList.jsx index 7682c04fc4..c11dfe589c 100644 --- a/src/ProductList.jsx +++ b/src/ProductList.jsx @@ -1,9 +1,13 @@ import React, { useState, useEffect } from 'react'; import './ProductList.css' import CartItem from './CartItem'; +import { addItem } from './CartSlice'; + + function ProductList({ onHomeClick }) { const [showCart, setShowCart] = useState(false); - const [showPlants, setShowPlants] = useState(false); // State to control the visibility of the About Us page + const [showPlants, setShowPlants] = useState(false); + const [addedToCart, setAddedToCart] = useState({}); const plantsArray = [ { @@ -252,6 +256,18 @@ function ProductList({ onHomeClick }) { e.preventDefault(); setShowCart(false); }; + + const handleAddToCart = (product) => { + dispatch(addItem(product)); + + setAddedToCart((prevState) => ( + { + ...prevState, + [product.name]: true, + } + )); + }; + return (
@@ -273,10 +289,36 @@ function ProductList({ onHomeClick }) {
{!showCart ? ( -
- - -
+
+ {plantsArray.map((category, index) => ( // Loop through each category in plantsArray +
{/* Unique key for each category div */} +

+
{category.category}
{/* Display the category name */} +

+
{/* Container for the list of plant cards */} + {category.plants.map((plant, plantIndex) => ( // Loop through each plant in the current category +
{/* Unique key for each plant card */} + {plant.name} +
{plant.name}
{/* Display plant name */} + {/* Display other plant details like description and cost */} +
{plant.description}
{/* Display plant description */} +
${plant.cost}
{/* Display plant cost */} + +
+ ))} +
+
+ ))} +
) : ( )}