Skip to content

Commit

Permalink
Autofill search bar based on path
Browse files Browse the repository at this point in the history
  • Loading branch information
armans-code committed Oct 19, 2024
1 parent 58e9019 commit 08efce4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/search-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { cn } from "@/lib/utils";
import { Product } from "../db/schema";
import { searchProducts } from "../lib/actions";
import Link from "next/link";
import { useParams } from "next/navigation";

type SearchResult = Product & { href: string };

Expand All @@ -29,6 +30,16 @@ export function SearchDropdownComponent() {
search();
}, [searchTerm]);

const params = useParams();
useEffect(() => {
if (!params.product) {
const subcategory = params.subcategory;
setSearchTerm(
typeof subcategory === "string" ? subcategory.replaceAll("-", " ") : "",
);
}
}, [params]);

return (
<div className="font-sans">
<div className="relative w-full">
Expand Down

0 comments on commit 08efce4

Please sign in to comment.