Skip to content

Commit

Permalink
chore(ethereum#6392): types for Search
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkhielseath committed Jul 16, 2022
1 parent 5225803 commit 38ac628
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/components/Search/Input.js → src/components/Search/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import React, { ChangeEvent, FormEvent } from "react"
import { useIntl } from "gatsby-plugin-intl"
import styled from "styled-components"
import { connectSearchBox } from "react-instantsearch-dom"
Expand Down Expand Up @@ -57,17 +57,31 @@ const SearchSlash = styled.p`
}
`

const Input = ({ query, setQuery, refine, inputRef, ...rest }) => {
interface IInputProps {
query: string
setQuery: (arg: string) => void
refine: (arg: string) => void
inputRef: React.MutableRefObject<HTMLInputElement>
[key: string]: unknown
}

const Input: React.FC<IInputProps> = ({
query,
setQuery,
refine,
inputRef,
...rest
}) => {
const intl = useIntl()
const searchString = translateMessageId("search", intl)

const handleInputChange = (event) => {
const handleInputChange = (event: ChangeEvent<HTMLInputElement>): void => {
const value = event.target.value
refine(value)
setQuery(value)
}

const handleSubmit = (event) => {
const handleSubmit = (event: FormEvent<HTMLFormElement>): void => {
event.preventDefault()
}

Expand Down
16 changes: 12 additions & 4 deletions src/components/Search/index.js → src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,18 @@ const Results = connectStateResults(
}
)

const Search = ({ handleSearchSelect, useKeyboardShortcuts }) => {
interface ISearchProps {
handleSearchSelect: () => void
useKeyboardShortcuts: boolean
}

const Search: React.FC<ISearchProps> = ({
handleSearchSelect,
useKeyboardShortcuts,
}) => {
const intl = useIntl()
const containerRef = useRef()
const inputRef = useRef()
const containerRef = useRef<HTMLDivElement>()
const inputRef = useRef<HTMLInputElement>()
const [query, setQuery] = useState(``)
const [focus, setFocus] = useState(false)
const algoliaClient = algoliasearch(
Expand Down Expand Up @@ -235,7 +243,7 @@ const Search = ({ handleSearchSelect, useKeyboardShortcuts }) => {
}
}

const focusSearch = (event) => {
const focusSearch = (event: KeyboardEvent) => {
if (!useKeyboardShortcuts) {
return
}
Expand Down

0 comments on commit 38ac628

Please sign in to comment.