@@ -7,9 +7,10 @@ function CourseSearchForm() {
7
7
// Create signals for each form input
8
8
const [ courseName , setCourseName ] = createSignal ( "" ) ;
9
9
const [ year , setYear ] = createSignal < number > ( 0 ) ;
10
- const [ semester , setSemester ] = createSignal ( "" ) ;
10
+ const [ exam , setExam ] = createSignal ( "" ) ;
11
11
const [ years , setYears ] = createSignal < number [ ] > ( [ ] ) ;
12
12
const [ searchResults , setSearchResults ] = createSignal < SearchResult [ ] > ( [ ] ) ;
13
+ const [ noResultsFound , setNoResultsFound ] = createSignal < boolean > ( false ) ;
13
14
14
15
async function fetchYears ( ) {
15
16
try {
@@ -29,19 +30,22 @@ function CourseSearchForm() {
29
30
const handleSubmit = async ( event : any ) => {
30
31
event . preventDefault ( ) ; // Prevent the default form submit action
31
32
32
- console . log ( "Form submitted!" , courseName ( ) , year ( ) , semester ( ) ) ;
33
+ console . log ( "Form submitted!" , courseName ( ) , year ( ) , exam ( ) ) ;
33
34
34
35
const params = new URLSearchParams ( ) ;
35
36
if ( courseName ( ) ) params . append ( "course" , courseName ( ) ) ;
36
37
if ( year ( ) ) params . append ( "year" , year ( ) . toString ( ) ) ;
37
- if ( semester ( ) ) params . append ( "semester " , semester ( ) ) ;
38
+ if ( exam ( ) ) params . append ( "exam " , exam ( ) ) ;
38
39
39
40
try {
40
41
const response = await fetch ( `${ import . meta. env . VITE_BACKEND_URL } /search?${ params } ` , {
41
42
method : "GET" , // GET request
42
43
} ) ;
44
+
43
45
const data : SearchResult [ ] = await response . json ( ) ;
46
+
44
47
setSearchResults ( data ) ; // Handle the response data
48
+ setNoResultsFound ( data . length === 0 ) ; // Show a message if no results are found
45
49
} catch ( error ) {
46
50
console . error ( "Error fetching data:" , error ) ;
47
51
}
@@ -64,16 +68,16 @@ function CourseSearchForm() {
64
68
</ select >
65
69
</ div >
66
70
< div >
67
- < label for = "semester" > Semester :</ label >
68
- < select id = "semester " value = { semester ( ) } onInput = { ( e ) => setSemester ( e . target . value ) } >
69
- < option value = "" > Select a semester </ option >
71
+ < label for = "exam" > Exam :</ label >
72
+ < select id = "exam " value = { exam ( ) } onInput = { ( e ) => setExam ( e . target . value ) } >
73
+ < option value = "" > Select an exam </ option >
70
74
< option value = "Mid Sem" > Mid Sem</ option >
71
75
< option value = "End Sem" > End Sem</ option >
72
76
</ select >
73
77
</ div >
74
78
< button type = "submit" > Search</ button >
75
79
</ form >
76
- < SearchResults results = { searchResults ( ) } />
80
+ < SearchResults results = { searchResults ( ) } noResultsFound = { noResultsFound ( ) } />
77
81
</ div >
78
82
) ;
79
83
}
0 commit comments