Skip to content

Conversation

@Lsimmons98
Copy link

Used fetch requests and state to add, delete, and update things on both the database and the DOM.

Copy link

@stephenmckeon stephenmckeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's just a code along, but I'd still like to see the code be "production ready" when you submit it. This time I won't, but going forward, I'm going to make you go back and cleanup your syntax. I really need you to start paying more attention to it. Otherwise, the concepts are there and you're going great, so keep that up!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be mindful of committing changes like this.

function Item({ item }) {
function Item({ item, onUpdateItem, onDeleteItem }) {
function handleAddToCartClick() {
// add fetch request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// add fetch request

Comment on lines +17 to +20
}


function handleDeleteClick() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
function handleDeleteClick() {
}
function handleDeleteClick() {

<span>{item.name}</span>
<span className="category">{item.category}</span>
<button className={item.isInCart ? "remove" : "add"}>
<button onClick={handleAddToCartClick}className={item.isInCart ? "remove" : "add"}>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<button onClick={handleAddToCartClick}className={item.isInCart ? "remove" : "add"}>
<button onClick={handleAddToCartClick} className={item.isInCart ? "remove" : "add"}>

{item.isInCart ? "Remove From" : "Add to"} Cart
</button>
<button className="remove">Delete</button>
<button onClick={handleDeleteClick}className="remove">Delete</button>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<button onClick={handleDeleteClick}className="remove">Delete</button>
<button onClick={handleDeleteClick} className="remove">Delete</button>

Comment on lines +3 to +9
function ItemForm({ onAddItem }) {
const [name, setName] = useState("");
const [category, setCategory] = useState("Produce");



function handleSubmit(e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ItemForm({ onAddItem }) {
const [name, setName] = useState("");
const [category, setCategory] = useState("Produce");
function handleSubmit(e) {
function ItemForm({ onAddItem }) {
const [name, setName] = useState("");
const [category, setCategory] = useState("Produce");
function handleSubmit(e) {

Comment on lines +9 to +25
function handleSubmit(e) {
e.preventDefault();
const itemData = {
name: name,
category: category,
isInCart: false,
};
fetch("http://localhost:4000/items", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(itemData),
})
.then((r) => r.json())
.then((newItem) => onAddItem(newItem));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole function needs to be indented.

Comment on lines +55 to 59
<Item key={item.id} item={item}
onUpdateItem={handleUpdateItem}
onDeleteItem={handleDeleteItem}/>

))}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Item key={item.id} item={item}
onUpdateItem={handleUpdateItem}
onDeleteItem={handleDeleteItem}/>
))}
<Item key={item.id} item={item}
onUpdateItem={handleUpdateItem}
onDeleteItem={handleDeleteItem}/>
))}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants