Skip to content
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

PTBC9 - Patrick #34

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

PTBC9 - Patrick #34

wants to merge 9 commits into from

Conversation

patrickkok
Copy link

No description provided.

useEffect(() => {
const getSightings = async () => {
const freshSightings = await fetch(BACKEND_URL + "/sightings", {
method: "get",
Copy link

Choose a reason for hiding this comment

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

I think get is the default for the fetch API, so redundant to add this

Comment on lines +23 to +26
const id = sighting.id;
const date = sighting.date;
const location = sighting.location;
const categories = sighting.categories;
Copy link

Choose a reason for hiding this comment

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

const { id, date, location, categories } = sighting;

easier

}));

setCategoryOptions(newCategoryOptions);
console.log(categoryOptions);
Copy link

Choose a reason for hiding this comment

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

remove logs

};
const handleSelectChange = (e) => {
const categoriesArr = e.map((obj) => obj.value);
console.log(categoriesArr);
Copy link

Choose a reason for hiding this comment

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

log

e.preventDefault();
const addNewSighting = async () => {
const categoriesArr = selectFields.map((obj) => obj.value);
await fetch(BACKEND_URL + "/sightings/", {
Copy link

Choose a reason for hiding this comment

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

i like that you explore the fetch API

body: JSON.stringify({ input: inputFields, categories: categoriesArr }),
})
.then((response) => response.json())
.then((data) => console.log(data));
Copy link

Choose a reason for hiding this comment

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

why use promise and all if you just console.log in the end? Usually you would need to update the list of sightings after creating a new one

type="text"
value={inputFields.date}
onChange={(e) => handleChange(e, "date")}
></input>
Copy link

Choose a reason for hiding this comment

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

Suggested change
></input>
/>

const { int } = useParams();

const fetchComments = async () => {
const fetchedComments = await fetch(BACKEND_URL + "/comments/" + int, {
Copy link

Choose a reason for hiding this comment

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

what if int is undefined or letters?

method: "get",
});
const fetchedCommentsJson = await fetchedComments.json();
setComments([...fetchedCommentsJson]);
Copy link

Choose a reason for hiding this comment

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

why not just setComments(fetchedCommentsJson) ?

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