Skip to content

Commit b380163

Browse files
committed
fix search bar
1 parent bdd835b commit b380163

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client';
2-
import React from 'react'
2+
import React from 'react';
33
import CourseCard from './CourseCard';
44

55
type Course = {
@@ -20,10 +20,13 @@ export const SearchBar = () => {
2020

2121
React.useEffect(() => {
2222
// 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
2424
.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) => {
2730
// if promise not fulfilled
2831
console.log('Error:' + `${error.message}`);
2932
});
@@ -33,25 +36,29 @@ export const SearchBar = () => {
3336
item.course.courseName.toLowerCase().includes(searchTerm.toLowerCase())
3437
);
3538

36-
const courseCards = filteredData.map(item => {
39+
const courseCards = filteredData.map((item, idx) => {
3740
return (
38-
<div>
41+
<div key={idx}>
3942
<CourseCard
40-
courseCode={item.course.courseCode}
41-
courseName={item.course.courseName}
43+
courseCode={item.course.courseCode}
44+
courseName={item.course.courseName}
4245
/>
4346
</div>
4447
);
45-
})
48+
});
4649

4750
return (
4851
<div className="justify-center">
4952
<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+
/>
5160
</div>
52-
<ul className="flex flex-wrap justify-center">
53-
{courseCards}
54-
</ul>
61+
<ul className="flex flex-wrap justify-center">{courseCards}</ul>
5562
</div>
56-
)
57-
}
63+
);
64+
};

0 commit comments

Comments
 (0)