@@ -5,6 +5,7 @@ import { Search } from "lucide-react";
5
5
import { useRouter } from "next/navigation" ;
6
6
import { Input } from "@/components/ui/input" ;
7
7
import Fuse from "fuse.js" ;
8
+ import axios from "axios" ;
8
9
9
10
function SearchBarChild ( {
10
11
initialSubjects,
@@ -19,7 +20,18 @@ function SearchBarChild({
19
20
const suggestionsRef = useRef < HTMLUListElement | null > ( null ) ;
20
21
const fuzzy = new Fuse ( initialSubjects ) ;
21
22
22
- const handleSearchChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
23
+ const fetchPaperQuantityByName = async ( subjectName : string ) => {
24
+ try {
25
+ const response = await axios . get ( "/api/papers" , {
26
+ params : { subject : subjectName } ,
27
+ } ) ;
28
+ return response . data . papers . length ;
29
+ } catch ( error ) {
30
+ return 0 ;
31
+ }
32
+ } ;
33
+
34
+ const handleSearchChange = async ( e : React . ChangeEvent < HTMLInputElement > ) => {
23
35
const text = e . target . value ;
24
36
setSearchText ( text ) ;
25
37
@@ -62,7 +74,7 @@ function SearchBarChild({
62
74
} , [ ] ) ;
63
75
64
76
return (
65
- < div className = "font-play mx-auto w-full max-w-xl" >
77
+ < div className = "mx-auto w-full max-w-xl font-play " >
66
78
< form
67
79
onSubmit = { ( e ) => {
68
80
e . preventDefault ( ) ;
@@ -78,7 +90,7 @@ function SearchBarChild({
78
90
value = { searchText }
79
91
onChange = { handleSearchChange }
80
92
placeholder = "Search by subject..."
81
- className = { `text-md font-play rounded-lg bg-[#B2B8FF] px-4 py-6 pr-10 tracking-wider text-black shadow-sm ring-0 placeholder:text-black focus:outline-none focus:ring-0 dark:bg-[#7480FF66] dark:text-white placeholder:dark:text-white ${ suggestions . length > 0 ? "rounded-b-none" : "" } ` }
93
+ className = { `text-md rounded-lg bg-[#B2B8FF] px-4 py-6 pr-10 font-play tracking-wider text-black shadow-sm ring-0 placeholder:text-black focus:outline-none focus:ring-0 dark:bg-[#7480FF66] dark:text-white placeholder:dark:text-white ${ suggestions . length > 0 ? "rounded-b-none" : "" } ` }
82
94
/>
83
95
< button
84
96
type = "submit"
0 commit comments