Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions src/ProductList.jsx
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand Down Expand Up @@ -252,6 +256,18 @@ function ProductList({ onHomeClick }) {
e.preventDefault();
setShowCart(false);
};

const handleAddToCart = (product) => {
dispatch(addItem(product));

setAddedToCart((prevState) => (
{
...prevState,
[product.name]: true,
}
));
};

return (
<div>
<div className="navbar" style={styleObj}>
Expand All @@ -273,10 +289,36 @@ function ProductList({ onHomeClick }) {
</div>
</div>
{!showCart ? (
<div className="product-grid">


</div>
<div>
{plantsArray.map((category, index) => ( // Loop through each category in plantsArray
<div key={index}> {/* Unique key for each category div */}
<h1>
<div>{category.category}</div> {/* Display the category name */}
</h1>
<div className="product-list"> {/* Container for the list of plant cards */}
{category.plants.map((plant, plantIndex) => ( // Loop through each plant in the current category
<div className="product-card" key={plantIndex}> {/* Unique key for each plant card */}
<img
className="product-image"
src={plant.image} // Display the plant image
alt={plant.name} // Alt text for accessibility
/>
<div className="product-title">{plant.name}</div> {/* Display plant name */}
{/* Display other plant details like description and cost */}
<div className="product-description">{plant.description}</div> {/* Display plant description */}
<div className="product-cost">${plant.cost}</div> {/* Display plant cost */}
<button
className="product-button"
onClick={() => handleAddToCart(plant)} // Handle adding plant to cart
>
Add to Cart
</button>
</div>
))}
</div>
</div>
))}
</div>
) : (
<CartItem onContinueShopping={handleContinueShopping} />
)}
Expand Down