From 45e572388b22fe89c84c4f741ce55feee6243d3a Mon Sep 17 00:00:00 2001 From: Piotr Janosz Date: Wed, 17 Jul 2019 18:27:11 +0200 Subject: [PATCH] [WIP] Tweak search: removed unnecessary code --- .../components/docs/search/autocomplete.tsx | 114 +----------------- 1 file changed, 3 insertions(+), 111 deletions(-) diff --git a/packages/website/ts/components/docs/search/autocomplete.tsx b/packages/website/ts/components/docs/search/autocomplete.tsx index 47d48b71d6..97b68a8b20 100644 --- a/packages/website/ts/components/docs/search/autocomplete.tsx +++ b/packages/website/ts/components/docs/search/autocomplete.tsx @@ -3,7 +3,7 @@ import styled from 'styled-components'; // import Autocomplete from 'react-autocomplete'; import Autosuggest from 'react-autosuggest'; -import { Highlight, Hits, Snippet } from 'react-instantsearch-dom'; +import { Highlight, Snippet } from 'react-instantsearch-dom'; import { colors } from 'ts/style/colors'; @@ -11,11 +11,6 @@ interface Props { isHome?: boolean; } -// interface ToolsHit { -// objectID: string; -// title: string; -// } - interface AutoCompleteProps { isHome?: boolean; hits?: object[]; @@ -27,27 +22,6 @@ interface HitProps { [key: string]: any; } -interface AutosuggestThemeClasses { - [key: string]: any; -} - -const theme: AutosuggestThemeClasses = { - container: 'react-autosuggest__container', - containerOpen: 'react-autosuggest__container--open', - input: 'react-autosuggest__input', - inputOpen: 'react-autosuggest__input--open', - inputFocused: 'react-autosuggest__input--focused', - suggestionsContainer: 'react-autosuggest__suggestions-container', - suggestionsContainerOpen: 'react-autosuggest__suggestions-container--open', - suggestionsList: 'react-autosuggest__suggestions-list', - suggestion: 'react-autosuggest__suggestion', - suggestionFirst: 'react-autosuggest__suggestion--first', - suggestionHighlighted: 'react-autosuggest__suggestion--highlighted', - sectionContainer: 'react-autosuggest__section-container', - sectionContainerFirst: 'react-autosuggest__section-container--first', - sectionTitle: 'react-autosuggest__section-title', -}; - export const CustomAutoComplete: React.FC = ({ isHome = false, hits = [], @@ -56,15 +30,9 @@ export const CustomAutoComplete: React.FC = ({ }) => { const [value, setValue] = useState(''); - const onChange = (event: HitProps, { newValue }: HitProps): void => { - console.log('set newValue', newValue); - setValue(newValue); - }; + const onChange = (event: HitProps, { newValue }: HitProps): void => setValue(newValue); - const onSuggestionsFetchRequested = ({ value }: HitProps): void => { - console.log('value', value); - refine(value); - }; + const onSuggestionsFetchRequested = ({ value: newValue }: HitProps): void => refine(newValue); const onSuggestionsClearRequested = (): void => refine(''); @@ -107,7 +75,6 @@ export const CustomAutoComplete: React.FC = ({ return ( ` } } `; - -// import React, { Component } from 'react'; -// import PropTypes from 'prop-types'; -// import { Highlight, connectAutoComplete } from 'react-instantsearch-dom'; -// import AutoSuggest from 'react-autosuggest'; - -// class AutoComplete extends Component { -// static propTypes = { -// hits: PropTypes.arrayOf(PropTypes.object).isRequired, -// currentRefinement: PropTypes.string.isRequired, -// refine: PropTypes.func.isRequired, -// onSuggestionSelected: PropTypes.func.isRequired, -// onSuggestionCleared: PropTypes.func.isRequired, -// }; - -// state = { -// // @ts-ignore -// value: this.props.currentRefinement, -// }; -// // @ts-ignore -// onChange = (_, { newValue }) => { -// if (!newValue) { -// // @ts-ignore -// // this.props.onSuggestionCleared(); -// } - -// this.setState({ -// value: newValue, -// }); -// }; -// // @ts-ignore -// onSuggestionsFetchRequested = ({ value }) => { -// // @ts-ignore -// this.props.refine(value); -// }; - -// onSuggestionsClearRequested = () => { -// // @ts-ignore -// this.props.refine(); -// }; -// // @ts-ignore -// getSuggestionValue(hit) { -// return hit.title; -// } -// // @ts-ignore -// renderSuggestion(hit) { -// return ; -// } - -// render() { -// // @ts-ignore -// const { hits, onSuggestionSelected } = this.props; -// const { value } = this.state; - -// const inputProps = { -// placeholder: 'Search for a product...', -// onChange: this.onChange, -// value, -// }; - -// return ( -// -// ); -// } -// } - -// export default connectAutoComplete(AutoComplete);