fix: fixed issues involving course meeting objects not being recognized as course meeting objects (#132)

* fix: coursemeeting objects now created properly. course popup works on calendar

* refactor: removed duplicated getTimeString method in useFlattenedHook

* refactor: meeting constructor

---------

Co-authored-by: Razboy20 <razboy20@gmail.com>
This commit is contained in:
Som Gupta
2024-03-09 20:21:38 -06:00
committed by GitHub
parent c51e6881d1
commit 3406e9a0e2
4 changed files with 20 additions and 75 deletions

View File

@@ -46,7 +46,7 @@ export default function Calendar(): JSX.Element {
Check CalendarGrid.tsx and AccountForCourseConflicts for an example */}
{course ? (
<CourseCatalogInjectedPopup
course={ExampleCourse}
course={course}
activeSchedule={activeSchedule}
onClose={() => setCourse(null)}
/>

View File

@@ -57,7 +57,11 @@ export function useFlattenedCourseSchedule(): FlattenedCourseSchedule {
if (!activeSchedule) {
return {
courseCells: [] as CalendarGridCourse[],
activeSchedule: new UserSchedule([], 'Something may have went wrong', 0),
activeSchedule: new UserSchedule({
courses: [],
name: 'Something may have went wrong',
hours: 0,
}),
} satisfies FlattenedCourseSchedule;
}
@@ -137,13 +141,11 @@ function processAsyncCourses({
/**
* Function to process each in-person class into its distinct meeting objects for calendar grid
*/
function processInPersonMeetings(
{ days, startTime, endTime, location }: CourseMeeting,
{ courseDeptAndInstr, status, course }
) {
function processInPersonMeetings(meeting: CourseMeeting, { courseDeptAndInstr, status, course }) {
const { days, startTime, endTime, location } = meeting;
const midnightIndex = 1440;
const normalizingTimeFactor = 720;
const time = getTimeString({ separator: '-', capitalize: true }, startTime, endTime);
const time = meeting.getTimeString({ separator: '-', capitalize: true });
const timeAndLocation = `${time} - ${location ? location.building : 'WB'}`;
let normalizedStartTime = startTime >= midnightIndex ? startTime - normalizingTimeFactor : startTime;
let normalizedEndTime = endTime >= midnightIndex ? endTime - normalizingTimeFactor : endTime;
@@ -181,54 +183,3 @@ function sortCourses(a: CalendarGridCourse, b: CalendarGridCourse): number {
}
return endIndexA - endIndexB;
}
/**
* Utility function also present in CourseMeeting object. Wasn't being found at runtime, so I copied it over.
*/
function getTimeString(options: TimeStringOptions, startTime: number, endTime: number): string {
const startHour = Math.floor(startTime / 60);
const startMinute = startTime % 60;
const endHour = Math.floor(endTime / 60);
const endMinute = endTime % 60;
let startTimeString = '';
let endTimeString = '';
if (startHour === 0) {
startTimeString = '12';
} else if (startHour > 12) {
startTimeString = `${startHour - 12}`;
} else {
startTimeString = `${startHour}`;
}
startTimeString += startMinute === 0 ? ':00' : `:${startMinute}`;
startTimeString += startHour >= 12 ? 'pm' : 'am';
if (endHour === 0) {
endTimeString = '12';
} else if (endHour > 12) {
endTimeString = `${endHour - 12}`;
} else {
endTimeString = `${endHour}`;
}
endTimeString += endMinute === 0 ? ':00' : `:${endMinute}`;
endTimeString += endHour >= 12 ? 'pm' : 'am';
if (options.capitalize) {
startTimeString = startTimeString.toUpperCase();
endTimeString = endTimeString.toUpperCase();
}
return `${startTimeString} ${options.separator} ${endTimeString}`;
}
/**
* Options to control the format of the time string
*/
type TimeStringOptions = {
/** the separator between the start and end times */
separator: string;
/** capitalizes the AM/PM */
capitalize?: boolean;
};