From 811277d1498fa025d4d7bb7ba478e7182c0acf90 Mon Sep 17 00:00:00 2001 From: Robin Schanbacher Date: Mon, 3 Aug 2026 17:13:54 +0200 Subject: [PATCH] feat: display per categorie informations --- app/evaluation/[days]/[...ical-link]/page.tsx | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/app/evaluation/[days]/[...ical-link]/page.tsx b/app/evaluation/[days]/[...ical-link]/page.tsx index 7a8dca1..0dc7cfd 100644 --- a/app/evaluation/[days]/[...ical-link]/page.tsx +++ b/app/evaluation/[days]/[...ical-link]/page.tsx @@ -1,4 +1,5 @@ import ical, { VEvent } from 'node-ical'; + interface PageProps { params: Promise<{ 'days': string; @@ -19,7 +20,19 @@ function getIcalDate(dateValue: any): Date { return new Date(dateValue); } +function getCategories(categoriesField: any): string[] { + if (!categoriesField) return []; + if (Array.isArray(categoriesField)) { + return categoriesField.map((cat) => getIcalText(cat)); + } + return [getIcalText(categoriesField)]; +} + +type TimeMap = Record + export default async function EvaluationPage({ params }: PageProps) { + let times: TimeMap = {}; + // get all params const resolvedParams = await params; @@ -54,10 +67,38 @@ export default async function EvaluationPage({ params }: PageProps) { return startDate >= cutoffDate && startDate <= now; }) .sort((a, b) => getIcalDate(b.start).getTime() - getIcalDate(a.start).getTime()); // newest first + + // read time per categorie + events.map((event, index) => { + const startDate = getIcalDate(event.start); + const endDate = getIcalDate(event.end); + const durationInMs = endDate.getTime() - startDate.getTime(); + const durationInMinutes = durationInMs / (1000 * 60); + const categories = getCategories(event.categories); + + categories.forEach((cat) => { + times[cat] = (times[cat] || 0) + durationInMinutes + }) + }) return ( -
+

Meine Kalender-Events

+ +
+

Gesamtdauer pro Kategorie

+ {Object.keys(times).length === 0 ? ( +

Keine Zeiten erfasst.

+ ) : ( +
    + {Object.entries(times).map(([category, minutes]) => ( +
  • + {category}: {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt) +
  • + ))} +
+ )} +
{events.length === 0 ? (

Keine Termine gefunden.