1
0
Fork 0

feat(calendar): copy summary, timestamps, and recurrence details for VEVENTs

This commit is contained in:
Ryan Mwangi 2024-11-18 23:49:50 +03:00
parent ddcfedbbdf
commit 6cf5b8420e
1 changed files with 24 additions and 51 deletions

View File

@ -49,65 +49,38 @@ export function addEventsToCalendar(calendarComponent, results) {
calendarComponent.addSubcomponent(timezone); calendarComponent.addSubcomponent(timezone);
} }
}); });
// Process VEVENT components
component.getAllSubcomponents('vevent').forEach((event) => {
const vevent = new ICAL.Event(event);
const newEvent = new ICAL.Component('vevent');
console.log(`Added VTIMEZONE components for calendar: ${result.name}`); // Copy UID
newEvent.updatePropertyWithValue('uid', vevent.uid);
// component.getAllSubcomponents('vevent').forEach((event) => { // Copy DTSTAMP
// const vevent = new ICAL.Event(event); const dtstamp = event.getFirstPropertyValue('dtstamp');
// const newEvent = new ICAL.Component('vevent'); if (dtstamp) newEvent.updatePropertyWithValue('dtstamp', dtstamp);
// // Use ICAL.Time to handle dates correctly
// const startDate = vevent.startDate;
// const endDate = vevent.endDate;
// // Create new ICAL.Time objects for start and end dates // Copy SUMMARY
// const startTime = new ICAL.Time({ newEvent.updatePropertyWithValue('summary', vevent.summary.trim());
// year: startDate.year,
// month: startDate.month,
// day: startDate.day,
// hour: startDate.isDate ? null : startDate.hour,
// minute: startDate.isDate ? null : startDate.minute,
// second: startDate.isDate ? null : startDate.second,
// zone: startDate.zone
// });
// startTime.isDate = startDate.isDate;
// const endTime = new ICAL.Time({ // Copy DTSTART and DTEND
// year: endDate.year, newEvent.updatePropertyWithValue('dtstart', vevent.startDate);
// month: endDate.month, newEvent.updatePropertyWithValue('dtend', vevent.endDate);
// day: endDate.day,
// hour: endDate.isDate ? null : endDate.hour,
// minute: endDate.isDate ? null : endDate.minute,
// second: endDate.isDate ? null : endDate.second,
// zone: endDate.zone
// });
// endTime.isDate = endDate.isDate;
// // Retain the existing DTSTAMP from vevent
// const dtstampProperty = event.getFirstProperty('dtstamp');
// const dtstamp = dtstampProperty ? dtstampProperty.getFirstValue() : null;
// // Add properties to the new event // Copy Recurrence Rules (RRULE) and Recurrence ID
// newEvent.updatePropertyWithValue('uid', vevent.uid); const rrule = event.getFirstPropertyValue('rrule');
// if (dtstamp) { if (rrule) newEvent.updatePropertyWithValue('rrule', rrule);
// newEvent.updatePropertyWithValue('dtstamp', dtstamp); // Retain the existing DTSTAMP
// } else {
// console.warn('DTSTAMP not found in the original event.'); // Warn if DTSTAMP is missing
// }
// // Set the dtstart and dtend properties using ICAL.Time
// newEvent.updatePropertyWithValue('dtstart', startTime);
// newEvent.updatePropertyWithValue('dtend', endTime);
// newEvent.updatePropertyWithValue('summary', vevent.summary.trim());
const recurrenceId = event.getFirstPropertyValue('recurrence-id');
if (recurrenceId) newEvent.updatePropertyWithValue('recurrence-id', recurrenceId);
// // Add the new event to the calendar component // Add the VEVENT to the calendar
// calendarComponent.addSubcomponent(newEvent); calendarComponent.addSubcomponent(newEvent);
// }); });
// // Log the added events for debugging console.log(`Processed VEVENT components for calendar: ${result.name}`);
// console.log('Added events:', calendarComponent.toString()); } catch (error) {
} catch (error) {
console.error('Error processing calendar data:', error.message); console.error('Error processing calendar data:', error.message);
} }
}); });