mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
Calendar
Calendar that show all events that we joined
This commit is contained in:
39
WebApp/ts/calendar.ts
Normal file
39
WebApp/ts/calendar.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
async function getRegisteredEvents(): Promise<any[]> {
|
||||
const res = await fetch("/api/events/registered");
|
||||
if (!res.ok) throw new Error("Couldn't load joined events");
|
||||
|
||||
const data = await res.json();
|
||||
return data.map((ev: any) => ({
|
||||
title: ev.title,
|
||||
start: ev.eventDate,
|
||||
url: `/view.html?event=${ev.eventId}`
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const calendarEl = document.getElementById("calendar") as HTMLElement;
|
||||
if (!calendarEl) return;
|
||||
|
||||
const events = await getRegisteredEvents();
|
||||
|
||||
const calendar = new (window as any).FullCalendar.Calendar(calendarEl, {
|
||||
initialView: 'dayGridMonth',
|
||||
headerToolbar: {
|
||||
left: 'prev,next today',
|
||||
center: 'title',
|
||||
right: 'dayGridMonth,timeGridWeek,listWeek'
|
||||
},
|
||||
themeSystem: 'bootstrap5',
|
||||
events: events,
|
||||
eventClick: function (info: any) {
|
||||
if (info.event.url) {
|
||||
window.location.href = info.event.url;
|
||||
info.jsEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
calendar.render();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user