Updated search input

This commit is contained in:
2025-09-02 17:44:00 +02:00
parent 6b7c3814d8
commit b3d7f2b46b

View File

@@ -5,6 +5,7 @@ import { cn } from "@/lib/utils"
import { Search } from "lucide-react" import { Search } from "lucide-react"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { useState } from "react" import { useState } from "react"
import { Button } from "./ui/button"
export function SearchBar({ navbar }: { navbar?: boolean }) { export function SearchBar({ navbar }: { navbar?: boolean }) {
const [input, setInput] = useState("") const [input, setInput] = useState("")
@@ -13,14 +14,6 @@ export function SearchBar({ navbar }: { navbar?: boolean }) {
async function handleSearch(e: React.FormEvent) { async function handleSearch(e: React.FormEvent) {
e.preventDefault() e.preventDefault()
// const validatedPlayer = await validatePlayer(input.trim())
//
// if (validatedPlayer.error === true) {
// toast.error(validatedPlayer.message)
// setInput("")
// return
// }
if (input.trim()) { if (input.trim()) {
router.push(`/player/${encodeURIComponent(input.trim())}`) router.push(`/player/${encodeURIComponent(input.trim())}`)
} }
@@ -29,25 +22,25 @@ export function SearchBar({ navbar }: { navbar?: boolean }) {
} }
} }
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter") {
handleSearch(e)
}
}
return ( return (
<div className={cn("w-full max-w-4xl px-4", !navbar && "mt-8")}> <div className={cn("w-full max-w-4xl px-4", !navbar && "mt-8")}>
<form onSubmit={handleSearch}> <form onSubmit={handleSearch}>
<div className="relative"> <div className="flex gap-2">
<Search className="absolute left-3 top-1/2 w-4 h-4 transform -translate-y-1/2 text-muted-foreground" />
<Input <Input
type="text" type="text"
placeholder={!navbar ? "Search for a player..." : ""} placeholder={!navbar ? "Search for a player..." : ""}
className="pl-10" className="px-5"
value={input} value={input}
onChange={(e) => setInput(e.target.value)} onChange={(e) => setInput(e.target.value)}
onKeyDown={handleKeyDown} onKeyDown={(e) => {
if (e.key === "Enter") {
handleSearch(e)
}
}}
/> />
<Button type="submit">
<Search />
</Button>
</div> </div>
</form> </form>
</div> </div>