diff --git a/src/App.jsx b/src/App.jsx
index 03e658b..e3305ca 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,44 +1,45 @@
-import './styles/reset.css'
-import './styles/index.css'
+import React, { useState } from 'react';
+import Store from './Store';
+import Cart from './Cart';
+import storeItems from './store-items';
+import './styles/index.css';
-import initialStoreItems from './store-items'
+function App() {
+ const [cart, setCart] = useState([]);
+
+ const addToCart = (item) => {
+ const existingItem = cart.find(cartItem => cartItem.id === item.id);
+ if (existingItem) {
+ setCart(cart.map(cartItem =>
+ cartItem.id === item.id ? { ...cartItem, quantity: cartItem.quantity + 1 } : cartItem
+ ));
+ } else {
+ setCart([...cart, { ...item, quantity: 1 }]);
+ }
+ };
+
+ const updateQuantity = (id, quantity) => {
+ setCart(cart.map(cartItem =>
+ cartItem.id === id ? { ...cartItem, quantity: Math.max(0, cartItem.quantity + quantity) } : cartItem
+ ).filter(cartItem => cartItem.quantity > 0));
+ };
+
+ const getTotal = () => {
+ return cart.reduce((total, item) => total + item.price * item.quantity, 0).toFixed(2);
+ };
-export default function App() {
return (
- <>
+
Your Cart
-
-
-
-
Total
-
-
- £0.00
-
-
+
-
- >
- )
+
+ );
}
+
+export default App;
diff --git a/src/Cart.jsx b/src/Cart.jsx
new file mode 100644
index 0000000..6e3ea45
--- /dev/null
+++ b/src/Cart.jsx
@@ -0,0 +1,20 @@
+import React from 'react';
+import CartItem from './CartItem';
+
+function Cart({ cart, updateQuantity, total }) {
+ return (
+
+
+ {cart.map(item => (
+
+ ))}
+
+
+
Total
+ £{total}
+
+
+ );
+}
+
+export default Cart;
diff --git a/src/CartItem.jsx b/src/CartItem.jsx
new file mode 100644
index 0000000..0eeb368
--- /dev/null
+++ b/src/CartItem.jsx
@@ -0,0 +1,15 @@
+import React from 'react';
+
+function CartItem({ item, updateQuantity }) {
+ return (
+
+
+ {item.name}
+
+ {item.quantity}
+
+
+ );
+}
+
+export default CartItem;
diff --git a/src/Item.jsx b/src/Item.jsx
new file mode 100644
index 0000000..1bb77ac
--- /dev/null
+++ b/src/Item.jsx
@@ -0,0 +1,14 @@
+import React from 'react';
+
+function Item({ item, addToCart }) {
+ return (
+
+
+

+
+
+
+ );
+}
+
+export default Item;
diff --git a/src/Store.jsx b/src/Store.jsx
new file mode 100644
index 0000000..20849ae
--- /dev/null
+++ b/src/Store.jsx
@@ -0,0 +1,14 @@
+import React from 'react';
+import Item from './Item';
+
+function Store({ items, addToCart }) {
+ return (
+
+ {items.map(item => (
+
+ ))}
+
+ );
+}
+
+export default Store;
diff --git a/src/main.jsx b/src/main.jsx
index 51a8c58..5ce65a6 100644
--- a/src/main.jsx
+++ b/src/main.jsx
@@ -1,9 +1,11 @@
-import React from 'react'
-import ReactDOM from 'react-dom/client'
-import App from './App.jsx'
+import React from 'react';
+import ReactDOM from 'react-dom';
+import App from './App';
+import './styles/index.css';
-ReactDOM.createRoot(document.getElementById('root')).render(
+ReactDOM.render(
,
-)
+ document.getElementById('root')
+);
diff --git a/src/store-items.js b/src/store-items.js
index 96dd2ea..1e5622c 100644
--- a/src/store-items.js
+++ b/src/store-items.js
@@ -1,4 +1,3 @@
-
const storeItems = [
{
id: "001-beetroot",
@@ -70,6 +69,6 @@ const storeItems = [
description: "Eggplant, aubergine, brinjal, or baigan is a plant species in the nightshade family Solanaceae. Solanum melongena is grown worldwide for its edible fruit.",
type: "vegetable"
}
-]
+];
-export default storeItems
+export default storeItems;
diff --git a/src/styles/index.css b/src/styles/index.css
index 0a04c2b..b188921 100644
--- a/src/styles/index.css
+++ b/src/styles/index.css
@@ -15,7 +15,6 @@ h2 {
button {
padding: 0.25rem 0.5rem;
-
text-transform: uppercase;
font-size: 0.725rem;
}
@@ -25,9 +24,7 @@ button {
#store {
height: 40vh;
padding: 1rem;
-
overflow-y: scroll;
-
background-color: #e7f4ea;
}
@@ -70,12 +67,10 @@ button {
#cart {
height: 60vh;
padding: 1rem;
-
display: grid;
grid-template-rows: auto 1fr auto;
grid-gap: 1rem;
justify-content: center;
-
border-top: 2px solid #00675b;
}
@@ -88,9 +83,7 @@ button {
min-width: 320px;
height: 100%;
padding: 0 1rem;
-
overflow-y: scroll;
-
border-radius: 0.5rem;
border: 2px solid #757575;
}
@@ -103,14 +96,11 @@ button {
.cart--item-list li {
padding: 1rem 0;
-
display: grid;
grid-template-columns: 24px minmax(150px, 1fr) repeat(3, auto);
grid-gap: 0.5rem;
align-items: center;
-
border-bottom: 1px dotted #000000;
-
font-size: 1.25rem;
}
@@ -131,9 +121,7 @@ button {
width: 20px;
height: 20px;
padding: 0;
-
border-radius: 0.25rem;
-
font-weight: bold;
}
@@ -152,11 +140,9 @@ button {
.quantity-text {
width: 24px;
height: 24px;
-
border-radius: 0.25rem;
border: 2px solid #757575;
color: #757575;
-
text-align: center;
font-size: 0.75rem;
font-weight: bold;
@@ -166,7 +152,6 @@ button {
.total-section {
padding: 0.5rem 1rem;
-
display: grid;
grid-template-columns: 1fr auto;
align-items: center;