36 lines
920 B
TypeScript
Raw Normal View History

"use client";
2024-04-16 16:25:21 -04:00
import { Input } from "../../ui/input";
import { Search } from "lucide-react";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
2024-04-16 16:25:21 -04:00
export default function DashboardNavbarSearch() {
const [search, setSearch] = useState("");
const router = useRouter();
2024-04-16 16:25:21 -04:00
useEffect(() => {
const delayDebounceFn = setTimeout(() => {
if (search) {
router.push(`/dashboard?q=${search}`);
2024-04-16 16:25:21 -04:00
} else {
router.push(`/dashboard`);
2024-04-16 16:25:21 -04:00
}
}, 300);
2024-04-16 16:25:21 -04:00
return () => clearTimeout(delayDebounceFn);
}, [search]);
2024-04-16 16:25:21 -04:00
return (
<div className="relative h-9 w-44 flex items-center justify-start">
<Search className="w-4 h-4 absolute left-2 text-muted-foreground" />
<Input
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder="Search projects..."
className="pl-8"
/>
</div>
);
2024-04-16 16:25:21 -04:00
}