From c2ecbe7ab227342171d2f5e1027d3a028b63012c Mon Sep 17 00:00:00 2001 From: Kobe Date: Sun, 24 Nov 2024 12:23:47 -0500 Subject: [PATCH] adding index to filtering logic --- packages/frontend/components/Plan/Plan.tsx | 2 ++ packages/frontend/components/Plan/ScheduleTerm.tsx | 10 ++++++++-- packages/frontend/components/Plan/ScheduleYear.tsx | 1 + packages/frontend/utils/plan/removeCourseFromTerm.ts | 6 +++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/frontend/components/Plan/Plan.tsx b/packages/frontend/components/Plan/Plan.tsx index 46d5d892d..a17ee6609 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 394ae9135..889ce8360 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 ab70f3b87..fcd7bcf56 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 6fbb39394..0e87f8d4d 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)) ); });