-
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.
#55: added Autocomplete with Autosugest on hero section from homepage…
… and creted style file for it
- Loading branch information
1 parent
b6b05a2
commit a7f171b
Showing
7 changed files
with
92 additions
and
53 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,11 @@ | ||
// @todo Seco - refactoring | ||
.autocomplete-search | ||
position: fixed | ||
top: 0 | ||
left: 25% | ||
z-index: 999999 | ||
width: 50% | ||
height: 100% | ||
background-color: white | ||
padding: 20px | ||
box-shadow: 0 0 100px black |
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
import React, { Component } from 'react'; | ||
import { Highlight, connectAutoComplete } from 'react-instantsearch-dom'; | ||
import AutoSuggest from 'react-autosuggest'; | ||
|
||
class Autocomplete extends Component { | ||
// @ts-ignore | ||
state = { value: this.props.currentRefinement }; | ||
|
||
onChange = (event: any, { newValue }: any) => { | ||
this.setState({ value: newValue }); | ||
}; | ||
|
||
onSuggestionsFetchRequested = ({ value }: any) => { | ||
// @ts-ignore | ||
this.props.refine(value); | ||
}; | ||
|
||
onSuggestionsClearRequested = () => { | ||
// @ts-ignore | ||
this.props.refine(); | ||
}; | ||
|
||
getSuggestionValue(hit: any) { | ||
return hit.name; | ||
} | ||
|
||
renderSuggestion(hit: any) { | ||
return <Highlight attribute="name" hit={hit} tagName="mark" />; | ||
} | ||
|
||
render() { | ||
const { hits }: any = this.props; | ||
const { value } = this.state; | ||
|
||
const inputProps = { | ||
placeholder: 'Search for a product...', | ||
onChange: this.onChange, | ||
value, | ||
}; | ||
|
||
return ( | ||
<AutoSuggest | ||
suggestions={hits} | ||
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested} | ||
onSuggestionsClearRequested={this.onSuggestionsClearRequested} | ||
getSuggestionValue={this.getSuggestionValue} | ||
renderSuggestion={this.renderSuggestion} | ||
inputProps={inputProps} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
// @ts-ignore | ||
export default connectAutoComplete(Autocomplete); |
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,20 @@ | ||
import React from 'react'; | ||
import algoliasearch from 'algoliasearch'; | ||
import { InstantSearch } from 'react-instantsearch-dom'; | ||
import Autocomplete from './Autocomplete'; | ||
|
||
const indexCommon: string | undefined = `${process.env.ALGOLIA_INDEX_NAME_COMMON}`; | ||
const client = algoliasearch(`${process.env.ALGOLIA_APP_ID}`, `${process.env.ALGOLIA_API_KEY}`); | ||
const common = client.initIndex(indexCommon); | ||
|
||
common.setSettings({ | ||
searchableAttributes: ['name', 'location', 'district', 'address', 'supplier.name', 'service.name'], | ||
}); | ||
|
||
export function AutocompleteSearch() { | ||
return ( | ||
<InstantSearch indexName={`${indexCommon}`} searchClient={client}> | ||
<Autocomplete /> | ||
</InstantSearch> | ||
); | ||
} |
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