feat: display per categorie informations

This commit is contained in:
robin committed 2026-08-03 17:13:54 +02:00
1 parent adf4446f8a
commit 811277d149
1 file changed
+42 -1
+42 -1
View File
@@ -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<string, number>
export default async function EvaluationPage({ params }: PageProps) {
let times: TimeMap = {};
// get all params
const resolvedParams = await params;
@@ -55,10 +68,38 @@ export default async function EvaluationPage({ params }: PageProps) {
})
.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 (
<main style={{ padding: '2rem', fontFamily: 'sans-serif' }}>
<main>
<h1>Meine Kalender-Events</h1>
<section>
<h2>Gesamtdauer pro Kategorie</h2>
{Object.keys(times).length === 0 ? (
<p>Keine Zeiten erfasst.</p>
) : (
<ul>
{Object.entries(times).map(([category, minutes]) => (
<li key={category}>
<strong>{category}:</strong> {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt)
</li>
))}
</ul>
)}
</section>
{events.length === 0 ? (
<p>Keine Termine gefunden.</p>
) : (