-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,17 @@ export default function WideFoundationButton({ | |
| className?: string | ||
| }) { | ||
| return ( | ||
| <Button | ||
| className={`bg-foundation text-white rounded-full ${className || ''}`} | ||
| <Link | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
| href={pageUrl} | ||
| className={`bg-foundation text-white text-center rounded-full ${ | ||
| className || '' | ||
| }`} | ||
| > | ||
| <Link href={pageUrl}>{buttonTitle}</Link> | ||
| </Button> | ||
| <Button | ||
| className={`bg-foundation text-white rounded-full ${className || ''}`} | ||
| > | ||
| {buttonTitle} | ||
| </Button> | ||
| </Link> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,24 +2,19 @@ import getItemDetails from '@/utils/fetchItemDetails' | |
| import ItemCard from '@/components/cards/ItemCard' | ||
| import fetchSellerName from '@/utils/fetchSellerName' | ||
| import getUser from '@/utils/getUser' | ||
| import { Item } from '@/utils/types' | ||
|
|
||
| export default async function Purchase() { | ||
| const { supabase, userID } = await getUser() | ||
|
|
||
| let itemDetails: Item[] = [] | ||
| if (userID) { | ||
| itemDetails = (await getItemDetails( | ||
| supabase, | ||
| 'favourite_items', | ||
| userID, | ||
| )) as Item[] | ||
| itemDetails = itemDetails.filter(item => item !== undefined) | ||
| if (!userID) { | ||
| return null | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| const itemDetails = await getItemDetails(supabase, 'favourite_items', userID) | ||
|
|
||
| const seller_name = await fetchSellerName( | ||
| supabase, | ||
| itemDetails[0].seller_id || '', | ||
| itemDetails?.[0]?.seller_id || '', | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the changes here and in |
||
| ) | ||
|
|
||
| return ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { createClient } from '@/utils/supabase/server' | ||
| import { Item } from '@/utils/types' | ||
|
|
||
| export default async function getItemDetails( | ||
| supabase: ReturnType<typeof createClient>, | ||
|
|
@@ -10,20 +11,24 @@ export default async function getItemDetails( | |
| .select(column_name as '*') | ||
| .eq('id', user_id) | ||
|
|
||
| const itemIds: number[] = data?.[0][`${column_name}`] ?? [] | ||
|
|
||
| if (itemIds) { | ||
| const itemDetails = await Promise.all( | ||
| itemIds && | ||
| itemIds.map(async item_id => { | ||
| const { data } = await supabase | ||
| .from('items') | ||
| .select('*') | ||
| .eq('item_id', item_id) | ||
| return data && data[0] | ||
| }), | ||
| ) | ||
| return itemDetails | ||
| if (!data || data.length === 0) { | ||
| return [] | ||
| } | ||
| return [] | ||
|
|
||
| const itemIds = data[0][`${column_name}`] ?? [] | ||
|
|
||
| const fetchedItems = await Promise.all( | ||
| itemIds.map(async item_id => { | ||
| const { data } = await supabase | ||
| .from('items') | ||
| .select('*') | ||
| .eq('item_id', item_id) | ||
| return data?.[0] | ||
| }), | ||
| ) | ||
|
|
||
| const items = fetchedItems.filter( | ||
| (item: Item | undefined): item is Item => item !== undefined, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this here is some pure typescript magic called a 'type predicate'. the |
||
| ) | ||
| return 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