Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

6 changes: 5 additions & 1 deletion src/shared/types/CourseSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import { CourseMeeting, DAY_MAP } from './CourseMeeting';
* This represents the schedule for a course, which includes all the meeting times for the course, as well as helper functions for parsing, serializing, and deserializing the schedule
*/
export class CourseSchedule {
meetings: CourseMeeting[] = [];
meetings: CourseMeeting[];

constructor(courseSchedule?: Serialized<CourseSchedule>) {
if (!courseSchedule) {
return;
}
Object.assign(this, courseSchedule);
this.meetings = [];
for (let meeting of courseSchedule.meetings) {
this.meetings.push(new CourseMeeting(meeting));
}
}

/**
Expand Down
22 changes: 6 additions & 16 deletions src/shared/types/UserSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,12 @@ export class UserSchedule {
name: string;
hours: number;

constructor(schedule: Serialized<UserSchedule>);
constructor(courses: Course[], name: string, hours: number);
constructor(coursesOrSchedule: Course[] | Serialized<UserSchedule>, name?: string, hours?: number) {
if (Array.isArray(coursesOrSchedule)) {
this.courses = coursesOrSchedule;
this.name = name || '';
this.hours = hours || 0;
} else {
this.courses = coursesOrSchedule?.courses.map(c => new Course(c)) || [];
this.name = coursesOrSchedule?.name || 'new schedule';
this.hours = 0;
if (this.courses && this.courses.length > 0) {
for (const course of this.courses) {
this.hours += course.creditHours;
}
}
constructor(schedule: Serialized<UserSchedule>) {
this.courses = schedule.courses.map(c => new Course(c));
this.name = schedule.name;
this.hours = 0;
for (const course of this.courses) {
this.hours += course.creditHours;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/components/calendar/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
/>
Expand Down
65 changes: 8 additions & 57 deletions src/views/hooks/useFlattenedCourseSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Loading