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

Commit 9cb00ab

Browse files
Merge pull request #86 from topcoder-platform/dev
Release 2021/04/30 - Challenge Listing fixes
2 parents a9aabd0 + fcf37a4 commit 9cb00ab

File tree

14 files changed

+314
-263
lines changed

14 files changed

+314
-263
lines changed

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the base image with Node.js
2-
FROM node:latest
2+
FROM node:10.22.1
33

44
ARG APPMODE
55
ARG APPENV

package-lock.json

+242-218
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.jsx

+16-17
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ const App = () => {
4949
return;
5050
}
5151

52-
if (location.pathname === "/earn/find/challenges") {
53-
const params = utils.url.parseUrlQuery(location.search);
54-
const toUpdate = utils.challenge.createChallengeFilter(params);
52+
//if (location.pathname === "/earn/find/challenges") {
53+
const params = utils.url.parseUrlQuery(location.search);
54+
const toUpdate = utils.challenge.createChallengeFilter(params);
5555

56-
if (!toUpdate.types) toUpdate.types = [];
57-
if (!toUpdate.tracks) toUpdate.tracks = [];
58-
if (!toUpdate.bucket) toUpdate.bucket = "";
56+
if (!toUpdate.types) toUpdate.types = [];
57+
if (!toUpdate.tracks) toUpdate.tracks = [];
58+
if (!toUpdate.bucket) toUpdate.bucket = "";
5959

60-
const updatedFilter = { ...initialChallengeFilter, ...toUpdate };
61-
const currentFilter = store.getState().filter.challenge;
62-
const diff = !_.isEqual(updatedFilter, currentFilter);
63-
if (diff) {
64-
store.dispatch(actions.filter.updateFilter(updatedFilter));
65-
}
66-
getChallengesDebounced.current(() =>
67-
store.dispatch(actions.challenges.getChallenges(updatedFilter))
68-
);
60+
const updatedFilter = { ...initialChallengeFilter, ...toUpdate };
61+
const currentFilter = store.getState().filter.challenge;
62+
const diff = !_.isEqual(updatedFilter, currentFilter);
63+
if (diff) {
64+
store.dispatch(actions.filter.updateFilter(updatedFilter));
6965
}
66+
getChallengesDebounced.current(() =>
67+
store.dispatch(actions.challenges.getChallenges(updatedFilter))
68+
);
69+
//}
7070
}, [location]);
7171

7272
useEffect(() => {
@@ -90,8 +90,7 @@ const App = () => {
9090
</aside>
9191
<div className="content">
9292
<Router>
93-
<Challenges path="/earn/find/challenges" />
94-
<NoSidebarDemo path="/earn" />
93+
<Challenges path="/earn/*" />
9594
</Router>
9695
</div>
9796
</div>

src/actions/lookup.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ async function getCommunityList() {
99
return service.getCommunityList();
1010
}
1111

12+
async function isLoggedIn() {
13+
return service.isLoggedIn();
14+
}
15+
1216
export default createActions({
1317
GET_TAGS: getTags,
1418
GET_COMMUNITY_LIST: getCommunityList,
19+
IS_LOGGED_IN: isLoggedIn,
1520
});

src/constants/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export const PAGINATION_MAX_PAGE_DISPLAY = 3;
33

44
export const NAV_MENU = {
55
"Find Work": {
6-
Gigs: "",
76
Challenges: "/earn/find/challenges",
87
},
98
};
@@ -59,7 +58,7 @@ export const SORT_ORDER = {
5958
};
6059

6160
export const SORT_BY_SORT_ORDER = {
62-
bestMatch: SORT_ORDER.DESC,
61+
// bestMatch: SORT_ORDER.DESC,
6362
updated: SORT_ORDER.DESC,
6463
"overview.totalPrizes": SORT_ORDER.DESC,
6564
name: SORT_ORDER.ASC,

src/containers/Challenges/Listing/ChallengeItem/index.jsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TagsMoreTooltip from "../tooltips/TagsMoreTooltip";
1414

1515
import "./styles.scss";
1616

17-
const ChallengeItem = ({ challenge, onClickTag, onClickTrack }) => {
17+
const ChallengeItem = ({ challenge, onClickTag, onClickTrack, isLoggedIn }) => {
1818
const totalPrizes = challenge.overview.totalPrizes;
1919
const currencySymbol = utils.challenge.getCurrencySymbol(challenge.prizeSets);
2020
const placementPrizes = utils.challenge.getPlacementPrizes(
@@ -24,6 +24,12 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack }) => {
2424
challenge.prizeSets
2525
);
2626

27+
let submissionLink = `${process.env.URL.BASE}/challenges/${challenge.id}`;
28+
29+
if (isLoggedIn && challenge.numOfSubmissions > 0) {
30+
submissionLink += "?tab=submissions";
31+
}
32+
2733
return (
2834
<div styleName="challenge-item">
2935
<div styleName="track">
@@ -69,9 +75,7 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack }) => {
6975
>
7076
<NumRegistrants numOfRegistrants={challenge.numOfRegistrants} />
7177
</a>
72-
<a
73-
href={`${process.env.URL.BASE}/challenges/${challenge.id}?tab=submissions`} // eslint-disable-line no-undef
74-
>
78+
<a href={submissionLink}>
7579
<NumSubmissions numOfSubmissions={challenge.numOfSubmissions} />
7680
</a>
7781
</div>
@@ -96,6 +100,7 @@ ChallengeItem.propTypes = {
96100
challenge: PT.shape(),
97101
onClickTag: PT.func,
98102
onClickTrack: PT.func,
103+
isLoggedIn: PT.bool,
99104
};
100105

101106
export default ChallengeItem;

src/containers/Challenges/Listing/index.jsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const Listing = ({
2626
updateFilter,
2727
bucket,
2828
sortByLabels,
29+
isLoggedIn,
30+
tags,
2931
}) => {
3032
const sortByOptions = utils.createDropdownOptions(
3133
sortByLabels,
@@ -105,13 +107,14 @@ const Listing = ({
105107
<ChallengeItem
106108
challenge={challenge}
107109
onClickTag={(tag) => {
108-
const filterChange = { search: tag };
110+
const filterChange = { tags: [tag] };
109111
updateFilter(filterChange);
110112
}}
111113
onClickTrack={(track) => {
112114
const filterChange = { tracks: [track] };
113115
updateFilter(filterChange);
114116
}}
117+
isLoggedIn={isLoggedIn}
115118
/>
116119
</div>
117120
))}
@@ -146,6 +149,7 @@ Listing.propTypes = {
146149
updateFilter: PT.func,
147150
bucket: PT.string,
148151
sortByLabels: PT.arrayOf(PT.string),
152+
isLoggedIn: PT.bool,
149153
};
150154

151155
export default Listing;

src/containers/Challenges/index.jsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect, useRef, useState } from "react";
22
import PT from "prop-types";
33
import { connect } from "react-redux";
44
import Listing from "./Listing";
@@ -26,7 +26,17 @@ const Challenges = ({
2626
recommendedChallenges,
2727
initialized,
2828
updateQuery,
29+
userLoggedIn,
30+
isLoggedIn,
31+
tags,
2932
}) => {
33+
const latestPropsRef = useRef(null);
34+
latestPropsRef.current = { userLoggedIn };
35+
36+
useEffect(() => {
37+
latestPropsRef.current.userLoggedIn();
38+
}, []);
39+
3040
const BUCKET_OPEN_FOR_REGISTRATION = constants.FILTER_BUCKETS[1];
3141
const isRecommended = recommended && bucket === BUCKET_OPEN_FOR_REGISTRATION;
3242
const sortByValue = isRecommended
@@ -75,7 +85,9 @@ const Challenges = ({
7585
updateQuery(filterChange);
7686
}}
7787
bucket={bucket}
88+
tags={tags}
7889
sortByLabels={sortByLabels}
90+
isLoggedIn={isLoggedIn}
7991
/>
8092
</>
8193
)}
@@ -98,6 +110,8 @@ Challenges.propTypes = {
98110
recommendedChallenges: PT.arrayOf(PT.shape()),
99111
initialized: PT.bool,
100112
updateQuery: PT.func,
113+
isLoggedIn: PT.bool,
114+
tags: PT.arrayOf(PT.string),
101115
};
102116

103117
const mapStateToProps = (state) => ({
@@ -114,11 +128,14 @@ const mapStateToProps = (state) => ({
114128
recommended: state.filter.challenge.recommended,
115129
recommendedChallenges: state.challenges.recommendedChallenges,
116130
initialized: state.challenges.initialized,
131+
isLoggedIn: state.lookup.isLoggedIn,
132+
tags: state.filter.challenge.tags,
117133
});
118134

119135
const mapDispatchToProps = {
120136
updateFilter: actions.filter.updateFilter,
121137
updateQuery: actions.filter.updateChallengeQuery,
138+
userLoggedIn: actions.lookup.isLoggedIn,
122139
};
123140

124141
const mergeProps = (stateProps, dispatchProps, ownProps) => ({

src/containers/Filter/ChallengeFilter/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ChallengeFilter = ({
3333
openForRegistrationCount,
3434
}) => {
3535
// const BUCKET_OPEN_FOR_REGISTRATION = constants.FILTER_BUCKETS[1];
36-
const tagOptions = utils.createDropdownTermOptions(challengeTags);
36+
const tagOptions = utils.createDropdownTermOptions(challengeTags, tags);
3737
const bucketOptions = utils.createRadioOptions(challengeBuckets, bucket);
3838

3939
const caseSensitive = false;

src/reducers/filter.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _ from "lodash";
55
const defaultState = {
66
challenge: {
77
types: constants.FILTER_CHALLENGE_TYPES,
8-
tracks: constants.FILTER_CHALLENGE_TRACKS.filter((track) => track !== "QA"),
8+
tracks: constants.FILTER_CHALLENGE_TRACKS,
99
search: "",
1010
tags: [],
1111
groups: [],
@@ -14,15 +14,12 @@ const defaultState = {
1414
endDateStart: null,
1515
page: 1,
1616
perPage: constants.PAGINATION_PER_PAGES[0],
17-
sortBy: constants.CHALLENGE_SORT_BY_RECOMMENDED,
17+
sortBy: constants.CHALLENGE_SORT_BY_MOST_RECENT,
1818
totalPrizesFrom: 0,
1919
totalPrizesTo: 10000,
20-
includeAllTags: true,
21-
2220
// ---
2321

2422
bucket: constants.FILTER_BUCKETS[1],
25-
recommended: false,
2623
},
2724
};
2825

src/reducers/lookup.js

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const defaultState = {
77
tracks: constants.FILTER_CHALLENGE_TRACKS,
88
tags: [],
99
subCommunities: [],
10+
isLoggedIn: false,
1011
};
1112

1213
function onGetTagsDone(state, { payload }) {
@@ -17,10 +18,15 @@ function onGetCommunityListDone(state, { payload }) {
1718
return { ...state, subCommunities: payload };
1819
}
1920

21+
function onIsLoggedInDone(state, { payload }) {
22+
return { ...state, isLoggedIn: payload };
23+
}
24+
2025
export default handleActions(
2126
{
2227
GET_TAGS_DONE: onGetTagsDone,
2328
GET_COMMUNITY_LIST_DONE: onGetCommunityListDone,
29+
IS_LOGGED_IN_DONE: onIsLoggedInDone,
2430
},
2531
defaultState
2632
);

src/services/lookup.js

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ async function getTags() {
1818
return data.result.content.map((tag) => tag.name);
1919
}
2020

21+
async function isLoggedIn() {
22+
const isLoggedIn = await utils.auth.isLoggedIn();
23+
return isLoggedIn;
24+
}
25+
2126
async function doGetUserGroups() {
2227
const isLoggedIn = await utils.auth.isLoggedIn();
2328

@@ -51,4 +56,5 @@ async function getCommunityList() {
5156
export default {
5257
getTags,
5358
getCommunityList,
59+
isLoggedIn,
5460
};

src/utils/challenge.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export function createChallengeFilter(params) {
100100
bucket: normalized.bucket,
101101
totalPrizesFrom: normalized.totalPrizesFrom,
102102
totalPrizesTo: normalized.totalPrizesTo,
103-
includeAllTags: normalized.includeAllTags,
104103
recommended: normalized.recommended,
105104
},
106105
(value) => value == null
@@ -116,18 +115,12 @@ const queryScheme = {
116115
tags: Joi.array().items(Joi.string()),
117116
startDateEnd: Joi.date(),
118117
endDateStart: Joi.date(),
119-
sortBy: Joi.string().valid(
120-
"bestMatch",
121-
"updated",
122-
"overview.totalPrizes",
123-
"name"
124-
),
118+
sortBy: Joi.string().valid("updated", "overview.totalPrizes", "name"),
125119
groups: Joi.array().items(Joi.optionalId()).unique(),
126120
events: Joi.array().items(Joi.string()),
127121
bucket: Joi.bucket(),
128122
totalPrizesFrom: Joi.number().integer().min(0),
129123
totalPrizesTo: Joi.number().integer().min(0),
130-
includeAllTags: Joi.boolean(),
131124
recommended: Joi.boolean(),
132125
};
133126

@@ -155,7 +148,6 @@ export function createChallengeParams(filter) {
155148
tracks: params.tracks.map(
156149
(track) => constants.FILTER_CHALLENGE_TRACK_ABBREVIATIONS[track]
157150
),
158-
includeAllTags: params.tags.length ? params.includeAllTags : null,
159151
};
160152
}
161153

@@ -189,7 +181,6 @@ export function createChallengeCriteria(filter) {
189181
events: filter.events,
190182
totalPrizesFrom: filter.totalPrizesFrom,
191183
totalPrizesTo: filter.totalPrizesTo,
192-
includeAllTags: filter.tags.length ? filter.includeAllTags : null,
193184
isLightweight: true,
194185
};
195186
}
@@ -264,7 +255,6 @@ export function shouldFetchChallenges(filterUpdate) {
264255
"bucket",
265256
"totalPrizesFrom",
266257
"totalPrizesTo",
267-
"includeAllTags",
268258
].includes(attr)
269259
);
270260
}
@@ -305,7 +295,6 @@ export function createEmptyChallengeFilter() {
305295
"sortBy",
306296
"totalPrizesFrom",
307297
"totalPrizesTo",
308-
"includeAllTags",
309298
"recommended",
310299
]);
311300
}

src/utils/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function setSelectedDropdownOptions(options, selectedValues) {
4848
export function createDropdownTermOptions(values, selectedValues) {
4949
return values.map((value) => ({
5050
label: `${value}`,
51-
selected: !!selectedValues && selectedValues.includes[value],
51+
selected: !!selectedValues && selectedValues.includes(value),
5252
}));
5353
}
5454

0 commit comments

Comments
 (0)