Skip to content

Commit cdfceef

Browse files
edison-nguyencagdas001
edison-nguyen
authored andcommitted
changes for topcoder-archive#15
1 parent e87a3fa commit cdfceef

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

client/src/components/FiltersSideMenu/filters.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ export default function SearchTabFilters({ achievements }) {
134134
};
135135

136136
const addLocationToFilter = (location) => {
137-
const locationFilters = JSON.parse(JSON.stringify(search.selectedLocations));
137+
const locationFilters = JSON.parse(
138+
JSON.stringify(search.selectedLocations)
139+
);
138140

139141
if (locationFilters.findIndex((s) => s.id === location.id) !== -1) {
140142
return;
@@ -144,7 +146,9 @@ export default function SearchTabFilters({ achievements }) {
144146
};
145147

146148
const removeLocationFromFilter = (location) => {
147-
const locationFilters = JSON.parse(JSON.stringify(search.selectedLocations));
149+
const locationFilters = JSON.parse(
150+
JSON.stringify(search.selectedLocations)
151+
);
148152
const index = locationFilters.findIndex((s) => s.id === location.id);
149153

150154
if (index === -1) {
@@ -256,7 +260,7 @@ export default function SearchTabFilters({ achievements }) {
256260
placeholder={"Search for a location"}
257261
onSelect={addLocationToFilter}
258262
purpose="locations"
259-
companyAttrId={config.STANDARD_USER_ATTRIBUTES.location}
263+
companyAttrId={search.getAttributeId(FILTERS.LOCATIONS)}
260264
/>
261265
{search.selectedLocations.length > 0 && (
262266
<div className={utilityStyles.mt16}>

client/src/components/SuggestionBox/index.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import config from "../../config";
44
import api from "../../services/api";
55
import style from "./style.module.scss";
66
import _ from "lodash";
7+
import { useSearch, FILTERS } from "../../lib/search";
78

89
const NO_RESULTS_FOUND = "no results found";
910
const DELAY_SEARCH = 300;
@@ -95,13 +96,19 @@ export default function SuggestionBox({
9596
placeholder,
9697
onSelect,
9798
}) {
99+
const search = useSearch();
98100
const apiClient = api();
99101
const [suggestions, setSuggestions] = React.useState([]);
100102
const [value, setValue] = React.useState("");
101103

102104
const onChange = (event, { newValue }) => setValue(newValue.trim());
103105

104106
const onSuggestionsFetchRequested = async ({ value }) => {
107+
if (purpose === "locations") {
108+
if (!companyAttrId) {
109+
companyAttrId = search.getAttributeId(FILTERS.LOCATIONS);
110+
}
111+
}
105112
if (purpose === "skills") {
106113
let data = await getSkillsSuggestions(apiClient, value);
107114

client/src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ export default {
3737
clientId: process.env.REACT_APP_AUTH0_CLIENTID,
3838
audience: process.env.REACT_APP_AUTH0_AUDIENCE,
3939
},
40+
41+
REACT_APP_ATTRIBUTE_ID_LOCATION:
42+
process.env.REACT_APP_ATTRIBUTE_ID_LOCATION || "location",
4043
};

client/src/lib/search.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ function useProvideSearch() {
6666
setPopupShown(true);
6767
};
6868

69+
const getAttributeId = (filter) => {
70+
return filters[filter].id;
71+
};
72+
6973
const isFilterActive = (filter) => {
7074
return filters[filter].active;
7175
};
@@ -133,6 +137,7 @@ function useProvideSearch() {
133137
showPopup,
134138
filters,
135139
setFilters,
140+
getAttributeId,
136141
isFilterActive,
137142
activateFilter,
138143
deactivateFilter,

client/src/pages/Search/Global.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ export default function SearchGlobal({ keyword }) {
116116
group: "Company attributes",
117117
active: false,
118118
};
119+
if (companyAttr.name === config.REACT_APP_ATTRIBUTE_ID_LOCATION) {
120+
filtersWithCompanyAttrs[FILTERS.LOCATIONS].id = companyAttr.id;
121+
}
119122
});
120123

121124
if (isSubscribed) {
@@ -206,10 +209,12 @@ export default function SearchGlobal({ keyword }) {
206209
pageChanged = true;
207210
}
208211

209-
if (_.isEqual(prevCriteria, criteria)
210-
&& prevKeyword === keyword
211-
&& prevOrderBy === orderBy
212-
&& pageChanged === false) {
212+
if (
213+
_.isEqual(prevCriteria, criteria) &&
214+
prevKeyword === keyword &&
215+
prevOrderBy === orderBy &&
216+
pageChanged === false
217+
) {
213218
return;
214219
} else {
215220
setPrevCriteria(criteria);

0 commit comments

Comments
 (0)