diff --git a/app/item/[id]/page.tsx b/app/item/[id]/page.tsx index ca0001d..244b179 100644 --- a/app/item/[id]/page.tsx +++ b/app/item/[id]/page.tsx @@ -61,8 +61,7 @@ export default async function listing({ .from('users') .select('favourite_items') .eq('id', userID) - const favouriteItems: number[] | null = - favourites && favourites[0].favourite_items + const favouriteItems = favourites && favourites[0].favourite_items return ( diff --git a/app/products/[category]/page.tsx b/app/products/[category]/page.tsx index 1a9d9fd..ceef42c 100644 --- a/app/products/[category]/page.tsx +++ b/app/products/[category]/page.tsx @@ -25,8 +25,7 @@ export default async function Page({ .select('favourite_items') .eq('id', userID || '') - const favouriteItems: number[] | null = - favourites && favourites[0].favourite_items + const favouriteItems = favourites && favourites[0].favourite_items return ( diff --git a/app/signup/page.tsx b/app/signup/page.tsx index 1766332..ba87272 100644 --- a/app/signup/page.tsx +++ b/app/signup/page.tsx @@ -62,7 +62,7 @@ export default async function Login({ first_name: firstName, last_name: lastName, created_at: new Date(), - email: email + email: email, }) .select() diff --git a/components/buttons/WideFoundationButton.tsx b/components/buttons/WideFoundationButton.tsx index d5ea599..5c74076 100644 --- a/components/buttons/WideFoundationButton.tsx +++ b/components/buttons/WideFoundationButton.tsx @@ -11,10 +11,17 @@ export default function WideFoundationButton({ className?: string }) { return ( - + + ) } diff --git a/components/user-info/UserFavourites.tsx b/components/user-info/UserFavourites.tsx index faa962b..71fd4ab 100644 --- a/components/user-info/UserFavourites.tsx +++ b/components/user-info/UserFavourites.tsx @@ -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 } + const itemDetails = await getItemDetails(supabase, 'favourite_items', userID) + const seller_name = await fetchSellerName( supabase, - itemDetails[0].seller_id || '', + itemDetails?.[0]?.seller_id || '', ) return ( diff --git a/utils/fetchItemDetails.ts b/utils/fetchItemDetails.ts index 87f7ee3..8840aa3 100644 --- a/utils/fetchItemDetails.ts +++ b/utils/fetchItemDetails.ts @@ -1,4 +1,5 @@ import { createClient } from '@/utils/supabase/server' +import { Item } from '@/utils/types' export default async function getItemDetails( supabase: ReturnType, @@ -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, + ) + return items }