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 ? (