Feat/evaluation #1

Merged
robin merged 15 commits from feat/evaluation into main 2026-08-03 16:46:56 +00:00
Showing only changes of commit 176602d9bb - Show all commits
@@ -1,6 +1,7 @@
import ical, { VEvent } from 'node-ical';
interface PageProps {
params: Promise<{
'days': number
'ical-link': string[];
}>;
}
@@ -19,8 +20,13 @@ function getIcalDate(dateValue: any): Date {
}
export default async function EvaluationPage({ params }: PageProps) {
// get the URL from the own URL (/evaluation/<ics-link>)
// 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/<ics-link>)
const pathSegments = resolvedParams['ical-link'];
let rawUrl = pathSegments.join('/');
rawUrl = decodeURIComponent(rawUrl);
@@ -35,12 +41,19 @@ export default async function EvaluationPage({ params }: PageProps) {
const icalData = await response.text();
const parsedData = ical.sync.parseICS(icalData);
// filter data (needed: "VEVENT")
const events = Object.values(parsedData).filter(
(item): item is VEvent => item !== undefined && item.type === 'VEVENT'
);
// 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 (
<main style={{ padding: '2rem', fontFamily: 'sans-serif' }}>