@@ -2,6 +2,7 @@ import { getCurrentSemester } from "@/lib/backend/audit-scraper";
22import { searchCatalogCourses } from "@/lib/backend/db" ;
33import type {
44 CatalogCourse ,
5+ Course ,
56 CourseCode ,
67 PlannedCourseOutline ,
78} from "@/lib/general-types" ;
@@ -54,11 +55,33 @@ const DEPARTMENTS = [
5455 "History" ,
5556] ;
5657
58+ // Course statuses that mean the student already has the course, so it should be
59+ // hidden from search results.
60+ const EXCLUDED_SEARCH_STATUSES = new Set < string > ( [ "Completed" , "In Progress" ] ) ;
61+
62+ // Build the set of course codes to hide from search based on the student's audit.
63+ function getExcludedCourseCodes ( courses : Course [ ] ) : Set < string > {
64+ const excludedCodes = new Set < string > ( ) ;
65+ for ( const course of courses ) {
66+ if ( EXCLUDED_SEARCH_STATUSES . has ( course . status ) ) {
67+ excludedCodes . add ( course . code . trim ( ) ) ;
68+ }
69+ }
70+ return excludedCodes ;
71+ }
72+
5773async function SearchCourses (
5874 searchData : CourseSearchData ,
75+ excludeCodes ?: Set < string > ,
5976) : Promise < CatalogCourse [ ] > {
6077 // Pass the modal form data into the DB search helper and return the results.
61- return searchCatalogCourses ( searchData ) ;
78+ return searchCatalogCourses ( {
79+ searchQuery : searchData . searchQuery ,
80+ department : searchData . department ,
81+ lowerDivision : searchData . lowerDivision ,
82+ upperDivision : searchData . upperDivision ,
83+ excludeCodes,
84+ } ) ;
6285}
6386
6487function waitForNextPaint ( ) : Promise < void > {
@@ -543,6 +566,7 @@ export function CourseSearchResults({
543566}
544567
545568export function CourseSearchPanel ( ) {
569+ const { courses : studentCourses } = useAuditContext ( ) ;
546570 const [ view , setView ] = useState ( false ) ;
547571 const [ courses , setCourses ] = useState < CatalogCourse [ ] > ( [ ] ) ;
548572
@@ -551,7 +575,10 @@ export function CourseSearchPanel() {
551575 ) : (
552576 < CourseSearchContent
553577 onSearchSubmit = { async ( formData ) => {
554- const results = await SearchCourses ( formData ) ;
578+ const results = await SearchCourses (
579+ formData ,
580+ getExcludedCourseCodes ( studentCourses ) ,
581+ ) ;
555582 setCourses ( results ) ;
556583 setView ( true ) ;
557584 } }
0 commit comments