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 // Copy SUMMARY
// const startDate = vevent.startDate; newEvent.updatePropertyWithValue('summary', vevent.summary.trim());
// const endDate = vevent.endDate;
// // Create new ICAL.Time objects for start and end dates // Copy DTSTART and DTEND
// const startTime = new ICAL.Time({ newEvent.updatePropertyWithValue('dtstart', vevent.startDate);
// year: startDate.year, newEvent.updatePropertyWithValue('dtend', vevent.endDate);
// 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 Recurrence Rules (RRULE) and Recurrence ID
// year: endDate.year, const rrule = event.getFirstPropertyValue('rrule');
// month: endDate.month, if (rrule) newEvent.updatePropertyWithValue('rrule', rrule);
// 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 recurrenceId = event.getFirstPropertyValue('recurrence-id');
// const dtstampProperty = event.getFirstProperty('dtstamp'); if (recurrenceId) newEvent.updatePropertyWithValue('recurrence-id', recurrenceId);
// const dtstamp = dtstampProperty ? dtstampProperty.getFirstValue() : null;
// // Add properties to the new event // Add the VEVENT to the calendar
// newEvent.updatePropertyWithValue('uid', vevent.uid); calendarComponent.addSubcomponent(newEvent);
// if (dtstamp) { });
// 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 console.log(`Processed VEVENT components for calendar: ${result.name}`);
// newEvent.updatePropertyWithValue('dtstart', startTime); } catch (error) {
// newEvent.updatePropertyWithValue('dtend', endTime);
// newEvent.updatePropertyWithValue('summary', vevent.summary.trim());
// // Add the new event to the calendar component
// calendarComponent.addSubcomponent(newEvent);
// });
// // Log the added events for debugging
// console.log('Added events:', calendarComponent.toString());
} catch (error) {
console.error('Error processing calendar data:', error.message); console.error('Error processing calendar data:', error.message);
} }
}); });