Skip to content

Commit 1754159

Browse files
Refactored filter selection code
1 parent c51da7f commit 1754159

File tree

21 files changed

+257
-145
lines changed

21 files changed

+257
-145
lines changed

client/src/actions/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
HANDLE_SIGN_IN_ERROR,
66
LOAD_FILTER_PRODUCTS,
77
LOAD_FILTER_ATTRIBUTES,
8-
SAVE_QUERY_STATUS,
98
SHIPPING_ADDRESS_CONFIRMED,
109
PAYMENT_INFO_CONFIRMED,
1110
PAYMENT_RESPONSE,
@@ -296,8 +295,6 @@ export const loadFilterAttributes = filterQuery => async dispatch => {
296295
if (response != null) {
297296
log.trace(`[ACTION]: Filter = ${JSON.stringify(response.data)}`)
298297

299-
const extractRequiredParams = filterQuery.slice(3)
300-
301298
dispatch({
302299
type: LOAD_FILTER_ATTRIBUTES,
303300
payload: JSON.parse(JSON.stringify(
@@ -307,11 +304,6 @@ export const loadFilterAttributes = filterQuery => async dispatch => {
307304
}))
308305
});
309306

310-
dispatch({
311-
type: SAVE_QUERY_STATUS,
312-
payload: extractRequiredParams
313-
});
314-
315307
return JSON.parse(JSON.stringify(response.data))
316308
} else {
317309
log.info(`[ACTION]: unable to fetch response for Filter API`)

client/src/actions/types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export const LOAD_TABS_DATA = "LOAD_TABS_DATA";
2020

2121
export const REMOVE_FILTER_ATTRIBUTES = "REMOVE_FILTER_ATTRIBUTES";
2222
export const SELECT_SORT_CATEGORY = "SELECT_SORT_CATEGORY";
23+
export const RESET_SELECT_SORT_CATEGORY = "RESET_SELECT_SORT_CATEGORY";
2324
export const SELECT_PRODUCT_PAGE = "SELECT_PRODUCT_PAGE";
25+
export const RESET_SELECT_PRODUCT_PAGE = "RESET_SELECT_PRODUCT_PAGE";
2426
export const SELECT_PRODUCT_DETAIL = "SELECT_PRODUCT_DETAIL";
2527
export const ADD_TO_CART = "ADD_TO_CART";
2628
export const RESET_ADD_TO_CART = "RESET_ADD_TO_CART";
@@ -30,8 +32,10 @@ export const DELIVERY_CHARGES = "DELIVERY_CHARGES";
3032
export const RESET_DELIVERY_CHARGES = "RESET_DELIVERY_CHARGES";
3133

3234
export const SAVE_QUERY_STATUS = "SAVE_QUERY_STATUS";
35+
export const RESET_QUERY_STATUS = "RESET_QUERY_STATUS";
3336
export const ADD_SELECTED_CATEGORY = "ADD_SELECTED_CATEGORY";
3437
export const REMOVE_SELECTED_CATEGORY = "REMOVE_SELECTED_CATEGORY";
38+
export const RESET_SELECTED_CATEGORY = "RESET_SELECTED_CATEGORY";
3539
export const SAVE_SORT_LIST = "SAVE_SORT_LIST";
3640
export const SHIPPING_ADDRESS_CONFIRMED = "SHIPPING_ADDRESS_CONFIRMED";
3741
export const RESET_SHIPPING_ADDRESS = "RESET_SHIPPING_ADDRESS";

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ import AccordionDetails from '@material-ui/core/AccordionDetails';
66
import Typography from '@material-ui/core/Typography';
77
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
88
import {Link} from "react-router-dom";
9-
import {useSelector} from "react-redux";
9+
import {useDispatch, useSelector} from "react-redux";
1010
import {TAB_CONFIG} from "../../../constants/constants";
1111
import log from "loglevel";
1212
import {PRODUCTS_ROUTE} from "../../../constants/react_routes";
13+
import {
14+
RESET_QUERY_STATUS,
15+
RESET_SELECT_PRODUCT_PAGE,
16+
RESET_SELECT_SORT_CATEGORY,
17+
RESET_SELECTED_CATEGORY
18+
} from "../../../actions/types";
1319

1420
const height = 48
1521

@@ -63,12 +69,24 @@ const useStyles = makeStyles((theme) => ({
6369
export default function AccordionSection() {
6470
const classes = useStyles();
6571
const tabsAPIData = useSelector(state => state.tabsDataReducer)
72+
const dispatch = useDispatch()
73+
74+
const handleLinkClick = () => {
75+
[RESET_SELECTED_CATEGORY,
76+
RESET_SELECT_PRODUCT_PAGE,
77+
RESET_SELECT_SORT_CATEGORY,
78+
RESET_QUERY_STATUS].forEach(type => {
79+
dispatch({
80+
type: type
81+
})
82+
})
83+
}
6684

6785
const renderContent = (contentList, mapKey, queryParam) => {
6886
return contentList.map(({id, value}) => {
6987
return (
7088
<Grid item key={`${mapKey}${id}`}>
71-
<Link to={`${PRODUCTS_ROUTE}?q=${queryParam}=${id}`}>
89+
<Link onClick={handleLinkClick} to={`${PRODUCTS_ROUTE}?q=${queryParam}=${id}`}>
7290
<Typography className={classes.content}>
7391
{value}
7492
</Typography>

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Autocomplete from '@material-ui/lab/Autocomplete';
44
import CloseIcon from '@material-ui/icons/Close';
55
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
66
import {Grid} from "@material-ui/core";
7-
import SearchIcon from '@material-ui/icons/Search';
87
import log from 'loglevel';
98
import {connect, useSelector} from "react-redux";
109
import {getSearchSuggestions, getDataViaAPI} from "../../../actions";
@@ -19,7 +18,7 @@ export const useSearchBarStyles = makeStyles((theme) => ({
1918
height: 250
2019
},
2120
listbox: {
22-
maxHeight: 290,
21+
maxHeight: 240,
2322
},
2423
option: {
2524
[theme.breakpoints.down("xs")]: {
@@ -64,25 +63,19 @@ function SearchBar(props) {
6463
if (queryLink) {
6564
setIsLoading(true)
6665
props.getDataViaAPI(LOAD_FILTER_PRODUCTS,
67-
PRODUCT_BY_CATEGORY_DATA_API + queryLink)
66+
`${PRODUCT_BY_CATEGORY_DATA_API}?q=${queryLink}`)
6867
}
6968
}
7069
}
7170

7271
const handleClose = () => {
73-
log.info(`selectedValue------2 ===== ${selectedValue}`)
7472
let finalSelectedValue = selectedValue
7573
if (!selectedValue) {
7674
finalSelectedValue = getSearchKeyword()
7775
}
7876
searchKeyword(finalSelectedValue)
7977
}
8078

81-
const onSearchBtnClick = () => {
82-
searchKeyword(getSearchKeyword())
83-
props.handleClose()
84-
}
85-
8679
const renderDesktopTextField = (params) => {
8780
return <TextField {...params} label="Search for products, brands and more" variant="outlined"/>
8881
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ const FilterChips = () => {
9494
[attributeName]: {
9595
id: selectedAttrList[i].id,
9696
value: selectedAttrList[i].value
97-
}
97+
},
98+
newQuery: null
9899
}
99100
})
100101
return

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import log from 'loglevel';
33
import {useDispatch, useSelector} from "react-redux";
44
import {SELECT_SORT_CATEGORY} from "../../../actions/types";
55
import DropdownSection from "../../ui/dropDown";
6+
import {SORT_ATTRIBUTE} from "../../../constants/constants";
67

78
export default function FilterDropdown() {
89
const dispatch = useDispatch()
910
const sortList = useSelector(state => state.filterAttributesReducer?
10-
state.filterAttributesReducer.sorts : null)
11+
state.filterAttributesReducer[SORT_ATTRIBUTE] : null)
1112
const selectedSortValue = useSelector(state => state.selectSortReducer)
1213

1314
if (!sortList) {
@@ -19,12 +20,13 @@ export default function FilterDropdown() {
1920
dispatch({
2021
type: SELECT_SORT_CATEGORY,
2122
payload: {
22-
id, value
23+
id, value,
24+
isLoadedFromURL: false
2325
}
2426
})
2527
}
2628

27-
log.info(`[FilterDropdown] Rendering FilterDropdown Component selectedSortValue = ${selectedSortValue}`)
29+
log.info(`[FilterDropdown] Rendering FilterDropdown Component selectedSortValue = ${JSON.stringify(selectedSortValue)}`)
2830

2931
return (
3032
<DropdownSection

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default function FilterPagination() {
1818
type: SELECT_PRODUCT_PAGE,
1919
payload: {
2020
pageNumber: page,
21-
maxProducts: MAX_PRODUCTS_PER_PAGE
21+
maxProducts: MAX_PRODUCTS_PER_PAGE,
22+
isLoadedFromURL: false
2223
}
2324
})
2425
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export default function ApparelCheckBox() {
4040
payload: {
4141
apparels: {
4242
id, value
43-
}
43+
},
44+
newQuery: null
4445
}
4546
})
4647
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export default function BrandCheckBox() {
4040
payload: {
4141
brands: {
4242
id, value
43-
}
43+
},
44+
newQuery: null
4445
}
4546
})
4647
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import log from 'loglevel';
33
import {useDispatch, useSelector} from "react-redux";
44
import {REMOVE_SELECTED_CATEGORY} from "../../../../actions/types";
5-
import history from "../../../../history";
65

76
function ClearAllButton() {
87
const dispatch = useDispatch()
@@ -20,7 +19,7 @@ function ClearAllButton() {
2019
*/
2120
const handleClearAllClick = () => {
2221
log.info(`[ClearAllButton] handleClearAllClick(value)`)
23-
dispatch({type: REMOVE_SELECTED_CATEGORY, payload: history.location.search.slice(3)})
22+
dispatch({type: REMOVE_SELECTED_CATEGORY})
2423
}
2524

2625
log.info(`[ClearAllButton] Rendering ClearAllButton Component`)

0 commit comments

Comments
 (0)