Skip to content

Commit

Permalink
Merge pull request #783 from sandboxnu/individual-course-check
Browse files Browse the repository at this point in the history
Courses in sidebar will display a checkmark if they are present anywhere in the users plan
  • Loading branch information
KobeZ123 authored Dec 5, 2024
2 parents 068b0e3 + b8d6a34 commit f20fcb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/frontend/components/Sidebar/SectionRequirement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ interface SidebarRequirementProps {
requirement: Requirement2;
courseData: { [id: string]: ScheduleCourse2<null> };
dndIdPrefix: string;
coursesTaken: ScheduleCourse2<unknown>[];
}

const SectionRequirement: React.FC<SidebarRequirementProps> = ({
requirement,
courseData,
dndIdPrefix,
coursesTaken,
}) => {
const renderRequirement = () => {
switch (requirement.type) {
Expand All @@ -47,6 +49,21 @@ const SectionRequirement: React.FC<SidebarRequirementProps> = ({
}
};

const isCourseInPlan = (requirement: Requirement2): boolean => {
let isTrue = false;
if (coursesTaken) {
coursesTaken.forEach((course) => {
if (
requirement.type === "COURSE" &&
getCourseDisplayString(course) === getCourseDisplayString(requirement)
) {
isTrue = true;
}
});
}
return isTrue;
};

const renderXOM = (requirement: IXofManyCourse) => {
return (
<div>
Expand All @@ -57,6 +74,7 @@ const SectionRequirement: React.FC<SidebarRequirementProps> = ({
<SectionRequirement
requirement={course}
courseData={courseData}
coursesTaken={coursesTaken}
dndIdPrefix={dndIdPrefix + "-" + index}
key={index}
/>
Expand All @@ -75,6 +93,7 @@ const SectionRequirement: React.FC<SidebarRequirementProps> = ({
<SectionRequirement
requirement={course}
courseData={courseData}
coursesTaken={coursesTaken}
dndIdPrefix={dndIdPrefix + "-" + index}
key={index}
/>
Expand All @@ -93,6 +112,7 @@ const SectionRequirement: React.FC<SidebarRequirementProps> = ({
<SectionRequirement
requirement={course}
courseData={courseData}
coursesTaken={coursesTaken}
dndIdPrefix={dndIdPrefix + "-" + index}
key={index}
/>
Expand Down Expand Up @@ -130,7 +150,7 @@ const SectionRequirement: React.FC<SidebarRequirementProps> = ({
}}
isInSidebar
// TODO: isChecked is for when the requirement is added to the plan and validated. When true, this will render a checkmark.
isChecked={false}
isChecked={isCourseInPlan(requirement)}
isDisabled={false}
/>
);
Expand All @@ -145,6 +165,7 @@ const SectionRequirement: React.FC<SidebarRequirementProps> = ({
validationStatus={SidebarValidationStatus.Complete}
section={requirement}
courseData={courseData}
coursesTaken={coursesTaken}
dndIdPrefix={dndIdPrefix + "-sec"}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const Sidebar: React.FC<SidebarProps> = memo(
courseData={courseData}
dndIdPrefix={`${SIDEBAR_DND_ID_PREFIX}-${index}`}
loading={isCoursesLoading}
coursesTaken={coursesTaken}
/>
);
})}
Expand All @@ -267,6 +268,7 @@ const Sidebar: React.FC<SidebarProps> = memo(
section={concentration}
courseData={courseData}
dndIdPrefix={`${SIDEBAR_DND_ID_PREFIX}-concentration`}
coursesTaken={[]}
/>
)}
</>
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/components/Sidebar/SidebarSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface SidebarSectionProps {
courseData: { [id: string]: ScheduleCourse2<null> };
dndIdPrefix: string;
validationStatus: SidebarValidationStatus;
coursesTaken: ScheduleCourse2<unknown>[];
loading?: boolean;
}

Expand All @@ -27,6 +28,7 @@ const SidebarSection: React.FC<SidebarSectionProps> = ({
dndIdPrefix,
validationStatus,
loading,
coursesTaken,
}) => {
const [opened, setOpened] = useState(false);

Expand Down Expand Up @@ -201,6 +203,7 @@ const SidebarSection: React.FC<SidebarSectionProps> = ({
courseData={courseData}
dndIdPrefix={dndIdPrefix + "-" + index}
key={index}
coursesTaken={coursesTaken}
/>
))}
</>
Expand Down

0 comments on commit f20fcb2

Please sign in to comment.