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: Color Changing Bug w/ Duplicate Courses #719

Merged
merged 11 commits into from
Oct 27, 2023
1 change: 0 additions & 1 deletion apps/antalmanac/src/components/Calendar/CalendarRoot.tsx
KevinWu098 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ class ScheduleCalendar extends PureComponent<ScheduleCalendarProps, ScheduleCale
return (
<div className={classes.container} style={isMobile ? { height: 'calc(100% - 50px)' } : undefined}>
<CalendarToolbar
onTakeScreenshot={this.handleTakeScreenshot}
currentScheduleIndex={this.state.currentScheduleIndex}
toggleDisplayFinalsSchedule={this.toggleDisplayFinalsSchedule}
showFinalsSchedule={this.state.showFinalsSchedule}
Expand Down
22 changes: 20 additions & 2 deletions apps/antalmanac/src/stores/Schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,30 @@ export class Schedules {
}

/**
* @return Reference of the course that matches the params
* @return Reference of a course that matches the params
*/
getExistingCourse(sectionCode: string, term: string) {
for (const course of this.getAllCourses()) {
for (const course of this.getCurrentCourses()) {
if (course.section.sectionCode === sectionCode && term === course.term) {
return course;
}
}
return undefined;
}

/**
* @return An array of references to courses that matches the params
*/
getExistingCourses(sectionCode: string, term: string) {
const courses: ScheduleCourse[] = [];
for (const course of this.getAllCourses()) {
if (course.section.sectionCode === sectionCode && term === course.term) {
courses.push(course);
}
}
return courses ?? undefined;
}

/**
* Adds a course to a given schedule index
* Sets color to an unused color in set, also will not add class if already exists
Expand Down Expand Up @@ -222,6 +235,11 @@ export class Schedules {
*/
changeCourseColor(sectionCode: string, term: string, newColor: string) {
this.addUndoState();
// const courses = this.getExistingCourses(sectionCode, term);
// for (const course of courses) {
// course.section.color = newColor;
// }

const course = this.getExistingCourse(sectionCode, term);
if (course) {
course.section.color = newColor;
Expand Down