diff --git a/src/components/searchbar.tsx b/src/components/searchbar.tsx new file mode 100644 index 0000000..4972a09 --- /dev/null +++ b/src/components/searchbar.tsx @@ -0,0 +1,61 @@ +"use client"; + +import Link from "next/link"; +import { Search } from "lucide-react"; +import { useState } from "react"; + +import { Card, CardDescription, CardHeader } from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { useFetchSearch } from "@/hooks"; +import { cn } from "@/lib/utils"; + +const placeholderText = ["Search problem number", "Search username"]; + +const SearchBar = () => { + const [searchStr, setSearchStr] = useState(""); + const { data: searchData } = useFetchSearch(searchStr); + + return ( +
+
+
+ + setSearchStr(event.target.value)} + value={searchStr} + className="pl-8" + placeholder={placeholderText[Math.floor(Math.random() * 2)]} + /> +
+
+
+ setSearchStr("")} + className={cn( + "flex flex-col divide-y", + searchData && "ring-2 ring-ring", + )} + > + {searchData && + searchData.length > 0 && + searchData.map((cur, index) => ( + + + + {cur.title} + + + + ))} + +
+
+ ); +}; + +export default SearchBar;