Skip to content

Commit 2f6963d

Browse files
NavvneetKAryawart-kathpal
authored andcommitted
fix: handle empty coursesToMajors in Courses component (#412)
This pull request updates the rendering logic for the courses table in `app/[locale]/academics/curricula/page.tsx`. The main improvement is ensuring that courses with no associated majors are still displayed in the table, preventing them from being omitted. Rendering improvements: * Courses that have no entries in `coursesToMajors` are now rendered as a single row with just their `code` and `title`, ensuring all courses are shown in the table. ([app/[locale]/academics/curricula/page.tsxL93-R102](diffhunk://#diff-f28e90cdfc2124ecddf73b3a9d4522b6270d42112fa9b8a81c67656ed7722c86L93-R102)) * The mapping logic for rendering table rows has been refactored to handle the case where `coursesToMajors` is empty, improving code readability and correctness. ([app/[locale]/academics/curricula/page.tsxL116-R124](diffhunk://#diff-f28e90cdfc2124ecddf73b3a9d4522b6270d42112fa9b8a81c67656ed7722c86L116-R124))
1 parent 5d9560b commit 2f6963d

File tree

1 file changed

+11
-3
lines changed
  • app/[locale]/academics/curricula

1 file changed

+11
-3
lines changed

app/[locale]/academics/curricula/page.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,16 @@ const Courses = async ({ page }: { page: number }) => {
9090

9191
console.log(courses);
9292

93-
return courses.map(({ code, coursesToMajors, title }) =>
94-
coursesToMajors.map(
93+
return courses.map(({ code, coursesToMajors, title }) => {
94+
if (coursesToMajors.length === 0) {
95+
return (
96+
<TableRow key={code}>
97+
<TableCell>{code}</TableCell>
98+
<TableCell>{title}</TableCell>
99+
</TableRow>
100+
);
101+
}
102+
return coursesToMajors.map(
95103
({ lectureCredits, practicalCredits, tutorialCredits, major }, index) => (
96104
<TableRow key={index}>
97105
<TableCell>{code}</TableCell>
@@ -113,5 +121,5 @@ const Courses = async ({ page }: { page: number }) => {
113121
</TableRow>
114122
)
115123
)
116-
);
124+
});
117125
};

0 commit comments

Comments
 (0)