From 3dd7e1a9853c0de9d4a3d64ace6440ee6808a694 Mon Sep 17 00:00:00 2001 From: Camille Moussu <66134347+Eriikah@users.noreply.github.com> Date: Tue, 23 Sep 2025 12:33:08 +0200 Subject: [PATCH] [#133] added dl event button (#134) Co-authored-by: Camille Moussu --- public/.env.example.js | 1 + src/features/Events/EventApi.ts | 7 ++++++ src/features/Events/EventDisplayPreview.tsx | 26 +++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/public/.env.example.js b/public/.env.example.js index c719c19..4a32816 100644 --- a/public/.env.example.js +++ b/public/.env.example.js @@ -7,3 +7,4 @@ var SSO_CODE_CHALLENGE_METHOD = "S256"; var SSO_POST_LOGOUT_REDIRECT = "http://example.com?logout=1"; var CALENDAR_BASE_URL = "https://calendar.example.com"; var MAIL_SPA_URL = "https://mail.example.com"; +var DEBUG = false; diff --git a/src/features/Events/EventApi.ts b/src/features/Events/EventApi.ts index e7a616b..7a6186a 100644 --- a/src/features/Events/EventApi.ts +++ b/src/features/Events/EventApi.ts @@ -16,6 +16,13 @@ export async function getEvent(event: CalendarEvent) { return { ...eventjson, ...event }; } +export async function dlEvent(event: CalendarEvent) { + const response = await api.get(`dav${event.URL}?export=`); + const eventData = await response.text(); + + return eventData; +} + export async function putEvent(event: CalendarEvent, calOwnerEmail?: string) { const response = await api(`dav${event.URL}`, { method: "PUT", diff --git a/src/features/Events/EventDisplayPreview.tsx b/src/features/Events/EventDisplayPreview.tsx index 7ecdb23..09b9c44 100644 --- a/src/features/Events/EventDisplayPreview.tsx +++ b/src/features/Events/EventDisplayPreview.tsx @@ -30,16 +30,17 @@ import VideocamIcon from "@mui/icons-material/Videocam"; import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline"; import CircleIcon from "@mui/icons-material/Circle"; import CancelIcon from "@mui/icons-material/Cancel"; -import CheckCircleIcon from "@mui/icons-material/CheckCircle"; +import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined"; import { userAttendee } from "../User/userDataTypes"; import EventDisplayModal, { InfoRow, renderAttendeeBadge, stringAvatar, } from "./EventDisplay"; -import { getEvent } from "./EventApi"; +import { dlEvent, getEvent } from "./EventApi"; import { CalendarEvent } from "./EventsTypes"; import EventDuplication from "../../components/Event/EventDuplicate"; +import { getCalendar } from "../Calendars/CalendarApi"; export default function EventPreviewModal({ eventId, @@ -123,6 +124,27 @@ export default function EventPreviewModal({ gap: 1, }} > + {(window as any).DEBUG && ( + { + const icsContent = await dlEvent(event); + const blob = new Blob([icsContent], { + type: "text/calendar", + }); + const url = URL.createObjectURL(blob); + + const link = document.createElement("a"); + link.href = url; + link.download = `${eventId}.ics`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + }} + > + + + )} {mailSpaUrl && attendees.length > 0 && (