import ical, { VEvent } from 'node-ical'; interface PageProps { params: Promise<{ 'days': string; 'ical-link': string[]; }>; } function getIcalText(field: any): string { if (!field) return ''; if (typeof field === 'string') return field; if (typeof field === 'object' && 'val' in field) return field.val as string; return String(field); } function getIcalDate(dateValue: any): Date { if (!dateValue) return new Date(0); // Fallback: 01.01.1970, falls kein Datum da ist if (dateValue instanceof Date) return dateValue; return new Date(dateValue); } export default async function EvaluationPage({ params }: PageProps) { // get all params const resolvedParams = await params; // get amount of days to fetch const daysToFetch = Number(resolvedParams['days']) || 7; //fallback to 7 days // get the URL from the own URL (/evaluation/) const pathSegments = resolvedParams['ical-link']; let rawUrl = pathSegments.join('/'); rawUrl = decodeURIComponent(rawUrl); const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://'); // fetch the file const response = await fetch(icalUrl, { next: { revalidate: 3600 } }); if (!response.ok) { return
Fehler beim Laden der Kalenderdaten. Status: {response.status}
; } const icalData = await response.text(); const parsedData = ical.sync.parseICS(icalData); // calculate range of time const now = new Date(); const cutoffDate = new Date(); cutoffDate.setDate(now.getDate() - daysToFetch); // filter and sort data (needed: "VEVENT"; time range) const events = Object.values(parsedData) .filter((item): item is VEvent => item !== undefined && item.type === 'VEVENT') .filter((event) => { const startDate = getIcalDate(event.start); return startDate >= cutoffDate && startDate <= now; }) .sort((a, b) => getIcalDate(b.start).getTime() - getIcalDate(a.start).getTime()); // newest first return (

Meine Kalender-Events

{events.length === 0 ? (

Keine Termine gefunden.

) : ( )}
); }