Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update search functionality for exact matches #129

Merged
merged 7 commits into from
Nov 19, 2023
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions frontend/src/components/CourseSearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ const CoursePage = () => {

const coursesToShow: string[] = useMemo(() => {
if (page === 1 && exactResultsCourses.length > 0) {
return [
...exactResultsCourses,
...pageCourses.filter(
(courseID) => !exactResultsCourses.includes(courseID)
),
];
const filteredCourses = pageCourses.filter(
(courseID) => !exactResultsCourses.includes(courseID)
);

if(pageCourses.includes(exactResultsCourses[0])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since filteredCourses is only required in the if case, let's try and optimize this by moving the filteredCourses inside the if case. It might be expensive to compute filteredCourses.

return [...exactResultsCourses, ...filteredCourses];
} else {
return pageCourses;
}

} else {
return pageCourses;
}
Expand Down
Loading