Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICS Download: Duplicate events for Custom Events #1005

Open
calejvaldez opened this issue Sep 17, 2024 · 0 comments
Open

ICS Download: Duplicate events for Custom Events #1005

calejvaldez opened this issue Sep 17, 2024 · 0 comments

Comments

@calejvaldez
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant