-
Notifications
You must be signed in to change notification settings - Fork 1
More code review suggestions #251
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
base: main
Are you sure you want to change the base?
Conversation
|
@yeo-yeo is attempting to deploy a commit to the Yuqing's projects Team on Vercel. A member of the Team first needs to authorize it. |
| .eq('id', userID) | ||
| const favouriteItems: number[] | null = | ||
| favourites && favourites[0].favourite_items | ||
| const favouriteItems = favourites && favourites[0].favourite_items |
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 haven't systematically been through but I think there a few places like this where you shouldn't need to declare the types so you can just get rid of them
| return ( | ||
| <Button | ||
| className={`bg-foundation text-white rounded-full ${className || ''}`} | ||
| <Link |
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.
Buttons like Message Seller only work if you click on the button text at the moment! I thought there was something wrong with their click handlers/links but then I realised the issue is only the text was being turned into a link
(I might not have got the class/css stuff right here)
| )) as Item[] | ||
| itemDetails = itemDetails.filter(item => item !== undefined) | ||
| if (!userID) { | ||
| return null |
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.
maybe this isn't the right thing to return, I was being lazy
I think it should be impossible for a logged out user to reach this component so this could actually be a legit time to use userID! on line 13!
| ) | ||
|
|
||
| const items = fetchedItems.filter( | ||
| (item: Item | undefined): item is Item => item !== undefined, |
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.
this here is some pure typescript magic called a 'type predicate'. the item is Item bit means 'what I'm going to return from this little fn is of type Item', and this does away with the annoying (Item | undefined)[] situation you were in before. Just using the filter without this type predicate magic annoyingly doesn't convince Typescript that you've got rid of the undefineds (even though you have)
| const seller_name = await fetchSellerName( | ||
| supabase, | ||
| itemDetails[0].seller_id || '', | ||
| itemDetails?.[0]?.seller_id || '', |
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.
With the changes here and in fetchItemDetails I think a bug should be fixed where at the moment if you try to view your favourite items but you don't have any, the whole page crashes
No description provided.