import Inferno from 'inferno'; import Component from 'inferno-component'; import Helper from '../../../Helper'; import dictionary from '../../../managers/DictionaryData'; import METHOD from './SearchMethod.js'; export class SearchBox extends Component { constructor (props) { super(props); this.state = { searchingIn: 'name', searchMethod: METHOD.contains, searchTerm: '', filteredPartsOfSpeech: [], showHeader: false, showAdvanced: false, }; } componentDidUpdate(prevProps, prevState) { if (this.state.showHeader && this.searchBox) { this.searchBox.focus(); } } search () { const {searchingIn, searchMethod, searchTerm, filteredPartsOfSpeech} = this.state; const searchConfig = { searchingIn, searchMethod, searchTerm, filteredPartsOfSpeech, }; this.props.search(searchConfig); } displaySearchHeader () { if (this.state.showHeader) { return (

{ this.searchBox = input; }} value={ this.state.searchTerm } onChange={(event) => { console.log(event); this.setState({ searchTerm: event.target.value }); }} />

{ this.showFilterOptions() }
); } } showFilterOptions () { if (this.props.partsOfSpeech.length > 0) { const searchMethodSectionJSX = this.state.searchingIn !== 'details' ? (

) : null; const filterSectionJSX = (
{ this.props.partsOfSpeech.map(partOfSpeech => { return (

); }) }
); const advancedSectionJSX = (
{ searchMethodSectionJSX } { filterSectionJSX }
); return (

this.setState({ showAdvanced: !this.state.showAdvanced }) }> Advanced

{ this.state.showAdvanced ? advancedSectionJSX : null }
); } } showHeader () { this.setState({ showHeader: true, }); } hideHeader () { this.setState({ showHeader: false, }); } render () { return (

Search

{ this.displaySearchHeader() }
); } }