From 2b05397b55041c582615382b8f7b655d4ff77214 Mon Sep 17 00:00:00 2001 From: timhaller <67918170+timhaller@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:11:24 +0100 Subject: [PATCH] added results page --- app/results/[id]/page.tsx | 24 ++++++++++++++++++++++-- components/custom/chart.tsx | 3 ++- components/custom/dayCard.tsx | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/results/[id]/page.tsx b/app/results/[id]/page.tsx index c3a16ea..93967e5 100644 --- a/app/results/[id]/page.tsx +++ b/app/results/[id]/page.tsx @@ -3,6 +3,11 @@ import {Chart} from "@components/custom/chart"; import Prisma from '@lib/prisma' +interface data { + name: string + total: number +} + export default async function Page({ params }: { params: { id: string } }) { const grades = await Prisma.grade.findMany({ where: { @@ -10,12 +15,27 @@ export default async function Page({ params }: { params: { id: string } }) { } }) + const allGrades = ['1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5', '5.5', '6'] + let gradeOccurences = new Array(allGrades.length).fill(0) + const gradeList = grades.map((grade) => grade.grade) + + for (let i = 0; i < gradeList.length; i++) { + gradeOccurences[allGrades.indexOf(gradeList[i].toString())]++ + } + + let data: data[] = [] + for (let i = 0; i < gradeOccurences.length; i++) { + data.push({ + name: allGrades[i], + total: gradeOccurences[i] + }) + } + for (let grade in grades) { console.log(grade); } return
- My Post: {params.id} - +
} diff --git a/components/custom/chart.tsx b/components/custom/chart.tsx index dcab596..50bd8fb 100644 --- a/components/custom/chart.tsx +++ b/components/custom/chart.tsx @@ -25,7 +25,8 @@ export function Chart({...props}: ChartProps) { fontSize={12} tickLine={false} axisLine={false} - tickFormatter={(value) => `$${value}`} + allowDecimals={false} + tickFormatter={(value) => `${value}`} /> diff --git a/components/custom/dayCard.tsx b/components/custom/dayCard.tsx index 9334e63..e0faea9 100644 --- a/components/custom/dayCard.tsx +++ b/components/custom/dayCard.tsx @@ -37,7 +37,7 @@ export function DayCard({ className, ...props }: DayCardProps) { } return ( - {route(props.enabled || false, props.day)}}> + {route(props.enabled || false, props.day)}}> {props.enabled ?