1
1
'use client' ;
2
- import React from 'react'
2
+ import React from 'react' ;
3
3
import CourseCard from './CourseCard' ;
4
4
5
5
type Course = {
@@ -20,10 +20,13 @@ export const SearchBar = () => {
20
20
21
21
React . useEffect ( ( ) => {
22
22
// Fetch the term list
23
- fetch ( 'http://localhost:3000/api/home' ) // Fetch terms
23
+ fetch ( 'http://localhost:3000/api/home' , { cache : 'no-store' } ) // Fetch terms
24
24
. then ( ( response ) => response . json ( ) ) // turn data from promise into a json file so we can use data
25
- . then ( ( data ) => setDataList ( data ) ) // set data using setData hook
26
- . catch ( error => {
25
+ . then ( ( data ) => {
26
+ console . log ( data ) ;
27
+ setDataList ( data ) ;
28
+ } ) // set data using setData hook
29
+ . catch ( ( error ) => {
27
30
// if promise not fulfilled
28
31
console . log ( 'Error:' + `${ error . message } ` ) ;
29
32
} ) ;
@@ -33,25 +36,29 @@ export const SearchBar = () => {
33
36
item . course . courseName . toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) )
34
37
) ;
35
38
36
- const courseCards = filteredData . map ( item => {
39
+ const courseCards = filteredData . map ( ( item , idx ) => {
37
40
return (
38
- < div >
41
+ < div key = { idx } >
39
42
< CourseCard
40
- courseCode = { item . course . courseCode }
41
- courseName = { item . course . courseName }
43
+ courseCode = { item . course . courseCode }
44
+ courseName = { item . course . courseName }
42
45
/>
43
46
</ div >
44
47
) ;
45
- } )
48
+ } ) ;
46
49
47
50
return (
48
51
< div className = "justify-center" >
49
52
< div className = "px-20" >
50
- < input className = "px-3 w-full bg-white py-0.1 text-0.5xl border border-black rounded-md text-left placeholder-left" type = "text" placeholder = "search for a course..." value = { searchTerm } onChange = { e => setSearchTerm ( e . target . value ) } />
53
+ < input
54
+ className = "px-3 w-full bg-white py-0.1 text-0.5xl border border-black rounded-md text-left placeholder-left"
55
+ type = "text"
56
+ placeholder = "search for a course..."
57
+ value = { searchTerm }
58
+ onChange = { ( e ) => setSearchTerm ( e . target . value ) }
59
+ />
51
60
</ div >
52
- < ul className = "flex flex-wrap justify-center" >
53
- { courseCards }
54
- </ ul >
61
+ < ul className = "flex flex-wrap justify-center" > { courseCards } </ ul >
55
62
</ div >
56
- )
57
- }
63
+ ) ;
64
+ } ;
0 commit comments