Skip to content

Conversation

@yeo-yeo
Copy link

@yeo-yeo yeo-yeo commented Dec 7, 2023

No description provided.

@vercel
Copy link

vercel bot commented Dec 7, 2023

@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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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,
Copy link
Author

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 || '',
Copy link
Author

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

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.

1 participant