globus/src/components/RepositorySearchInput.tsx

32 lines
890 B
TypeScript
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useContext } from 'react'
import { RepositorySearchContext } from '../context/RepositorySearchContext'
export default function RepositorySearchInput () {
const context = useContext(RepositorySearchContext)
return (
<div>
<label htmlFor="keyword-input">
<input type="text" id="keyword-input"
value={context.keyword}
onChange={({ target }) => {
context.setKeyword(target.value)
}}
onKeyDown={evt => {
const value = (evt.target as HTMLInputElement).value
if (evt.key.toLocaleLowerCase() === 'enter') {
context.setKeyword(value)
context.search(value, 1)
}
}}
/>
</label>
<button onClick={() => {
context.search(context.keyword, 1)
}} disabled={context.loading}></button>
</div>
)
}