diff --git a/src/app/portfolio/[uid]/hook.ts b/src/app/portfolio/[uid]/hook.ts index 4d59dfa..151d0eb 100644 --- a/src/app/portfolio/[uid]/hook.ts +++ b/src/app/portfolio/[uid]/hook.ts @@ -1,6 +1,22 @@ import { SupabaseClient } from "@supabase/supabase-js"; import { getProjectTag, getTagName } from "@/lib/data/tagQuery"; +async function fetchLogoURL(supabase: SupabaseClient, projectId: number) { + const logoIndex = 1; + let { data: project_material, error } = await supabase + .from("project_material") + .select("material_url") + .eq("project_id", projectId) + .eq("material_type_id", logoIndex); + if (error) { + console.error("Error while fetching golo url" + error); + } + if (project_material && project_material.length > 0) { + return project_material[0].material_url; + } + return ""; +} + function getTotalInvestment(deals: { deal_amount: number }[]) { let total = 0; for (let index = 0; index < deals.length; index++) { @@ -20,10 +36,12 @@ async function getLatestInvestment( if (error) { console.error(error); } + let url = fetchLogoURL(supabase, deals[i].project_id); llist.push({ name: project?.[0]?.project_name, amount: deals[i].deal_amount, date: new Date(deals[i].created_time), + logo_url: url, }); } @@ -234,4 +252,5 @@ export { checkForInvest, getLatestInvestment, getTotalInvestment, + fetchLogoURL, }; diff --git a/src/app/portfolio/[uid]/page.tsx b/src/app/portfolio/[uid]/page.tsx index dd8ec1a..052e7ca 100644 --- a/src/app/portfolio/[uid]/page.tsx +++ b/src/app/portfolio/[uid]/page.tsx @@ -57,9 +57,17 @@ export default async function Portfolio({ params }: { params: { uid: string } }) const fourYearData = deals ? fourYearGraphData(deals) : []; const dayOfWeekData = deals ? dayOftheWeekData(deals) : []; const tags = deals ? await getInvestorProjectTag(supabase, deals) : []; - const latestDeals = deals ? await getLatestInvestment(supabase, deals) : []; + const latestDeals = deals + ? await Promise.all( + (await getLatestInvestment(supabase, deals)).map(async (deal) => ({ + ...deal, + logo_url: await deal.logo_url, + })) + ) + : []; const totalInvestment = deals ? getTotalInvestment(deals) : 0; // console.log(latestDeals); + const tagCount = countTags(tags); // console.log(investedBusinessIds); const businessType = deals diff --git a/src/components/recent-funds.tsx b/src/components/recent-funds.tsx index 5a1c71b..3707d2d 100644 --- a/src/components/recent-funds.tsx +++ b/src/components/recent-funds.tsx @@ -5,12 +5,12 @@ export type RecentDealData = { deal_amount: number; investor_id: string; username: string; - avatar_url?: string; + logo_url?: string; // email: string; }; interface RecentFundsProps { - data?: { name?: string; amount?: number; avatar?: string; date?: Date }[]; + data?: { name?: string; amount?: number; avatar?: string; date?: Date; logo_url?: string }[]; } export function RecentFunds(props: RecentFundsProps) { @@ -19,7 +19,7 @@ export function RecentFunds(props: RecentFundsProps) { {(props?.data || []).map((deal, index) => (