Skip to content

Fetching from backend#26

Draft
wr1159 wants to merge 4 commits into
designfrom
fetch-backend
Draft

Fetching from backend#26
wr1159 wants to merge 4 commits into
designfrom
fetch-backend

Conversation

@wr1159

@wr1159 wr1159 commented Oct 28, 2023

Copy link
Copy Markdown

Added fetch statements either in react hooks or using getStaticProps

@wr1159 wr1159 self-assigned this Oct 28, 2023
@wr1159 wr1159 marked this pull request as draft October 28, 2023 17:58
@wr1159 wr1159 added the enhancement New feature or request label Oct 28, 2023
Comment thread pages/events.tsx
Comment on lines +258 to +261
if (query.trim() === '') {
setEventCount(defaultList.length)
setPageCount(1)
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

try writing code in an "early return" idea.
consider this with multiple cases, will be very clear.

if (case A || case B) { ... return }
if (case C) {... return}
if (case D) {... return}

compared to

if (A) { ...} 
else if (B) {...}
else if (C) {...} 

Comment thread pages/events.tsx
Comment on lines 281 to 286
const realQuery = query.toLowerCase()
const filtered = defaultList.filter((event) => {
return searchedCategories.some((type) => {
return event[type].toLowerCase().includes(realQuery)
})
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not truly understanding the use case here, but can try useMemo to return filtered as a value instead.

though after the latest react update we might no longer need all these KEK

Comment thread pages/events.tsx
key={index}
title={event.name}
description={event.description}
imgPosition={index % 2 === 0 ? 'left' : 'right'}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

notice how === 0 is not required here~

Comment thread pages/events.tsx
// direct database queries.
export async function getStaticProps() {
try {
const res = await fetch('https://.../events')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could consider using a promise instead.

Comment thread pages/index.tsx
console.error('Error fetching photos', error)
return {
props: {
carouselPhotos: [],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not very elegant but can handle errors by adding new props
carouselPhotos: {
data: [],
error: {
message: "unauthorised query"
status: 401
}
}

@cjunxiang

Copy link
Copy Markdown

ok bye just happened to be on github after awhile so decided to drop by. have fun coding!

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants