Skip to content

Commit 4f320c6

Browse files
authored
Merge pull request #33 from arghya17/arghya
[Fix]Events were sorted in ascending order
2 parents 7a7c8e6 + 7d43ccc commit 4f320c6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/logic/events.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ 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-
return items.filter((i: any) => dayjs(i.end.dateTime).isAfter(dayjs()) && !i.recurrence)
9+
const sortedEvents = items.filter(
10+
(i: any) => dayjs(i.end.dateTime).isAfter(dayjs()) && !i.recurrence
11+
);
12+
sortedEvents.sort((a: any, b: any) =>
13+
dayjs(a.start.dateTime).isBefore(dayjs(b.start.dateTime))? -1: 1);
14+
return sortedEvents;
1015
}
1116

1217
export const formatDateTime = (dateTime: string): string => {

0 commit comments

Comments
 (0)