Skip to content

Fetch to Add, Delete, and Update #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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() {

return (
<li className={item.isInCart ? "in-cart" : ""}>
<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