diff --git a/packages/frontend/components/Plan/Plan.tsx b/packages/frontend/components/Plan/Plan.tsx index 46d5d892..a17ee660 100644 --- a/packages/frontend/components/Plan/Plan.tsx +++ b/packages/frontend/components/Plan/Plan.tsx @@ -69,11 +69,13 @@ export const Plan: React.FC = ({ const removeCourseFromTermInCurrPlan = ( course: ScheduleCourse2, + courseIndex: number, termYear: number, termSeason: SeasonEnum ) => { const updatedPlan = removeCourseFromTerm( course, + courseIndex, termYear, termSeason, plan diff --git a/packages/frontend/components/Plan/ScheduleTerm.tsx b/packages/frontend/components/Plan/ScheduleTerm.tsx index 394ae913..889ce836 100644 --- a/packages/frontend/components/Plan/ScheduleTerm.tsx +++ b/packages/frontend/components/Plan/ScheduleTerm.tsx @@ -32,6 +32,7 @@ interface ScheduleTermProps { /** Function to remove a course from a given term in the plan being displayed. */ removeCourseFromTermInCurrPlan: ( course: ScheduleCourse2, + courseIndex: number, termYear: number, termSeason: SeasonEnum ) => void; @@ -72,13 +73,18 @@ export const ScheduleTerm: React.FC = ({ season={scheduleTerm.season} credits={totalCreditsInTerm(scheduleTerm)} /> - {scheduleTerm.classes.map((scheduleCourse) => ( + {scheduleTerm.classes.map((scheduleCourse, courseIndex) => ( ) => - removeCourseFromTermInCurrPlan(course, yearNum, scheduleTerm.season) + removeCourseFromTermInCurrPlan( + course, + courseIndex, + yearNum, + scheduleTerm.season + ) } isEditable key={scheduleCourse.id} diff --git a/packages/frontend/components/Plan/ScheduleYear.tsx b/packages/frontend/components/Plan/ScheduleYear.tsx index ab70f3b8..fcd7bcf5 100644 --- a/packages/frontend/components/Plan/ScheduleYear.tsx +++ b/packages/frontend/components/Plan/ScheduleYear.tsx @@ -32,6 +32,7 @@ interface ScheduleYearProps extends ToggleYearProps { /** Function to remove a course from a given term in the plan being displayed. */ removeCourseFromTermInCurrPlan: ( course: ScheduleCourse2, + courseIndex: number, termYear: number, termSeason: SeasonEnum ) => void; diff --git a/packages/frontend/utils/plan/removeCourseFromTerm.ts b/packages/frontend/utils/plan/removeCourseFromTerm.ts index 6fbb3939..0e87f8d4 100644 --- a/packages/frontend/utils/plan/removeCourseFromTerm.ts +++ b/packages/frontend/utils/plan/removeCourseFromTerm.ts @@ -10,6 +10,7 @@ import { findTerm } from "./findTerm"; */ export const removeCourseFromTerm = ( courseToRemove: ScheduleCourse2, + courseToRemoveIndex: number, termYear: number, termSeason: SeasonEnum, plan: PlanModel @@ -19,7 +20,10 @@ export const removeCourseFromTerm = ( // remove the course term.classes = term.classes.filter( - (course) => !isEqualCourses(course, courseToRemove) + (course, index) => + index != courseToRemoveIndex || + (index == courseToRemoveIndex && + !isEqualCourses(course, courseToRemove)) ); });