Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit cfe3462

Browse files
authoredJul 26, 2020
Merge pull request #586 from topcoder-platform/issue-473
Issue #473 fixes.
2 parents 238620d + e6d66d1 commit cfe3462

File tree

5 files changed

+55
-27
lines changed

5 files changed

+55
-27
lines changed
 

‎client/src/Router.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export default function AppRouter() {
3232
right: 0,
3333
}}
3434
>
35-
<img style={{height: "120px", width: "120px" }} src={loader} alt="Loading" />
35+
<img
36+
style={{ height: "120px", width: "120px" }}
37+
src={loader}
38+
alt="Loading"
39+
/>
3640
</div>
3741
);
3842
}

‎client/src/components/Upload/Initial/style.module.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
text-underline-position: under;
5454
}
5555

56-
.label3[disabled]
57-
{
56+
.label3[disabled] {
5857
pointer-events: none;
5958
opacity: 0.7;
6059
}

‎client/src/lib/company-attributes.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// FIRST - import config from the file under src/config
22
import config from "../config";
33
import * as OrgService from "../services/user-org";
4+
import Axios from "axios";
45

56
let primaryAttributeIds = [
67
config.STANDARD_USER_ATTRIBUTES.location,
@@ -13,7 +14,7 @@ let primaryAttributeIds = [
1314
* Get the attributes associated with the company (organization)
1415
* @param {Object} apiClient The api client (you can get this from src/services/api and then call api() to get the apiClient)
1516
*/
16-
export async function getCompanyAttributes(apiClient) {
17+
export async function getCompanyAttributes(apiClient, cancelToken) {
1718
let response;
1819
let attributeGroups;
1920
let attributes = [];
@@ -25,8 +26,11 @@ export async function getCompanyAttributes(apiClient) {
2526
let url = `${config.API_URL}/attributeGroups?organizationId=${organizationId}`;
2627

2728
try {
28-
response = await apiClient.get(url);
29+
response = await apiClient.get(url, { cancelToken });
2930
} catch (error) {
31+
if (Axios.isCancel(error)) {
32+
return undefined;
33+
}
3034
console.log(error);
3135
alert(errorMessage);
3236
// TODO - handle error
@@ -45,8 +49,11 @@ export async function getCompanyAttributes(apiClient) {
4549
url = `${config.API_URL}/attributes?attributeGroupId=${attributeGroups[0].id}`;
4650

4751
try {
48-
response = await apiClient.get(url);
52+
response = await apiClient.get(url, { cancelToken });
4953
} catch (error) {
54+
if (Axios.isCancel(error)) {
55+
return undefined;
56+
}
5057
console.log(error);
5158
alert(errorMessage);
5259
// TODO - handle error

‎client/src/pages/Search/Global.jsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default function SearchGlobal({ keyword }) {
6363

6464
const prevOrderBy = usePrevious(orderBy);
6565
const [prevCriteria, setPrevCriteria] = React.useState(null);
66-
66+
const cancelTokenSource = axios.CancelToken.source();
6767
const usersPerPage = config.ITEMS_PER_PAGE;
6868

6969
React.useEffect(() => {
@@ -106,22 +106,30 @@ export default function SearchGlobal({ keyword }) {
106106
let isSubscribed = true;
107107

108108
(async () => {
109-
const companyAttrs = await getCompanyAttributes(apiClient);
109+
const companyAttrs = await getCompanyAttributes(
110+
apiClient,
111+
cancelTokenSource.token
112+
);
110113
const filtersWithCompanyAttrs = { ...searchContext.filters };
111-
companyAttrs.forEach((companyAttr) => {
112-
filtersWithCompanyAttrs[companyAttr.id] = {
113-
text: companyAttr.name,
114-
group: "Company attributes",
115-
active: false,
116-
};
117-
});
114+
if (companyAttrs) {
115+
companyAttrs.forEach((companyAttr) => {
116+
filtersWithCompanyAttrs[companyAttr.id] = {
117+
text: companyAttr.name,
118+
group: "Company attributes",
119+
active: false,
120+
};
121+
});
118122

119-
if (isSubscribed) {
120-
searchContext.setFilters(filtersWithCompanyAttrs);
123+
if (isSubscribed) {
124+
searchContext.setFilters(filtersWithCompanyAttrs);
125+
}
121126
}
122127
})();
123128

124-
return () => (isSubscribed = false);
129+
return () => {
130+
isSubscribed = false;
131+
cancelTokenSource.cancel();
132+
};
125133
// eslint-disable-next-line react-hooks/exhaustive-deps
126134
}, [isLoading, isAuthenticated, auth0User]);
127135

@@ -187,8 +195,10 @@ export default function SearchGlobal({ keyword }) {
187195
});
188196

189197
// reset first page when change orderBy or criteria
190-
if ((prevOrderBy !== "undefined" && prevOrderBy !== orderBy)
191-
|| _.isEqual(prevCriteria,criteria) === false) {
198+
if (
199+
(prevOrderBy !== "undefined" && prevOrderBy !== orderBy) ||
200+
_.isEqual(prevCriteria, criteria) === false
201+
) {
192202
searchContext.pagination.page = 1;
193203
}
194204

@@ -198,14 +208,13 @@ export default function SearchGlobal({ keyword }) {
198208
pageChanged = true;
199209
}
200210

201-
if (_.isEqual(prevCriteria,criteria) && !pageChanged) {
211+
if (_.isEqual(prevCriteria, criteria) && !pageChanged) {
202212
return;
203213
} else {
204214
setPrevCriteria(criteria);
205215
}
206216

207217
let isSubscribed = true;
208-
let source = axios.CancelToken.source();
209218

210219
(async () => {
211220
let headers;
@@ -225,7 +234,7 @@ export default function SearchGlobal({ keyword }) {
225234
try {
226235
const response = await apiClient.post(url, body, {
227236
...options,
228-
cancelToken: source.token,
237+
cancelToken: cancelTokenSource.token,
229238
});
230239

231240
headers = response.headers;
@@ -256,6 +265,7 @@ export default function SearchGlobal({ keyword }) {
256265
setTotalPages(Number(headers["x-total-pages"]));
257266
}
258267
})();
268+
259269
// eslint-disable-next-line react-hooks/exhaustive-deps
260270
}, [isLoading, isAuthenticated, keyword, orderBy, searchContext]);
261271

‎client/src/pages/Search/Groups.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import Axios from "axios";
23
import GroupsSideMenu from "../../components/GroupsSideMenu";
34
import ProfileCardGroupWrapper from "../../components/ProfileCardGroupWrapper";
45
import Pagination from "../../components/Pagination";
@@ -26,24 +27,31 @@ export default function SearchGroups() {
2627
const [totalResults, setTotalResults] = React.useState(0);
2728
const [totalPages, setTotalPages] = React.useState(0);
2829
const [creatingGroup, setCreatingGroup] = React.useState(false);
29-
30+
const cancelTokenSource = Axios.CancelToken.source();
3031
const usersPerPage = config.ITEMS_PER_PAGE;
3132

3233
React.useEffect(() => {
3334
let isSubscribed = true;
3435
setLoadingGroups(true);
3536

3637
(async () => {
37-
const groups = await groupLib.getGroups(apiClient, auth0User.nickname);
38+
const groups = await groupLib.getGroups(
39+
apiClient,
40+
auth0User.nickname,
41+
cancelTokenSource.token
42+
);
3843

39-
if (isSubscribed) {
44+
if (isSubscribed && groups) {
4045
setMyGroups(groups.myGroups);
4146
setOtherGroups(groups.otherGroups);
4247
setLoadingGroups(false);
4348
}
4449
})();
4550

46-
return () => (isSubscribed = false);
51+
return () => {
52+
isSubscribed = false;
53+
cancelTokenSource.cancel();
54+
};
4755
// eslint-disable-next-line react-hooks/exhaustive-deps
4856
}, []);
4957

0 commit comments

Comments
 (0)
This repository has been archived.