Skip to content

Commit

Permalink
Transfer credits now add up to total credits on sidebar (#746)
Browse files Browse the repository at this point in the history
* transfer credits now add up to total credits on sidebar

* changed totalcreditsinschedule function to take in transfer credit courses and calculate everything

transferred the calculation logic into the totalcreditsinschedule function
  • Loading branch information
denniwang authored Sep 26, 2024
1 parent 429f157 commit e8ea7af
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ GraduateNU aims to empower Northeastern students to customize their plan of stud

5. Then run the new version of the application by running `yarn dev` at the root of the project. This starts up a NestJS server + a NextJS frontend + a Proxy. The proxy listens on port [3002](http://localhost:3002/), forwards /api requests to the NestJS server running on port 3001, and all other requests to the frontend running on port 3000.

5a. For Windows machines, run `yarn concurrently "yarn workspaces foreach --parallel --verbose --interlaced run dev" "yarn dev:proxy"` instead of `yarn dev`

6. Visit [http://localhost:3002](http://localhost:3002/) to view the app.

To run the two separately, visit the frontend and api packages(sub directories of the monorepo).
Expand Down
12 changes: 10 additions & 2 deletions packages/frontend/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ const Sidebar: React.FC<SidebarProps> = memo(
concentrationValidationStatus = SidebarValidationStatus.Error;
}

const creditsTaken = totalCreditsInSchedule(selectedPlan.schedule);
const creditsTaken = totalCreditsInSchedule(
selectedPlan.schedule,
transferCourses
);

return (
<SidebarContainer
Expand Down Expand Up @@ -249,12 +252,17 @@ const Sidebar: React.FC<SidebarProps> = memo(

interface NoMajorSidebarProps {
selectedPlan: PlanModel<string>;
transferCourses: ScheduleCourse2<unknown>[];
}

export const NoMajorSidebar: React.FC<NoMajorSidebarProps> = ({
selectedPlan,
transferCourses,
}) => {
const creditsTaken = totalCreditsInSchedule(selectedPlan.schedule);
const creditsTaken = totalCreditsInSchedule(
selectedPlan.schedule,
transferCourses
);
return (
<SidebarContainer
title="No Major"
Expand Down
8 changes: 7 additions & 1 deletion packages/frontend/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ const HomePage: NextPage = () => {
transferCourses={student.coursesTransfered || []}
/>
);
} else renderedSidebar = <NoMajorSidebar selectedPlan={selectedPlan} />;
} else
renderedSidebar = (
<NoMajorSidebar
selectedPlan={selectedPlan}
transferCourses={student.coursesTransfered || []}
/>
);
}

return (
Expand Down
15 changes: 11 additions & 4 deletions packages/frontend/utils/plan/totalCredits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Schedule2, ScheduleTerm2, ScheduleYear2 } from "@graduate/common";
import {
Schedule2,
ScheduleCourse2,
ScheduleTerm2,
ScheduleYear2,
} from "@graduate/common";

/** The credits for all courses in a term. */
export const totalCreditsInTerm = (term: ScheduleTerm2<unknown>): number => {
Expand All @@ -23,12 +28,14 @@ export const totalCreditsInYear = (

/** The credits for all courses in a schedule summed. */
export const totalCreditsInSchedule = (
schedule: Schedule2<unknown>
schedule: Schedule2<unknown>,
transfer: ScheduleCourse2<unknown>[]
): 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)
);
};

0 comments on commit e8ea7af

Please sign in to comment.