- </ClickAwayListener>;
- }
-
- componentDidMount() {
- this.setState({ value: this.props.searchValue });
- }
-
- componentWillReceiveProps(nextProps: SearchBarViewProps) {
- if (nextProps.searchValue !== this.props.searchValue) {
- this.setState({ value: nextProps.searchValue });
- }
- }
-
- componentWillUnmount() {
- clearTimeout(this.timeout);
- }
-
- getView = (currentView: string) => {
- const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue,
- searchResults, saveQuery, onSearch, navigateTo, editSavedQuery, tags } = this.props;
- switch (currentView) {
- case SearchView.AUTOCOMPLETE:
- return <SearchBarAutocompleteView
- navigateTo={navigateTo}
- searchResults={searchResults}
- searchValue={searchValue} />;
- case SearchView.ADVANCED:
- return <SearchBarAdvancedView
- onSetView={onSetView}
- saveQuery={saveQuery}
- tags={tags} />;
- default:
- return <SearchBarBasicView
- onSetView={onSetView}
- onSearch={onSearch}
- loadRecentQueries={loadRecentQueries}
- savedQueries={savedQueries}
- deleteSavedQuery={deleteSavedQuery}
- editSavedQuery={editSavedQuery} />;
- }
- }
-
- handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
- event.preventDefault();
- clearTimeout(this.timeout);
- this.props.saveRecentQuery(this.state.value);
- this.props.searchDataOnEnter(this.state.value);
- this.props.loadRecentQueries();
- }
-
- // ToDo: nie pokazywac autocomplete jezeli jestesmy w advance
- // currentView ze state.searchBar.currentView
- handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
- clearTimeout(this.timeout);
- this.setState({ value: event.target.value });
- this.timeout = window.setTimeout(
- () => this.props.onSearch(this.state.value),
- this.props.debounce || DEFAULT_SEARCH_DEBOUNCE
- );
- if (event.target.value.length > 0) {
- this.props.onSetView(SearchView.AUTOCOMPLETE);
- } else {
- this.props.onSetView(SearchView.BASIC);
- }
- }