Skip to content

Commit

Permalink
adding index to filtering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeZ123 committed Nov 24, 2024
1 parent d12454e commit c2ecbe7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/frontend/components/Plan/Plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ export const Plan: React.FC<PlanProps> = ({

const removeCourseFromTermInCurrPlan = (
course: ScheduleCourse2<unknown>,
courseIndex: number,
termYear: number,
termSeason: SeasonEnum
) => {
const updatedPlan = removeCourseFromTerm(
course,
courseIndex,
termYear,
termSeason,
plan
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/components/Plan/ScheduleTerm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ScheduleTermProps {
/** Function to remove a course from a given term in the plan being displayed. */
removeCourseFromTermInCurrPlan: (
course: ScheduleCourse2<unknown>,
courseIndex: number,
termYear: number,
termSeason: SeasonEnum
) => void;
Expand Down Expand Up @@ -72,13 +73,18 @@ export const ScheduleTerm: React.FC<ScheduleTermProps> = ({
season={scheduleTerm.season}
credits={totalCreditsInTerm(scheduleTerm)}
/>
{scheduleTerm.classes.map((scheduleCourse) => (
{scheduleTerm.classes.map((scheduleCourse, courseIndex) => (
<DraggableScheduleCourse
coReqErr={termCoReqErr?.[courseToString(scheduleCourse)]}
preReqErr={termPreReqErr?.[courseToString(scheduleCourse)]}
scheduleCourse={scheduleCourse}
removeCourse={(course: ScheduleCourse2<unknown>) =>
removeCourseFromTermInCurrPlan(course, yearNum, scheduleTerm.season)
removeCourseFromTermInCurrPlan(
course,
courseIndex,
yearNum,
scheduleTerm.season
)
}
isEditable
key={scheduleCourse.id}
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/components/Plan/ScheduleYear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>,
courseIndex: number,
termYear: number,
termSeason: SeasonEnum
) => void;
Expand Down
6 changes: 5 additions & 1 deletion packages/frontend/utils/plan/removeCourseFromTerm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { findTerm } from "./findTerm";
*/
export const removeCourseFromTerm = (
courseToRemove: ScheduleCourse2<unknown>,
courseToRemoveIndex: number,
termYear: number,
termSeason: SeasonEnum,
plan: PlanModel<string>
Expand All @@ -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))
);
});

Expand Down

0 comments on commit c2ecbe7

Please sign in to comment.