diff --git a/src/app/portfolio/[uid]/page.tsx b/src/app/portfolio/[uid]/page.tsx index 97751af..42a8676 100644 --- a/src/app/portfolio/[uid]/page.tsx +++ b/src/app/portfolio/[uid]/page.tsx @@ -17,6 +17,7 @@ export default async function Portfolio({ ); const projectTag = async () => { + // get unique project id from deals const uniqueProjectIds = Array.from( new Set(deals?.map((deal) => deal.project_id)) ); @@ -24,8 +25,10 @@ export default async function Portfolio({ const tagIds = ( await Promise.all( uniqueProjectIds.map(async (projectId: number) => { - const { data: tagIdsArray, error: tagError } = - await getProjectTag(supabase, projectId); + const { data: tagIdsArray, error: tagError } = await getProjectTag( + supabase, + projectId + ); if (tagError) { console.error(tagError); return []; @@ -35,12 +38,15 @@ export default async function Portfolio({ ) ).flat(); - // console.log(tagIds); + // console.log(tagIds, uniqueProjectIds); const tagNames = await Promise.all( tagIds .filter((tagId) => tagId !== null) .map(async (id: number) => { - const { data: tagName, error: nameError } = await getTagName(supabase, id); + const { data: tagName, error: nameError } = await getTagName( + supabase, + id + ); if (nameError) { console.error(nameError); return null; @@ -48,24 +54,28 @@ export default async function Portfolio({ return tagName; }) ); - + // console.log(tagNames); return tagNames.filter((tagName) => tagName !== null); }; const countTags = (tags: any[]) => { - const tagCounts = tags.flat().reduce((acc, tag) => { + const tagCounts = tags.flat().reduce( + (acc, tag) => { const tagName = tag.value; acc[tagName] = (acc[tagName] || 0) + 1; return acc; - }, {} as Record); - - return Object.entries(tagCounts).map(([name, count]) => ({ - name, - count: count as number, - })); - }; + }, + {} as Record + ); + + return Object.entries(tagCounts).map(([name, count]) => ({ + name, + count: count as number, + })); + }; const tags = await projectTag(); - console.log(tags) - // const tagCount = countTags(tags); + // console.log(tags); + const tagCount = countTags(tags); + // console.log(tagCount); if (investorDealError) { console.error(investorDealError); @@ -163,6 +173,15 @@ export default async function Portfolio({ + item.count + )} + labels={tagCount.map( + (item: { name: string; count: number }) => item.name + )} + header="Total" + /> ); } diff --git a/src/components/pieChart.tsx b/src/components/pieChart.tsx index 5bd121f..7edbfc2 100644 --- a/src/components/pieChart.tsx +++ b/src/components/pieChart.tsx @@ -1,3 +1,5 @@ +"use client"; + import { Pie } from "react-chartjs-2"; import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; @@ -6,7 +8,7 @@ ChartJS.register(ArcElement, Tooltip, Legend); interface PieChartProps { labels: string[]; data: number[]; - header:string + header: string; } const PieChart = (props: PieChartProps) => { diff --git a/src/lib/data/query.ts b/src/lib/data/query.ts index 5c21498..e3ae04f 100644 --- a/src/lib/data/query.ts +++ b/src/lib/data/query.ts @@ -56,8 +56,8 @@ function getProjectTag(client: SupabaseClient, projectId: number) { return client.from("project_tag").select("tag_id").in("item_id", [projectId]); } -function getTagName(client: SupabaseClient, tagId: number){ - return client.from("project_tag").select("tag_id").in("item_id", [tagId]); +function getTagName(client: SupabaseClient, tagId: number) { + return client.from("tag").select("value").in("id", [tagId]); } export { @@ -67,5 +67,5 @@ export { getTags, getInvestorDeal, getProjectTag, - getTagName + getTagName, };