AntAlmanac icon indicating copy to clipboard operation
AntAlmanac copied to clipboard

ICS Download: Duplicate events for Custom Events

Open calejvaldez opened this issue 5 months ago • 0 comments

Summary

I noticed as I was testing #1004 that when I download and import custom events, I get a lot of duplicate events. If I select 5 days out of the week, I get 5 copies of the same event on the days I select.

image

image

Console Logs

I looked into it more and noticed this in the code when I added console.log(event) after if (event.isCustomEvent) {, I found this. My assumption is that because there are multiple events all with the same customEventID that are going to get the recurrence rule added later on in the code, we get multiple events.

image

Attempted Solution

I tried to solve this by ensuring there are only unique customEventIDs in the array.

/**
 * Ensures there's only unique CustomEvents.customEventIDs
 */
function removeDuplicateCustomEventIds(events: (CourseEvent | CustomEvent)[]): (CourseEvent | CustomEvent)[] {
    let customCalendarIds: number[] = [];

    return events.filter(value => {
        if (!value.isCustomEvent) {
            return value;
        }

        if (!customCalendarIds.includes(value.customEventID)) {
            customCalendarIds.push(value.customEventID);
            return value;
        }
        
    })
}

export function getEventsFromCourses(
    events = removeDuplicateCustomEventIds(AppStore.getEventsWithFinalsInCalendar()),

Although this solved the issue, I feel like there's a better way to figure this out. I'm not familiar enough with the code base to figure it out at the moment though.

calejvaldez avatar Sep 17 '24 11:09 calejvaldez