Skip to content

Commit

Permalink
Update Search Params through Search Bar (#84)
Browse files Browse the repository at this point in the history
* initial commit with comments

* installed fuse.js

* YIPPEE

* h

* [Fixed] Removed comments and Relocated the fuse installation
  • Loading branch information
suxls authored Oct 6, 2024
1 parent ff00668 commit b9ba9ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
23 changes: 22 additions & 1 deletion apps/web/src/app/_components/search/search-filter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import { useCallback } from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand All @@ -22,8 +24,27 @@ export default function SearchFilter() {
},
});

const searchParams = useSearchParams();
const router = useRouter();
const pathName = usePathname();

const createQueryString = useCallback(
(name: string, value: string) => {
const params = new URLSearchParams(searchParams);
params.set(name, value);
return params.toString();
},
[searchParams],
);

function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values);
if (values.searchText != "") {
router.push(
pathName + `/?${createQueryString("search", values.searchText)}`,
);
} else {
router.push(pathName);
}
}

return (
Expand Down
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@cooper/db": "workspace:*",
"@cooper/validators": "workspace:*",
"@trpc/server": "11.0.0-rc.441",
"fuse.js": "^7.0.0",
"superjson": "2.2.1",
"zod": "catalog:"
},
Expand Down
17 changes: 13 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9ba9ec

Please sign in to comment.