Skip to content

Commit 2121495

Browse files
added search-suggestion request on search selection
1 parent 825d262 commit 2121495

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

client/src/actions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export const sendPaymentToken = (token) => async dispatch => {
253253
}
254254

255255

256-
export const getDataViaAPI = (type, uri) => async dispatch => {
256+
export const getDataViaAPI = (type, uri, subsequent_request) => async dispatch => {
257257
log.info(`[ACTION]: invokeAndDispatchAPIData Calling API = ${uri}.`)
258258

259259
if (uri) {

client/src/components/routes/navbar/searchBar.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useRef, useState} from 'react';
1+
import React, {useState} from 'react';
22
import TextField from '@material-ui/core/TextField';
33
import Autocomplete from '@material-ui/lab/Autocomplete';
44
import CloseIcon from '@material-ui/icons/Close';
@@ -7,8 +7,10 @@ import {Grid} from "@material-ui/core";
77
import SearchIcon from '@material-ui/icons/Search';
88
import log from 'loglevel';
99
import {connect, useSelector} from "react-redux";
10-
import {getSearchSuggestions} from "../../../actions";
10+
import {getSearchSuggestions, getDataViaAPI} from "../../../actions";
1111
import {makeStyles} from "@material-ui/core/styles";
12+
import {LOAD_FILTER_PRODUCTS} from "../../../actions/types";
13+
import {PRODUCT_BY_CATEGORY_DATA_API} from "../../../constants/api_routes";
1214

1315
export const useSearchBarStyles = makeStyles(() => ({
1416
paper: {
@@ -23,17 +25,25 @@ function SearchBar(props) {
2325
const [value, setValue] = useState(null);
2426
const searchSuggestions = useSelector(state => state.searchKeywordReducer)
2527
const classes = useSearchBarStyles()
26-
const textFieldRef = useRef(null)
28+
let selectedValue = null
2729

2830
const handleClose = (event, reason) => {
2931
if (props.handleClose) {
3032
props.handleClose();
3133
}
3234

3335
// search is selected
34-
if(reason === "select-option") {
36+
if(reason === "select-option" && selectedValue != null) {
3537
log.info("Search is selected.... value = "
36-
+ event.target.getAttributeNames())
38+
+ selectedValue)
39+
for(let index = 0; index < searchSuggestions.data.length; ++index) {
40+
if(searchSuggestions.data[index].keyword.length === selectedValue.length
41+
&& searchSuggestions.data[index].keyword.localeCompare(selectedValue) === 0) {
42+
props.getDataViaAPI(LOAD_FILTER_PRODUCTS,
43+
PRODUCT_BY_CATEGORY_DATA_API + searchSuggestions.data[index].link)
44+
return
45+
}
46+
}
3747
}
3848
}
3949

@@ -58,6 +68,7 @@ function SearchBar(props) {
5868
}
5969

6070
const handleInputChange = (event, newValue) => {
71+
selectedValue = newValue
6172
props.getSearchSuggestions(newValue)
6273
}
6374

@@ -87,8 +98,6 @@ function SearchBar(props) {
8798
selectOnFocus
8899
clearOnBlur
89100
handleHomeEndKeys
90-
ref={textFieldRef}
91-
open
92101
closeIcon={<CloseIcon/>}
93102
id="free-solo"
94103
options={searchSuggestions.data}
@@ -117,4 +126,4 @@ function SearchBar(props) {
117126
);
118127
}
119128

120-
export default connect(null, {getSearchSuggestions})(SearchBar);
129+
export default connect(null, {getSearchSuggestions, getDataViaAPI})(SearchBar);

0 commit comments

Comments
 (0)