From b00e5c853d925dd279f7508f3ee0d4701b960237 Mon Sep 17 00:00:00 2001 From: Dennis Wang <66754085+hellolol2016@users.noreply.github.com> Date: Sun, 22 Sep 2024 16:39:01 -0400 Subject: [PATCH] changed totalcreditsinschedule function to take in transfer credit courses and calculate everything transferred the calculation logic into the totalcreditsinschedule function --- .../frontend/components/Sidebar/Sidebar.tsx | 17 ++++++----------- packages/frontend/utils/plan/totalCredits.ts | 15 +++++++++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/frontend/components/Sidebar/Sidebar.tsx b/packages/frontend/components/Sidebar/Sidebar.tsx index dc339102a..ae32e7044 100644 --- a/packages/frontend/components/Sidebar/Sidebar.tsx +++ b/packages/frontend/components/Sidebar/Sidebar.tsx @@ -190,14 +190,11 @@ const Sidebar: React.FC = memo( concentrationValidationStatus = SidebarValidationStatus.Error; } - const transferCredits = transferCourses.reduce( - (sum, course) => course.numCreditsMin + sum, - 0 + const creditsTaken = totalCreditsInSchedule( + selectedPlan.schedule, + transferCourses ); - const creditsTaken = - totalCreditsInSchedule(selectedPlan.schedule) + transferCredits; - return ( = ({ selectedPlan, transferCourses, }) => { - const transferCredits = transferCourses.reduce( - (sum, course) => course.numCreditsMin + sum, - 0 + const creditsTaken = totalCreditsInSchedule( + selectedPlan.schedule, + transferCourses ); - const creditsTaken = - totalCreditsInSchedule(selectedPlan.schedule) + transferCredits; return ( ): number => { @@ -23,12 +28,14 @@ export const totalCreditsInYear = ( /** The credits for all courses in a schedule summed. */ export const totalCreditsInSchedule = ( - schedule: Schedule2 + schedule: Schedule2, + transfer: ScheduleCourse2[] ): number => { return ( - schedule.years.reduce( + (schedule.years.reduce( (totalCredits, year) => totalCreditsInYear(year) + totalCredits, 0 - ) ?? 0 + ) ?? 0) + + (transfer.reduce((sum, course) => course.numCreditsMin + sum, 0) ?? 0) ); };