Skip to content

Commit

Permalink
Use form for search
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Dec 27, 2023
1 parent 42b1fce commit bd0dced
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
45 changes: 23 additions & 22 deletions app/_components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@ export function SearchButton() {
const [value, setValue] = useState("");
const router = useRouter();

const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter") {
router.push(`/search?q=${value}`);
}
const handleSearch = (e: React.FormEvent) => {
e.preventDefault(); // Prevent the form from refreshing the page
router.push(`/search?q=${value}`);
};

return (
<Input
type="search"
placeholder="Search packages"
aria-label="Search packages"
labelPlacement="outside"
startContent={
<FontAwesomeIcon
className="text-default-600 dark:text-default-500"
icon={faMagnifyingGlass}
width={13}
/>
}
value={value}
onValueChange={setValue}
onKeyDown={handleKeyDown}
>
Search packages
</Input>
<form onSubmit={handleSearch}>
<Input
type="search"
placeholder="Search packages"
aria-label="Search packages"
labelPlacement="outside"
startContent={
<FontAwesomeIcon
className="text-default-600 dark:text-default-500"
icon={faMagnifyingGlass}
width={13}
/>
}
value={value}
onValueChange={setValue}
// onKeyDown={handleKeyDown}
>
Search packages
</Input>
</form>
);
}
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function middleware(request: NextRequest) {
const nonce = Buffer.from(crypto.randomUUID()).toString("base64");
const cspHeader = `
default-src 'self';
script-src 'self' 'nonce-${nonce}' 'strict-dynamic' static.cloudflareinsights.com 'unsafe-inline' ${
script-src 'self' 'nonce-${nonce}' 'strict-dynamic' static.cloudflareinsights.com ${
IS_DEV ? "'unsafe-eval'" : ""
};
style-src 'self' 'nonce-${nonce}';
Expand Down

0 comments on commit bd0dced

Please sign in to comment.