-
Notifications
You must be signed in to change notification settings - Fork 93
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
base: main
Are you sure you want to change the base?
PTBC9 - Patrick #34
Conversation
…ual sighting pages
…s page, minor bugfix
useEffect(() => { | ||
const getSightings = async () => { | ||
const freshSightings = await fetch(BACKEND_URL + "/sightings", { | ||
method: "get", |
There was a problem hiding this comment.
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
const id = sighting.id; | ||
const date = sighting.date; | ||
const location = sighting.location; | ||
const categories = sighting.categories; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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/", { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
></input> | |
/> |
const { int } = useParams(); | ||
|
||
const fetchComments = async () => { | ||
const fetchedComments = await fetch(BACKEND_URL + "/comments/" + int, { |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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)
?
No description provided.