diff --git a/db.json b/db.json index 285c67c0..0f1f4d0f 100644 --- a/db.json +++ b/db.json @@ -35,6 +35,42 @@ "name": "Cookies", "category": "Dessert", "isInCart": false + }, + { + "name": "", + "category": "Produce", + "isInCart": false, + "id": 7 + }, + { + "name": "", + "category": "Produce", + "isInCart": false, + "id": 8 + }, + { + "name": "fdesgfserf", + "category": "Dessert", + "isInCart": false, + "id": 9 + }, + { + "name": "fdesgfserf", + "category": "Dessert", + "isInCart": false, + "id": 10 + }, + { + "name": "dwad", + "category": "Produce", + "isInCart": false, + "id": 11 + }, + { + "name": "dweadw", + "category": "Produce", + "isInCart": false, + "id": 12 } ] } \ No newline at end of file diff --git a/src/components/Item.js b/src/components/Item.js index 2f40e63f..c4cccfdb 100644 --- a/src/components/Item.js +++ b/src/components/Item.js @@ -1,14 +1,38 @@ import React from "react"; -function Item({ item }) { +function Item({ item, onUpdateItem, onDeleteItem }) { + function handleAddToCartClick() { + // add fetch request + fetch(`http://localhost:4000/items/${item.id}`, { + method: "PATCH", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + isInCart: !item.isInCart, + }), + }) + .then((r) => r.json()) + .then((updatedItem) => onUpdateItem(updatedItem)); + } + + + function handleDeleteClick() { + fetch(`http://localhost:4000/items/${item.id}`, { + method: "DELETE", + }) + .then((r) => r.json()) + .then((r) => onDeleteItem(item)); + } + return (