diff --git a/src/CartSlice.jsx b/src/CartSlice.jsx index 32b8761ed0..b62c103803 100644 --- a/src/CartSlice.jsx +++ b/src/CartSlice.jsx @@ -7,7 +7,7 @@ export const CartSlice = createSlice({ }, reducers: { addItem: (state, action) => { - + state.items.push(action.payload); }, removeItem: (state, action) => { }, diff --git a/src/ProductList.jsx b/src/ProductList.jsx index 7682c04fc4..fe1200d998 100644 --- a/src/ProductList.jsx +++ b/src/ProductList.jsx @@ -1,10 +1,24 @@ import React, { useState, useEffect } from 'react'; import './ProductList.css' import CartItem from './CartItem'; +import { addItem } from './CartSlice'; + function ProductList({ onHomeClick }) { + const dispatch = useDispatch(); const [showCart, setShowCart] = useState(false); const [showPlants, setShowPlants] = useState(false); // State to control the visibility of the About Us page + const [addedToCart, setAddedToCart] = useState({}); + + const handleAddToCart = (product) => { + dispatch(addItem(product)); + + setAddedToCart((prevState) => ({ + ...prevState, + [product.name]: true, + })); + }; + const plantsArray = [ { category: "Air Purifying Plants", @@ -274,9 +288,32 @@ function ProductList({ onHomeClick }) { {!showCart ? (
- - -
+ {plantsArray.map((category, index) => ( +
+

+
{category.category}
+

+
+ {category.plants.map((plant, plantIndex) => ( +
+ {plant.name} +
{plant.name}
+
{plant.description}
+
${plant.cost}
+ +
+ ))} +
+
+))} + ) : ( )} diff --git a/src/main.jsx b/src/main.jsx index 9ea042ec2b..b7217c9240 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -10,4 +10,4 @@ ReactDOM.createRoot(document.getElementById('root')).render( , -) +);