File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
apps/web/src/app/_components/search Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 1
1
"use client" ;
2
2
3
+ import { useCallback } from "react" ;
4
+ import { usePathname , useRouter , useSearchParams } from "next/navigation" ;
3
5
import { zodResolver } from "@hookform/resolvers/zod" ;
4
6
import { useForm } from "react-hook-form" ;
5
7
import { z } from "zod" ;
@@ -22,10 +24,24 @@ export default function SearchFilter() {
22
24
} ,
23
25
} ) ;
24
26
25
- function onSubmit ( values : z . infer < typeof formSchema > ) {
26
- //value is user's search info
27
+ const searchParams = useSearchParams ( ) ! ;
28
+ const router = useRouter ( ) ;
29
+ const pathName = usePathname ( ) ;
27
30
28
- console . log ( values ) ;
31
+ const createQueryString = useCallback (
32
+ ( name : string , value : string ) => {
33
+ const params = new URLSearchParams ( searchParams ) ;
34
+ params . set ( name , value ) ;
35
+ return params . toString ( ) ;
36
+ } ,
37
+ [ searchParams ] ,
38
+ ) ;
39
+
40
+ function onSubmit ( values : z . infer < typeof formSchema > ) {
41
+ // console.log(searchParams.get("search")); query the user search info
42
+ router . push (
43
+ pathName + `/?${ createQueryString ( "search" , values . searchText ) } ` ,
44
+ ) ;
29
45
}
30
46
31
47
return (
Original file line number Diff line number Diff line change 1
1
import type { TRPCRouterRecord } from "@trpc/server" ;
2
+ import Fuse from "fuse.js" ;
2
3
import { z } from "zod" ;
3
4
4
5
import { desc , eq } from "@cooper/db" ;
You can’t perform that action at this time.
0 commit comments