generated from acdh-oeaw/template-app-next
-
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.
feat: add SearchInput client-side component
Create new /search page which uses it to display faceted search results
- Loading branch information
1 parent
2a66a91
commit e25f7f7
Showing
2 changed files
with
43 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client"; | ||
|
||
// eslint-disable-next-line no-restricted-imports | ||
import { useRouter } from "next/navigation"; | ||
import { type ReactNode, useOptimistic } from "react"; | ||
|
||
interface SearchInputProps { | ||
value?: Array<string> | string; | ||
} | ||
|
||
export function SearchInput(props: SearchInputProps): ReactNode { | ||
const router = useRouter(); | ||
const [optimisticValue, addOptimistic] = useOptimistic( | ||
props.value, | ||
(_currentState, optimisticValue: string) => { | ||
return optimisticValue; | ||
}, | ||
); | ||
return ( | ||
<input | ||
onChange={(e) => { | ||
addOptimistic(e.target.value); | ||
router.push(`?search=${e.target.value}`); | ||
}} | ||
placeholder="Heldenplatz" | ||
type="text" | ||
value={optimisticValue} | ||
/> | ||
); | ||
} |
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