From cc3a1075a01d06e82954a146785dff5bc2c0d7c0 Mon Sep 17 00:00:00 2001 From: SumanthBA Date: Fri, 13 Sep 2019 00:26:02 +0530 Subject: [PATCH] suggestion fix --- src/components/searchBar/searchBar.jsx | 8 ++++++-- src/index.jsx | 2 +- src/scripts/suggestionStringGenerator.js | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/searchBar/searchBar.jsx b/src/components/searchBar/searchBar.jsx index 25dc6bb..82548c8 100644 --- a/src/components/searchBar/searchBar.jsx +++ b/src/components/searchBar/searchBar.jsx @@ -1,6 +1,7 @@ import React,{ Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; +import { withRouter } from 'react-router-dom'; import searchBarActions from '../../actions/searchBar/searchBarActions'; import { searchIcon } from '../../assets/images/common/'; @@ -63,7 +64,8 @@ class SearchBar extends Component{ this.setState({ isFocused: false, }); - this.refs.input.blur() + this.props.history.push(`groups`); + this.refs.input.blur(); } }; @@ -82,8 +84,10 @@ class SearchBar extends Component{ }; onSuggestionClickHanlder = searchParam =>{ + console.log('search param received is ', searchParam); this.props.setSearchParam(searchParam); this.props.triggerSearch(); + this.props.history.push(`groups`); }; getSuggestionItems = (suggestionsList, searchParam) =>{ @@ -153,4 +157,4 @@ const mapDispatchToProps = dispatch =>({ setSearchParam : payload => dispatch(searchBarActions.setSearchParam(payload)), triggerSearch : () => dispatch(searchBarActions.triggerSearch()), }); -export default connect(mapStateToProps, mapDispatchToProps)(SearchBar); +export default connect(mapStateToProps, mapDispatchToProps)(withRouter(SearchBar)); diff --git a/src/index.jsx b/src/index.jsx index d71feea..d3c10b8 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -12,7 +12,7 @@ const loggerMiddleware = createLogger({ predicate: () => ({ logger: console, dif const store = createStore( allReducers, - applyMiddleware(thunk , loggerMiddleware) + applyMiddleware(thunk ) ); ReactDOM.render( diff --git a/src/scripts/suggestionStringGenerator.js b/src/scripts/suggestionStringGenerator.js index 6216154..a1dd1c5 100644 --- a/src/scripts/suggestionStringGenerator.js +++ b/src/scripts/suggestionStringGenerator.js @@ -1,6 +1,9 @@ export default { getHighlightText : (longString , shortString) =>{ const startOfSubstring = longString.indexOf(shortString); + if(startOfSubstring === -1){ + return longString + } const endOfSubstring = startOfSubstring + shortString.length; return [longString.slice(0, startOfSubstring),'', shortString,'', longString.slice(endOfSubstring)].join(''); }