Skip to content

Commit fd77412

Browse files
Merge pull request #224 from CodeChefVIT/staging
Staging
2 parents 178ec0a + 6343c61 commit fd77412

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/components/Searchbar/searchbar-child.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Search } from "lucide-react";
55
import { useRouter } from "next/navigation";
66
import { Input } from "@/components/ui/input";
77
import Fuse from "fuse.js";
8+
import axios from "axios";
89

910
function SearchBarChild({
1011
initialSubjects,
@@ -19,7 +20,18 @@ function SearchBarChild({
1920
const suggestionsRef = useRef<HTMLUListElement | null>(null);
2021
const fuzzy = new Fuse(initialSubjects);
2122

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>) => {
2335
const text = e.target.value;
2436
setSearchText(text);
2537

@@ -62,7 +74,7 @@ function SearchBarChild({
6274
}, []);
6375

6476
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">
6678
<form
6779
onSubmit={(e) => {
6880
e.preventDefault();
@@ -78,7 +90,7 @@ function SearchBarChild({
7890
value={searchText}
7991
onChange={handleSearchChange}
8092
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" : ""}`}
8294
/>
8395
<button
8496
type="submit"

0 commit comments

Comments
 (0)