diff --git a/GreenGrocersTree.jpg b/GreenGrocersTree.jpg new file mode 100644 index 0000000..0ec0a46 Binary files /dev/null and b/GreenGrocersTree.jpg differ diff --git a/src/App.jsx b/src/App.jsx index 03e658b..9d5d231 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,31 +1,57 @@ import './styles/reset.css' import './styles/index.css' - +import YourItems from './components/YourItems' +import Heading from './components/Heading' import initialStoreItems from './store-items' +import ProductItems from './components/ProductItems' +import React from 'react' +import YourCart from './components/YourCart' +import CartContainer from './components/CartContainer' + + export default function App() { +const [productList, setProductList] = React.useState(initialStoreItems) +const [cartList, setCartList] = React.useState([]) + +const onItemClick = (product) => { return () => { + const foundProduct = cartList.find((item)=> {return item.name === product.name}) + if (foundProduct != undefined) { + const filteredCartList = cartList.filter((item)=>{return item.name != product.name}) + const newCart = [...filteredCartList, {...product, amount:foundProduct.amount+1 }] + setCartList(newCart) + } else { + const newCart = [...cartList, {...product, amount:1 }] + setCartList(newCart) + } +}} + +const onCartUpdate = (product, changeNumber) => { +return ()=>{ + const newAmount = product.amount + changeNumber + const newCart = cartList.map((item)=>{return {...item, amount:newAmount}}).filter((item)=>{return item.amount > 0}) + setCartList(newCart) + console.log('product:', product, changeNumber) +} +} +const totalAmount = cartList.reduce((a, b)=>{return a + (b.amount * b.price)}, 0) return ( - <> -
-

Greengrocers

- -
-
-

Your Cart

-
- -
-
+ <> + Green Grocers + + + + Your Cart + +

Total

- £0.00 + £{totalAmount.toFixed(2)}
-
+
Icons made by + +
) +} \ No newline at end of file diff --git a/src/components/Heading/index.jsx b/src/components/Heading/index.jsx new file mode 100644 index 0000000..332eb12 --- /dev/null +++ b/src/components/Heading/index.jsx @@ -0,0 +1,3 @@ +export default function Heading({children}) { + return

{children}

+} \ No newline at end of file diff --git a/src/components/ProductItems/index.jsx b/src/components/ProductItems/index.jsx new file mode 100644 index 0000000..f0e57cc --- /dev/null +++ b/src/components/ProductItems/index.jsx @@ -0,0 +1,8 @@ +export default function ProductItems({onItemClick, productList}) { + return () +} \ No newline at end of file diff --git a/src/components/YourCart/index.jsx b/src/components/YourCart/index.jsx new file mode 100644 index 0000000..53ec910 --- /dev/null +++ b/src/components/YourCart/index.jsx @@ -0,0 +1,3 @@ +export default function YourCart({cartList, onCartUpdate, children}) { + return
{children}
+} \ No newline at end of file diff --git a/src/components/YourItems/index.jsx b/src/components/YourItems/index.jsx new file mode 100644 index 0000000..00556a8 --- /dev/null +++ b/src/components/YourItems/index.jsx @@ -0,0 +1,3 @@ +export default function YourItems({productList, onItemClick, children}) { + return
{children}
+} \ No newline at end of file