Skip to content

Commit

Permalink
Update Courses.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Dec 29, 2024
1 parent a41146e commit 6b6b7ee
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions frontend/src/pages/Courses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ const Courses: React.FC<{
const [semFilter, setSemFilter] = useState<string | null>(null);
const [codeFilter, setCodeFilter] = useState<NameAndCode | null>(null);
const [profFilter, setProfFilter] = useState<ProfType | null>(null);
const [filteredCourses, setFilteredCourses] = useState<CourseType[] | null>(
null
);
const [filteredCourses, setFilteredCourses] = useState<CourseType[]>([]);

const applyFilters = () => {
if (!semFilter && !codeFilter && !profFilter) {
/* No filters chosen */
setFilteredCourses(null);
setFilteredCourses([]);
return;
}
if (courseList) {
Expand Down Expand Up @@ -188,47 +186,38 @@ const Courses: React.FC<{
All filters are optional but you have to set atleast one of the three.
</Typography>
<SortBox
sortableData={filteredCourses ?? []}
sortableData={filteredCourses}
setSortableData={setFilteredCourses}
/>
<Typography variant="h5" color="secondary" gutterBottom>
Reviews
</Typography>
{filteredCourses ? (
filteredCourses.length <= 0 ? (
<Typography
variant="body2"
color="text.primary"
sx={{ fontStyle: 'italic' }}
{filteredCourses.length > 0 ? (
filteredCourses.map((course, index) => (
<ReviewBox
key={index}
title={`[${course.code}] ${course.name} (${course.sem})`}
endpoint={`/courses/reviews/${course.sem}/${course.code}`}
initExpanded={filteredCourses.length < 10}
>
No match found for given filters.
</Typography>
) : (
filteredCourses.map((course, index) => (
<ReviewBox
key={index}
title={`[${course.code}] ${course.name} (${course.sem})`}
endpoint={`/courses/reviews/${course.sem}/${course.code}`}
initExpanded={filteredCourses.length < 10}
>
{course.profs.map((email) => {
const prof = profMap.get(email);
return prof ? (
<Typography variant="body1" color="text.primary" key={email}>
{prof.name} &lt;{email}&gt;
</Typography>
) : null;
})}
</ReviewBox>
))
)
{course.profs.map((email) => {
const prof = profMap.get(email);
return prof ? (
<Typography variant="body1" color="text.primary" key={email}>
{prof.name} &lt;{email}&gt;
</Typography>
) : null;
})}
</ReviewBox>
))
) : (
<Typography
variant="body2"
color="text.primary"
sx={{ fontStyle: 'italic' }}
>
Hit search after choosing your filter(s).
No matches found, make sure to hit the search button after picking the
filter(s).
</Typography>
)}
</Container>
Expand Down

0 comments on commit 6b6b7ee

Please sign in to comment.