organize events by day in UpcomingEvents
This commit is contained in:
@ -143,7 +143,7 @@ export function sortSingularEvents(events: SingularEvent[]) {
|
||||
compareDates(a.occurrence.start, b.occurrence.start)
|
||||
);
|
||||
}
|
||||
interface EventsByDate {
|
||||
interface EventCalendar {
|
||||
[yearMonth: string]: {
|
||||
[week: string]: {
|
||||
[day: string]: SingularEvent[];
|
||||
@ -151,10 +151,12 @@ interface EventsByDate {
|
||||
};
|
||||
}
|
||||
|
||||
export function organizeEventsByDate(events: SingularEvent[]): EventsByDate {
|
||||
export function organizeEventsInCalendar(
|
||||
events: SingularEvent[]
|
||||
): EventCalendar {
|
||||
const sortedEvents = sortSingularEvents(events);
|
||||
|
||||
const eventsByDate: EventsByDate = {};
|
||||
const calendar: EventCalendar = {};
|
||||
|
||||
const minDate = new Date(sortedEvents[0]?.occurrence.start);
|
||||
const maxDate = new Date(
|
||||
@ -170,16 +172,16 @@ export function organizeEventsByDate(events: SingularEvent[]): EventsByDate {
|
||||
end: endOfWeek(currentDate, { weekStartsOn: 1 }),
|
||||
});
|
||||
|
||||
if (!eventsByDate[yearMonth]) {
|
||||
eventsByDate[yearMonth] = {};
|
||||
if (!calendar[yearMonth]) {
|
||||
calendar[yearMonth] = {};
|
||||
}
|
||||
if (!eventsByDate[yearMonth][week]) {
|
||||
eventsByDate[yearMonth][week] = {};
|
||||
if (!calendar[yearMonth][week]) {
|
||||
calendar[yearMonth][week] = {};
|
||||
}
|
||||
daysOfWeek.forEach((day) => {
|
||||
const formattedDay = formatDate(day, "yyyy-MM-dd");
|
||||
if (!eventsByDate[yearMonth][week][formattedDay]) {
|
||||
eventsByDate[yearMonth][week][formattedDay] = [];
|
||||
if (!calendar[yearMonth][week][formattedDay]) {
|
||||
calendar[yearMonth][week][formattedDay] = [];
|
||||
}
|
||||
});
|
||||
|
||||
@ -191,7 +193,27 @@ export function organizeEventsByDate(events: SingularEvent[]): EventsByDate {
|
||||
const yearMonth = formatDate(start, "yyyy-MM");
|
||||
const week = formatDate(start, "w");
|
||||
const day = formatDate(start, "yyyy-MM-dd");
|
||||
eventsByDate[yearMonth][week][day].push(event);
|
||||
calendar[yearMonth][week][day].push(event);
|
||||
});
|
||||
|
||||
return calendar;
|
||||
}
|
||||
|
||||
interface EventsByDate {
|
||||
[day: string]: SingularEvent[];
|
||||
}
|
||||
|
||||
export function organizeEventsByDate(events: SingularEvent[]): EventsByDate {
|
||||
const sortedEvents = sortSingularEvents(events);
|
||||
const eventsByDate: EventsByDate = {};
|
||||
|
||||
sortedEvents.forEach((event) => {
|
||||
const start = toLocalTime(event.occurrence.start);
|
||||
const day = formatDate(start, "yyyy-MM-dd");
|
||||
if (!eventsByDate[day]) {
|
||||
eventsByDate[day] = [];
|
||||
}
|
||||
eventsByDate[day].push(event);
|
||||
});
|
||||
|
||||
return eventsByDate;
|
||||
|
Reference in New Issue
Block a user