-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
63 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
function SearchBarFallback() { | ||
return <div>SearchBarFallback</div>; | ||
} | ||
|
||
export default SearchBarFallback; |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use client"; | ||
|
||
import { FormEvent, useRef } from "react"; | ||
import { IoSearchOutline } from "react-icons/io5"; | ||
|
||
import useQueryParams from "@/hooks/useQueryParams"; | ||
|
||
type QueryParams = { | ||
search: string; | ||
}; | ||
|
||
function SearchBar() { | ||
const { queryParams, setQueryParams } = useQueryParams<QueryParams>(); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
async function onSubmit(e: FormEvent<HTMLFormElement>) { | ||
e.preventDefault(); | ||
|
||
const query = inputRef?.current?.value; | ||
|
||
if (!query) return; | ||
|
||
setQueryParams({ search: inputRef?.current?.value }); | ||
inputRef.current.blur(); | ||
} | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<div className="w-full sm:w-2/6 rounded-full flex items-center"> | ||
<div className="flex items-center relative"> | ||
<IoSearchOutline className="absolute ml-4 w-5 h-5" /> | ||
</div> | ||
<input | ||
className="w-full p-4 pl-12 rounded-full" | ||
placeholder="Search" | ||
defaultValue={queryParams.search} | ||
ref={inputRef} | ||
type="text" | ||
/> | ||
</div> | ||
</form> | ||
); | ||
} | ||
|
||
export default SearchBar; |
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
Oops, something went wrong.