Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JacE070 committed Dec 4, 2023
1 parent 12db2db commit 9efca46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
24 changes: 15 additions & 9 deletions apps/antalmanac/src/lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export const vTimeZoneSection =
'END:VTIMEZONE\n' +
'BEGIN:VEVENT';

export const CALENDAR_ID = 'antalmanac/ics';

export const CALENDAR_OUTPUT = 'local' as const;

/**
* @example [YEAR, MONTH, DAY, HOUR, MINUTE]
*/
Expand Down Expand Up @@ -247,9 +251,7 @@ export function getRRule(bydays: string[], quarter: string) {
return `FREQ=WEEKLY;BYDAY=${bydays.toString()};INTERVAL=1;COUNT=${count}`;
}

export function getEventsFromCourses(
events = [...AppStore.getEventsInCalendar(), ...AppStore.getFinalEventsInCalendar()]
): EventAttributes[] {
export function getEventsFromCourses(events = AppStore.getEventsWithFinalsInCalendar()): EventAttributes[] {
const calendarEvents = events.flatMap((event) => {
if (event.isCustomEvent) {
// FIXME: We don't have a way to get the term for custom events,
Expand Down Expand Up @@ -280,18 +282,22 @@ export function getEventsFromCourses(
const { term, title, courseTitle, instructors, sectionType, start, end, finalExam } = event;
const courseEvents: EventAttributes[] = event.locations
.map((location) => {
if (location.days === undefined) return null;
if (location.days === undefined) {
return null;
}
const days = getByDays(location.days);

const [finalStart, finalEnd] = getExamTime(finalExam, getYear(term));

if (sectionType === 'Fin') {
return {
productId: 'antalmanac/ics',
startOutputType: 'local' as const,
endOutputType: 'local' as const,
productId: CALENDAR_ID,
startOutputType: CALENDAR_OUTPUT,
endOutputType: CALENDAR_OUTPUT,
title: `${title} Final Exam`,
description: `Final Exam for ${courseTitle}`,
start: getExamTime(finalExam, getYear(term))[0]!,
end: getExamTime(finalExam, getYear(term))[1]!,
start: finalStart!,
end: finalEnd!,
};
} else {
const classStartDate = getClassStartDate(term, days);
Expand Down
4 changes: 4 additions & 0 deletions apps/antalmanac/src/stores/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class AppStore extends EventEmitter {
return this.schedule.getCalendarizedEvents();
}

getEventsWithFinalsInCalendar() {
return [...this.schedule.getCalendarizedEvents(), ...this.schedule.getCalendarizedFinals()];
}

getCourseEventsInCalendar() {
return this.schedule.getCalendarizedCourseEvents();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/antalmanac/src/stores/calendarizeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function calendarizeCourseEvents(currentCourses: ScheduleCourse[] = []):
locations: meeting.bldg.map(getLocation).map((location: Location) => {
return {
...location,
days: meeting.days === null ? undefined : COURSE_WEEK_DAYS[dayIndex],
...(meeting.days && { days: COURSE_WEEK_DAYS[dayIndex] }),
};
}),
showLocationInfo: false,
Expand Down

0 comments on commit 9efca46

Please sign in to comment.