-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5ef465
commit 77f3e0d
Showing
3 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
"use client"; | ||
|
||
export const Search = () => {}; | ||
import { Input } from "@/components/ui/Input"; | ||
import { useDebouncedValue } from "foxact/use-debounced-value"; | ||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export const Search = () => { | ||
const router = useRouter(); | ||
const searchParams = useSearchParams(); | ||
const pathname = usePathname(); | ||
const [value, setValue] = useState( | ||
searchParams?.get("search")?.toString() || "", | ||
); | ||
const _debouncedValue = useDebouncedValue(value, 200); | ||
|
||
useEffect(() => { | ||
const newSearchParams = new URLSearchParams( | ||
Object.entries({ search: value }).filter(([_, value]) => value), | ||
); | ||
|
||
router.replace(`${pathname}?${newSearchParams.toString()}`, { | ||
scroll: false, | ||
}); | ||
}, [value]); | ||
|
||
return ( | ||
<Input | ||
placeholder="Search guild.xyz" | ||
size="lg" | ||
value={value} | ||
onChange={(e) => setValue(e.currentTarget.value)} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters