Skip to content

Commit 85294db

Browse files
committed
[FIX]: recurring events based on unique etags
1 parent 1c40429 commit 85294db

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/logic/events.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ const DATE_FORMAT = 'DD MMM, YYYY hh:mm A'
66
export const getEvents = async(): Promise<any> => {
77
const { data } = await axios.get(`https://www.googleapis.com/calendar/v3/calendars/5rbvb4k7c10ujfrpeboh5je074@group.calendar.google.com/events?key=${import.meta.env.VITE_CALENDAR_KEY}`)
88
const { items } = data;
9+
10+
const recurringEvents = items.filter((i:any)=> i.recurrence);
11+
12+
// get unique events based on etag
13+
const uniqueRecurringEvents = [...new Map(recurringEvents.map((i:any) => [i.etag, i])).values()];
14+
915
const sortedEvents = items.filter(
10-
(i: any) => dayjs(i.end.dateTime).isAfter(dayjs()) && !i.recurrence
16+
(i: any) => !i.recurrence && i.end && dayjs(i.end.dateTime).isAfter(dayjs())
1117
);
1218
sortedEvents.sort((a: any, b: any) =>
1319
dayjs(a.start.dateTime).isBefore(dayjs(b.start.dateTime))? -1: 1);
14-
return sortedEvents;
20+
return sortedEvents.concat(uniqueRecurringEvents);
1521
}
1622

1723
export const formatDateTime = (dateTime: string): string => {
@@ -42,4 +48,4 @@ export function sanitizeHTML(description: string): string {
4248
element.innerHTML = description
4349
let sanitizedHTML = element.innerHTML
4450
return sanitizedHTML
45-
}
51+
}

0 commit comments

Comments
 (0)