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:
@@ -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
|
* 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 {
|
export class CourseSchedule {
|
||||||
meetings: CourseMeeting[] = [];
|
meetings: CourseMeeting[];
|
||||||
|
|
||||||
constructor(courseSchedule?: Serialized<CourseSchedule>) {
|
constructor(courseSchedule?: Serialized<CourseSchedule>) {
|
||||||
if (!courseSchedule) {
|
if (!courseSchedule) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object.assign(this, courseSchedule);
|
Object.assign(this, courseSchedule);
|
||||||
|
this.meetings = [];
|
||||||
|
for (let meeting of courseSchedule.meetings) {
|
||||||
|
this.meetings.push(new CourseMeeting(meeting));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,24 +10,14 @@ export class UserSchedule {
|
|||||||
name: string;
|
name: string;
|
||||||
hours: number;
|
hours: number;
|
||||||
|
|
||||||
constructor(schedule: Serialized<UserSchedule>);
|
constructor(schedule: Serialized<UserSchedule>) {
|
||||||
constructor(courses: Course[], name: string, hours: number);
|
this.courses = schedule.courses.map(c => new Course(c));
|
||||||
constructor(coursesOrSchedule: Course[] | Serialized<UserSchedule>, name?: string, hours?: number) {
|
this.name = schedule.name;
|
||||||
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;
|
this.hours = 0;
|
||||||
if (this.courses && this.courses.length > 0) {
|
|
||||||
for (const course of this.courses) {
|
for (const course of this.courses) {
|
||||||
this.hours += course.creditHours;
|
this.hours += course.creditHours;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
containsCourse(course: Course): boolean {
|
containsCourse(course: Course): boolean {
|
||||||
return this.courses.some(c => c.uniqueId === course.uniqueId);
|
return this.courses.some(c => c.uniqueId === course.uniqueId);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default function Calendar(): JSX.Element {
|
|||||||
Check CalendarGrid.tsx and AccountForCourseConflicts for an example */}
|
Check CalendarGrid.tsx and AccountForCourseConflicts for an example */}
|
||||||
{course ? (
|
{course ? (
|
||||||
<CourseCatalogInjectedPopup
|
<CourseCatalogInjectedPopup
|
||||||
course={ExampleCourse}
|
course={course}
|
||||||
activeSchedule={activeSchedule}
|
activeSchedule={activeSchedule}
|
||||||
onClose={() => setCourse(null)}
|
onClose={() => setCourse(null)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -57,7 +57,11 @@ export function useFlattenedCourseSchedule(): FlattenedCourseSchedule {
|
|||||||
if (!activeSchedule) {
|
if (!activeSchedule) {
|
||||||
return {
|
return {
|
||||||
courseCells: [] as CalendarGridCourse[],
|
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;
|
} satisfies FlattenedCourseSchedule;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,13 +141,11 @@ function processAsyncCourses({
|
|||||||
/**
|
/**
|
||||||
* Function to process each in-person class into its distinct meeting objects for calendar grid
|
* Function to process each in-person class into its distinct meeting objects for calendar grid
|
||||||
*/
|
*/
|
||||||
function processInPersonMeetings(
|
function processInPersonMeetings(meeting: CourseMeeting, { courseDeptAndInstr, status, course }) {
|
||||||
{ days, startTime, endTime, location }: CourseMeeting,
|
const { days, startTime, endTime, location } = meeting;
|
||||||
{ courseDeptAndInstr, status, course }
|
|
||||||
) {
|
|
||||||
const midnightIndex = 1440;
|
const midnightIndex = 1440;
|
||||||
const normalizingTimeFactor = 720;
|
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'}`;
|
const timeAndLocation = `${time} - ${location ? location.building : 'WB'}`;
|
||||||
let normalizedStartTime = startTime >= midnightIndex ? startTime - normalizingTimeFactor : startTime;
|
let normalizedStartTime = startTime >= midnightIndex ? startTime - normalizingTimeFactor : startTime;
|
||||||
let normalizedEndTime = endTime >= midnightIndex ? endTime - normalizingTimeFactor : endTime;
|
let normalizedEndTime = endTime >= midnightIndex ? endTime - normalizingTimeFactor : endTime;
|
||||||
@@ -181,54 +183,3 @@ function sortCourses(a: CalendarGridCourse, b: CalendarGridCourse): number {
|
|||||||
}
|
}
|
||||||
return endIndexA - endIndexB;
|
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;
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user