Skip to content

Commit 8db7c99

Browse files
Added functionality to keep up all the heroku services on app startup.
1 parent 37ba919 commit 8db7c99

File tree

13 files changed

+69
-30
lines changed

13 files changed

+69
-30
lines changed

client/src/actions/index.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -354,22 +354,17 @@ export const getSearchSuggestions = (prefix) => async dispatch => {
354354

355355
}
356356

357-
export const setDefaultSearchSuggestions = () => async dispatch => {
357+
export const setDefaultSearchSuggestions = () => dispatch => {
358358
log.info(`[ACTION]: getSearchSuggestions Calling API.`)
359-
let responseError = false
360-
const response = await searchSuggestionServiceAPI.get(DEFAULT_SEARCH_SUGGESTION_API)
359+
360+
searchSuggestionServiceAPI.get(DEFAULT_SEARCH_SUGGESTION_API)
361+
.then(response => {
362+
dispatch({
363+
type: SEARCH_KEYWORD, payload: {data: JSON.parse(JSON.stringify(response.data))}
364+
});
365+
})
361366
.catch(err => {
362367
log.info(`[ACTION]: unable to fetch response for API = ${DEFAULT_SEARCH_SUGGESTION_API}`)
363368
dispatch({type: SEARCH_KEYWORD_ERROR});
364-
responseError = true
365369
});
366-
367-
if (responseError) {
368-
return
369-
}
370-
371-
log.debug(`[ACTION]: Data = ${JSON.parse(JSON.stringify(response.data))}.`)
372-
dispatch({
373-
type: SEARCH_KEYWORD, payload: {data: JSON.parse(JSON.stringify(response.data))}
374-
});
375370
}

client/src/components/routes/home/home.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TopCategoriesAndBrands from "./topCategoriesAndBrands";
55
import {StyledSegment, StyledDimmer} from "../../../styles/semanticUI/customStyles";
66
import {connect, useSelector} from "react-redux";
77
import {DocumentTitle} from "../../ui/documentTitle";
8-
import {getDataViaAPI} from "../../../actions";
8+
import {getDataViaAPI, setDefaultSearchSuggestions} from "../../../actions";
99
import log from 'loglevel';
1010
import {homePageDataReducer} from "../../../reducers/screens/commonScreenReducer";
1111
import HomeMenuIcons from "./homeMenuIcons";
@@ -16,6 +16,8 @@ import {LOAD_HOME_PAGE} from "../../../actions/types";
1616
import {BadRequest} from "../../ui/error/badRequest";
1717
import {HOME_PAGE_DATA_API} from "../../../constants/api_routes";
1818
import {HOME_PAGE_API_OBJECT_LEN} from "../../../constants/constants"
19+
import {authServiceAPI} from "../../../api/service_api";
20+
import axios from "axios";
1921

2022
const Home = props => {
2123
const {hover} = useSelector(state => state.tabHoverEventReducer)
@@ -25,6 +27,26 @@ const Home = props => {
2527
useEffect(() => {
2628
log.info("[Home]: component did mount.")
2729

30+
///////////////////////////////////////////////////////////
31+
// Below requests are made just to wake up all services on
32+
// Heroku so that it serves the requests quickly.
33+
// This should be removed when the app is deployed on actual server.
34+
props.setDefaultSearchSuggestions()
35+
authServiceAPI.post('/authenticate').catch(err => {})
36+
if(process.env.REACT_APP_PAYMENT_SERVICE_URL) {
37+
axios({
38+
method: 'post',
39+
url: `${process.env.REACT_APP_PAYMENT_SERVICE_URL}/payment`,
40+
headers: {
41+
'Content-Type': 'application/json',
42+
},
43+
data: "xyz"
44+
}).catch(err => {})
45+
}
46+
///////////////////////////////////////////////////////////
47+
48+
49+
2850
if(!homeAPIData.hasOwnProperty("data")) {
2951
props.getDataViaAPI(LOAD_HOME_PAGE, HOME_PAGE_DATA_API, null, false);
3052
}
@@ -75,4 +97,4 @@ const Home = props => {
7597
)
7698
}
7799

78-
export default connect(null, {getDataViaAPI})(Home);
100+
export default connect(null, {getDataViaAPI, setDefaultSearchSuggestions})(Home);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {getSearchSuggestions} from "../../../actions";
1010
import {makeStyles} from "@material-ui/core/styles";
1111
import history from "../../../history";
1212
import {PRODUCT_BY_CATEGORY_DATA_API} from "../../../constants/api_routes";
13+
import {MAX_PRODUCTS_PER_PAGE} from "../../../constants/constants";
1314

1415
export const useSearchBarStyles = makeStyles((theme) => ({
1516
paper: {
@@ -52,7 +53,7 @@ function SearchBar(props) {
5253

5354
log.info(`=======> queryLink = ${queryLink}, value = ${value}, history = ${JSON.stringify(history)}`)
5455
if (queryLink) {
55-
history.push(`${PRODUCT_BY_CATEGORY_DATA_API}?q=${queryLink}`)
56+
history.push(`${PRODUCT_BY_CATEGORY_DATA_API}?q=${queryLink}::page=0,${MAX_PRODUCTS_PER_PAGE}`)
5657
}
5758
}
5859
}

client/src/components/routes/product/filterChips.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,25 @@ const FilterChips = () => {
103103
}
104104
})
105105

106-
const {list, ids} = toggleId(selectedAttrList[i].id, selectedAttrList[i].value, selectedAttrList)
107-
history.push(updateQueryString(history, attributeName, selectedAttrList[i].id, ids))
106+
const {ids} = toggleId(selectedAttrList[i].id, selectedAttrList[i].value, selectedAttrList)
107+
let queryString = updateQueryString(history, attributeName, selectedAttrList[i].id, ids)
108+
109+
let URL = ""
110+
if(!queryString.startsWith(PRODUCT_BY_CATEGORY_DATA_API)) {
111+
URL += PRODUCT_BY_CATEGORY_DATA_API
112+
}
113+
114+
if(!queryString.startsWith(`?q=`)) {
115+
URL += `?q=`
116+
}
117+
118+
if(URL !== "") {
119+
history.push(URL + queryString)
120+
} else {
121+
history.push(queryString)
122+
}
123+
124+
108125
return
109126
}
110127
}

client/src/components/routes/product/filterDropdown.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React, {useEffect, useState} from 'react';
22
import log from 'loglevel';
3-
import {useDispatch, useSelector} from "react-redux";
4-
import {SELECT_SORT_CATEGORY} from "../../../actions/types";
3+
import {useSelector} from "react-redux";
54
import DropdownSection from "../../ui/dropDown";
6-
import {MAX_PRODUCTS_PER_PAGE, SORT_ATTRIBUTE} from "../../../constants/constants";
5+
import {SORT_ATTRIBUTE} from "../../../constants/constants";
76
import history from "../../../history";
87

98
export default function FilterDropdown() {

client/src/components/routes/product/filterPagination.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import React, {useEffect, useState} from 'react';
22
import Grid from "@material-ui/core/Grid";
33
import log from 'loglevel';
4-
import {useDispatch, useSelector} from "react-redux";
5-
import {SELECT_PRODUCT_PAGE} from "../../../actions/types";
4+
import {useSelector} from "react-redux";
65
import Pagination from "@material-ui/lab/Pagination";
76
import {MAX_PRODUCTS_PER_PAGE} from "../../../constants/constants";
8-
import {toggleId} from "../../../helper/toggleId";
97
import history from "../../../history";
10-
import {updateQueryString} from "../../../helper/updateQueryString";
118

129
export default function FilterPagination() {
1310
const selectedPage = useSelector(state => state.selectPageReducer)

client/src/components/routes/product/filterSideNavbar/apparelCheckBox.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export default function ApparelCheckBox() {
3232
setSelectedList([])
3333
}
3434
}
35+
36+
// eslint-disable-next-line
3537
}, [history.location.search])
3638

3739
// return if doesn't got anything from the server

client/src/components/routes/product/filterSideNavbar/brandCheckBox.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export default function BrandCheckBox() {
3232
setSelectedList([])
3333
}
3434
}
35+
36+
// eslint-disable-next-line
3537
}, [history.location.search])
3638

3739
// return if doesn't got anything from the server

client/src/components/routes/product/filterSideNavbar/clearAllButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import log from 'loglevel';
33
import {useDispatch, useSelector} from "react-redux";
4-
import {CLEAR_ALL_FILTERS, REMOVE_SELECTED_CATEGORY, RESET_SELECTED_CATEGORY} from "../../../../actions/types";
4+
import {CLEAR_ALL_FILTERS, RESET_SELECTED_CATEGORY} from "../../../../actions/types";
55
import history from "../../../../history";
66

77
function ClearAllButton() {

client/src/components/routes/product/filterSideNavbar/filterNavBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useState} from 'react';
1+
import React, {useEffect} from 'react';
22
import Divider from '@material-ui/core/Divider';
33
import Drawer from '@material-ui/core/Drawer';
44
import Hidden from '@material-ui/core/Hidden';
@@ -20,7 +20,7 @@ import {
2020
import {
2121
CLEAR_ALL_FILTERS,
2222
LOAD_FILTER_ATTRIBUTES, LOAD_SELECTED_CATEGORY_FROM_URL,
23-
SAVE_QUERY_STATUS, SAVE_SORT_LIST, SELECT_PRODUCT_PAGE, SELECT_SORT_CATEGORY,
23+
SAVE_SORT_LIST, SELECT_PRODUCT_PAGE, SELECT_SORT_CATEGORY,
2424
} from "../../../../actions/types";
2525
import {PRODUCTS_ROUTE} from "../../../../constants/react_routes";
2626
import {FILTER_ATTRIBUTES_API} from "../../../../constants/api_routes";

0 commit comments

Comments
 (0)