From 423c95eee394ce36c86e77f64b89a56de493c37e Mon Sep 17 00:00:00 2001 From: Blackbeard348 Date: Sat, 15 Mar 2025 19:07:20 +0800 Subject: [PATCH 1/6] first save --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index af7843d84..984e118a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1212,13 +1212,13 @@ "version": "15.7.12", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==", - "devOptional": true + "dev": true }, "node_modules/@types/react": { "version": "18.3.0", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.0.tgz", "integrity": "sha512-DiUcKjzE6soLyln8NNZmyhcQjVv+WsUIFSqetMN0p8927OztKT4VTfFTqsbAi5oAGIcgOmOajlfBqyptDDjZRw==", - "devOptional": true, + "dev": true, "dependencies": { "@types/prop-types": "*", "csstype": "^3.0.2" @@ -1678,7 +1678,7 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", - "devOptional": true + "dev": true }, "node_modules/data-view-buffer": { "version": "1.0.1", From 078bd4a30a56de97cf6fb415a284b5cb30ab392d Mon Sep 17 00:00:00 2001 From: Blackbeard348 Date: Sat, 15 Mar 2025 21:17:14 +0800 Subject: [PATCH 2/6] product list --- src/ProductList.jsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ProductList.jsx b/src/ProductList.jsx index 7682c04fc..8cc7abdd7 100644 --- a/src/ProductList.jsx +++ b/src/ProductList.jsx @@ -274,8 +274,22 @@ function ProductList({ onHomeClick }) { {!showCart ? (
- - + {plantsArray.map((category, index) => ( +
+

{category.category}

+
+ {category.plants.map((plant, plantIndex) => ( +
+
{plant.name}
+ {plant.name}/ +
{plant.description}
+

{plant.cost}

+ +
+ ))} +
+
+ ))}
) : ( From ee6d4e001f2096fa1a05f0943a89d18a74349423 Mon Sep 17 00:00:00 2001 From: Blackbeard348 Date: Fri, 21 Mar 2025 07:09:48 +0800 Subject: [PATCH 3/6] update --- .dependencygraph/data.json | 1 + .dependencygraph/setting.json | 15 ++++++++++++++ src/CartItem.jsx | 1 - src/CartSlice.jsx | 5 ++--- src/ProductList.jsx | 38 +++++++++++++++++++++++++++-------- 5 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 .dependencygraph/data.json create mode 100644 .dependencygraph/setting.json diff --git a/.dependencygraph/data.json b/.dependencygraph/data.json new file mode 100644 index 000000000..8b705deca --- /dev/null +++ b/.dependencygraph/data.json @@ -0,0 +1 @@ +{"dependencyTree":{"children":[]},"dependencyNodes":{}} \ No newline at end of file diff --git a/.dependencygraph/setting.json b/.dependencygraph/setting.json new file mode 100644 index 000000000..d439092c8 --- /dev/null +++ b/.dependencygraph/setting.json @@ -0,0 +1,15 @@ +{ + "entryFilePath": "src\\extension.ts", + "alias": { + "@": "./src" + }, + "resolveExtensions": [ + ".js", + ".jsx", + ".ts", + ".tsx", + ".vue", + ".scss", + ".less" + ] +} \ No newline at end of file diff --git a/src/CartItem.jsx b/src/CartItem.jsx index e06317433..23ee01406 100644 --- a/src/CartItem.jsx +++ b/src/CartItem.jsx @@ -17,7 +17,6 @@ const CartItem = ({ onContinueShopping }) => { }; - const handleIncrement = (item) => { }; diff --git a/src/CartSlice.jsx b/src/CartSlice.jsx index 32b8761ed..cce6ca992 100644 --- a/src/CartSlice.jsx +++ b/src/CartSlice.jsx @@ -7,13 +7,12 @@ export const CartSlice = createSlice({ }, reducers: { addItem: (state, action) => { - }, + removeItem: (state, action) => { }, - updateQuantity: (state, action) => { - + updateQuantity: (state, action) => { }, }, }); diff --git a/src/ProductList.jsx b/src/ProductList.jsx index 8cc7abdd7..c94fd4471 100644 --- a/src/ProductList.jsx +++ b/src/ProductList.jsx @@ -1,9 +1,25 @@ import React, { useState, useEffect } from 'react'; import './ProductList.css' import CartItem from './CartItem'; +import { addItem } from '/CartSlice'; +import { useDispatch } from 'react-redux'; + + + function ProductList({ onHomeClick }) { const [showCart, setShowCart] = useState(false); const [showPlants, setShowPlants] = useState(false); // State to control the visibility of the About Us page + const [addedToCart, setAddedToCart] = useState({}); // State to store the items added to the cart + const [cartItems, setCartItems] = useState([]); // State to store the items in the cart + const dispatch = useDispatch(); + + const handleAddToCart = (plant) => { + dispatch(addItem(plant)); + setAddedToCart((prevState) => ({ + ...prevState, + [plant.name]: true, + })); + }; const plantsArray = [ { @@ -252,6 +268,10 @@ function ProductList({ onHomeClick }) { e.preventDefault(); setShowCart(false); }; +FIXME: // Add the handleAddToCart function here + + + return (
@@ -274,22 +294,24 @@ function ProductList({ onHomeClick }) {
{!showCart ? (
- {plantsArray.map((category, index) => ( -
-

{category.category}

+
+ {plantsArray.map((category, index) => ( +
+

{category.category}

{category.plants.map((plant, plantIndex) => (
{plant.name}
{plant.name}/ -
{plant.description}
-

{plant.cost}

+
{plant.description}
+

{plant.cost}

- ))} + ))}
-
- ))} +
+ ))} +
) : ( From 53fe152f3655ecf0b68f37aeed617a55cbd6e57e Mon Sep 17 00:00:00 2001 From: Blackbeard348 Date: Sun, 23 Mar 2025 10:48:57 +0800 Subject: [PATCH 4/6] new changes --- src/CartItem.jsx | 2 ++ src/ProductList.jsx | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/CartItem.jsx b/src/CartItem.jsx index 23ee01406..762f51549 100644 --- a/src/CartItem.jsx +++ b/src/CartItem.jsx @@ -18,6 +18,8 @@ const CartItem = ({ onContinueShopping }) => { const handleIncrement = (item) => { + const updatedItem = { ...item, quantity: item.quantity + 1 }; + dispatch(updateQuantity(updatedItem)); }; const handleDecrement = (item) => { diff --git a/src/ProductList.jsx b/src/ProductList.jsx index c94fd4471..3883031b5 100644 --- a/src/ProductList.jsx +++ b/src/ProductList.jsx @@ -1,25 +1,18 @@ import React, { useState, useEffect } from 'react'; import './ProductList.css' import CartItem from './CartItem'; -import { addItem } from '/CartSlice'; import { useDispatch } from 'react-redux'; - +import CartSlice, { addItem, removeItem, updateQuantity } from './CartSlice'; // Import the reducer function ProductList({ onHomeClick }) { const [showCart, setShowCart] = useState(false); const [showPlants, setShowPlants] = useState(false); // State to control the visibility of the About Us page - const [addedToCart, setAddedToCart] = useState({}); // State to store the items added to the cart + const [addedToCart, setAddedToCart] = useState([]); // State to store the items added to the cart const [cartItems, setCartItems] = useState([]); // State to store the items in the cart const dispatch = useDispatch(); - const handleAddToCart = (plant) => { - dispatch(addItem(plant)); - setAddedToCart((prevState) => ({ - ...prevState, - [plant.name]: true, - })); - }; + const plantsArray = [ { @@ -268,8 +261,14 @@ function ProductList({ onHomeClick }) { e.preventDefault(); setShowCart(false); }; -FIXME: // Add the handleAddToCart function here + const handleAddToCart = (plants) => { + dispatch(addItem(plants)); + setAddedToCart((prevState) => ({ + ...prevState, + [plants.name]: true, + })); + }; return ( From 664931dfcfa51cf5d0e86a21f62706cbeca17487 Mon Sep 17 00:00:00 2001 From: Blackbeard348 Date: Sun, 23 Mar 2025 11:42:52 +0800 Subject: [PATCH 5/6] Reduc changes in CartSlice --- src/CartSlice.jsx | 18 ++++++++++++++++-- src/ProductList.jsx | 14 +++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/CartSlice.jsx b/src/CartSlice.jsx index cce6ca992..07eed8d55 100644 --- a/src/CartSlice.jsx +++ b/src/CartSlice.jsx @@ -7,16 +7,30 @@ export const CartSlice = createSlice({ }, reducers: { addItem: (state, action) => { + const { name, image, cost } = action.payload; + const existingItem = state.items.find(item => item.name === name); + if (existingItem) { + existingItem.quantity++; + } else { + state.items.push({ name, image, cost, quantity: 1 }); + } }, removeItem: (state, action) => { + state.items = state.items.filter(item => item.name !== action.payload); }, updateQuantity: (state, action) => { - }, - }, + const { name, quantity } = action.payload; + const itemToUpdate = state.items.find(item => item.name === name); + if (itemToUpdate) { + itemToUpdate.quantity = quantity; + } + } + } }); export const { addItem, removeItem, updateQuantity } = CartSlice.actions; export default CartSlice.reducer; + \ No newline at end of file diff --git a/src/ProductList.jsx b/src/ProductList.jsx index 3883031b5..7ff6bc4fb 100644 --- a/src/ProductList.jsx +++ b/src/ProductList.jsx @@ -8,7 +8,7 @@ import CartSlice, { addItem, removeItem, updateQuantity } 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 [addedToCart, setAddedToCart] = useState([]); // State to store the items added to the cart + const [addedToCart, setAddedToCart] = useState({}); // State to store the items added to the cart const [cartItems, setCartItems] = useState([]); // State to store the items in the cart const dispatch = useDispatch(); @@ -262,13 +262,13 @@ function ProductList({ onHomeClick }) { setShowCart(false); }; - const handleAddToCart = (plants) => { - dispatch(addItem(plants)); + const handleAddToCart = (product) => { + dispatch(addItem(product)); setAddedToCart((prevState) => ({ - ...prevState, - [plants.name]: true, - })); - }; + ...prevState, + [product.name]: true, // Set the product name as key and value as true to indicate it's added to cart + })); + }; return ( From 1aa1f9be10fe5f672fd65f8f869198893eeda088 Mon Sep 17 00:00:00 2001 From: Blackbeard348 Date: Mon, 24 Mar 2025 21:49:59 +0800 Subject: [PATCH 6/6] Total logic added --- src/CartItem.jsx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/CartItem.jsx b/src/CartItem.jsx index 762f51549..c740f688e 100644 --- a/src/CartItem.jsx +++ b/src/CartItem.jsx @@ -9,8 +9,22 @@ const CartItem = ({ onContinueShopping }) => { // Calculate total amount for all products in the cart const calculateTotalAmount = () => { - - }; + let total = 0; + + if (!cart || cart.length === 0) return total; + + cart.forEach(item => { + // Extract cost (remove $ and convert to number) + const cost = parseFloat(item.cost.substring(1)); + // Get quantity + const quantity = item.quantity || 0; + // Add to running total + total += cost * quantity; + }); + + // Return formatted total with 2 decimal places + return total.toFixed(2); +}; const handleContinueShopping = (e) => { @@ -31,7 +45,10 @@ const CartItem = ({ onContinueShopping }) => { // Calculate total cost based on quantity for an item const calculateTotalCost = (item) => { - }; + if (!item) return "0.00"; + const cost = parseFloat(item.cost.substring(1)); + return (cost * item.quantity).toFixed(2); +}; return (