feat: fetch and read calendar
This commit is contained in:
1 parent
1b2df1912a
commit
e3072755e7
3 files changed
+100
-4
No files matched your search
@@ -1,20 +1,78 @@
|
||||
import ical, { VEvent } from 'node-ical';
|
||||
interface PageProps {
|
||||
params: Promise<{
|
||||
'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 the URL from the own URL (/evaluation/<ics-link>)
|
||||
const resolvedParams = await params;
|
||||
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 <div>Fehler beim Laden der Kalenderdaten. Status: {response.status}</div>;
|
||||
}
|
||||
|
||||
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'
|
||||
);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<p>iCal-Adresse: {icalUrl}</p>
|
||||
<main style={{ padding: '2rem', fontFamily: 'sans-serif' }}>
|
||||
<h1>Meine Kalender-Events</h1>
|
||||
|
||||
{events.length === 0 ? (
|
||||
<p>Keine Termine gefunden.</p>
|
||||
) : (
|
||||
<ul style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
||||
{events.map((event, index) => {
|
||||
const startDate = getIcalDate(event.start);
|
||||
const endDate = getIcalDate(event.end);
|
||||
|
||||
return (
|
||||
<li key={index} style={{ border: '1px solid #ccc', padding: '1rem', borderRadius: '8px' }}>
|
||||
{/* HIER WENDEN WIR DIE HILFSFUNKTION AN */}
|
||||
<h2>{getIcalText(event.summary)}</h2>
|
||||
<p>
|
||||
<strong>Start:</strong> {startDate.toLocaleString('de-DE')} <br />
|
||||
<strong>Ende:</strong> {endDate.toLocaleString('de-DE')}
|
||||
</p>
|
||||
{event.location && (
|
||||
<p><strong>Ort:</strong> {getIcalText(event.location)}</p>
|
||||
)}
|
||||
{event.description && (
|
||||
<p><strong>Beschreibung:</strong> {getIcalText(event.description)}</p>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "16.2.12",
|
||||
"node-ical": "^0.27.1",
|
||||
"react": "19.2.4",
|
||||
"react-dom": "19.2.4"
|
||||
},
|
||||
|
||||
Generated
+37
@@ -11,6 +11,9 @@ importers:
|
||||
next:
|
||||
specifier: 16.2.12
|
||||
version: 16.2.12(@babel/core@7.29.7(supports-color@7.2.0))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||
node-ical:
|
||||
specifier: ^0.27.1
|
||||
version: 0.27.1
|
||||
react:
|
||||
specifier: 19.2.4
|
||||
version: 19.2.4
|
||||
@@ -1598,6 +1601,10 @@ packages:
|
||||
resolution: {integrity: sha512-kXs9Go0cah0qHVV2v389IXQLdLCeE1xfFtjOAF+iobu0OIoG1pje8At2vMHyaPMiPMnG/LWP50twML21eMcAag==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
node-ical@0.27.1:
|
||||
resolution: {integrity: sha512-5fiKuh/h2HrWKzFt20LtRQdjtjdGfijGfDnCfdAEc++SFX9gA6sa7xwj7/BJmRfWtW/NJWBenN4tOJhg0vM3pg==}
|
||||
engines: {node: '>=22'}
|
||||
|
||||
node-releases@2.0.51:
|
||||
resolution: {integrity: sha512-wRNIrw4DmVLKQlbgOMdkMx27Wrpzes2hh5Jtbi2bjPd+4wJstWIqP5A+lscnqbm0xxmT5Bpg8Lec5ItEBwx6BQ==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -1738,6 +1745,9 @@ packages:
|
||||
resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==}
|
||||
engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
|
||||
|
||||
rrule-temporal@2.0.2:
|
||||
resolution: {integrity: sha512-pwe7+pWXKUotQgdudN8W36tFHWf8eH+FbcB5Tl4Zftb4RYpl1hnqMRapizv0s8QlOlC6GEKcVSmITurpSOVZfQ==}
|
||||
|
||||
run-parallel@1.2.0:
|
||||
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
|
||||
|
||||
@@ -1875,6 +1885,15 @@ packages:
|
||||
resolution: {integrity: sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
temporal-polyfill@1.0.2:
|
||||
resolution: {integrity: sha512-pTyp/7kfStJQbJ8YOHmcJItkxvOGCZHu3PaVgLvLnxFS7O12EPiWLElnRre/rw77z4TGZX/gvdqMXWn6ispQvA==}
|
||||
|
||||
temporal-spec@1.0.1:
|
||||
resolution: {integrity: sha512-wxVoanmDeavXie1vu2JaQ3WIc3JZnWAOYFBsJyATaVsXsycKYUflGsyBmrRSnoCpZJpwPyr38VpgSUlQ8CbFxg==}
|
||||
|
||||
temporal-utils@1.0.1:
|
||||
resolution: {integrity: sha512-HAixuesxFQIUaQk3ptX2jhfO/FsOkgVkDDMawvp6n/fkB1q6BKfs3lURw9I+pK/2e2e/q/vrLrxmeqauBoyGMQ==}
|
||||
|
||||
tinyglobby@0.2.17:
|
||||
resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
@@ -3618,6 +3637,11 @@ snapshots:
|
||||
object.entries: 1.1.9
|
||||
semver: 6.3.1
|
||||
|
||||
node-ical@0.27.1:
|
||||
dependencies:
|
||||
rrule-temporal: 2.0.2
|
||||
temporal-polyfill: 1.0.2
|
||||
|
||||
node-releases@2.0.51: {}
|
||||
|
||||
object-assign@4.1.1: {}
|
||||
@@ -3772,6 +3796,10 @@ snapshots:
|
||||
|
||||
reusify@1.1.0: {}
|
||||
|
||||
rrule-temporal@2.0.2:
|
||||
dependencies:
|
||||
temporal-spec: 1.0.1
|
||||
|
||||
run-parallel@1.2.0:
|
||||
dependencies:
|
||||
queue-microtask: 1.2.3
|
||||
@@ -3970,6 +3998,15 @@ snapshots:
|
||||
|
||||
tapable@2.3.3: {}
|
||||
|
||||
temporal-polyfill@1.0.2:
|
||||
dependencies:
|
||||
temporal-spec: 1.0.1
|
||||
temporal-utils: 1.0.1
|
||||
|
||||
temporal-spec@1.0.1: {}
|
||||
|
||||
temporal-utils@1.0.1: {}
|
||||
|
||||
tinyglobby@0.2.17:
|
||||
dependencies:
|
||||
fdir: 6.5.0(picomatch@4.0.5)
|
||||
|
||||
Reference in new issue
Block a user