@@ -7,6 +7,7 @@ import { createActions } from 'redux-actions';
7
7
import { decodeToken } from 'tc-accounts' ;
8
8
import 'isomorphic-fetch' ;
9
9
import { processSRM } from 'utils/tc' ;
10
+ import { mapUserWithChallenges } from 'utils/challenge-listing/helper' ;
10
11
import { errors , services } from 'topcoder-react-lib' ;
11
12
12
13
const { fireErrorMessage } = errors ;
@@ -104,27 +105,12 @@ function getAllActiveChallengesWithUsersDone(uuid, tokenV3, filter, page = 0) {
104
105
calls . push ( getAll ( params => service . getUserChallenges ( user , newFilter , params )
105
106
. catch ( ( ) => ( { challenges : [ ] } ) ) ) , page ) ;
106
107
}
107
- return Promise . all ( calls ) . then ( ( [ ch , uch ] ) => {
108
- /* uch array contains challenges where the user is participating in
109
- @@ -111,8 +124,8 @@ function getAllActiveChallengesDone(uuid, tokenV3) {
110
- * challenges in an efficient way. */
111
- if ( uch ) {
112
- const map = { } ;
113
- uch . forEach ( ( item ) => { map [ item . id ] = item ; } ) ;
114
- ch . forEach ( ( item ) => {
115
- if ( map [ item . id ] ) {
116
- /* It is fine to reassing, as the array we modifying is created just
117
- * above within the same function. */
118
- /* eslint-disable no-param-reassign */
119
- item . users [ user ] = true ;
120
- item . userDetails = map [ item . id ] . userDetails ;
121
- /* eslint-enable no-param-reassign */
122
- }
123
- } ) ;
124
- }
125
-
126
- return { uuid, challenges : ch , ...filter } ;
127
- } ) ;
108
+ // uch array contains challenges where the user is participating in
109
+ return Promise . all ( calls ) . then ( ( [ ch , uch ] ) => ( {
110
+ uuid,
111
+ challenges : mapUserWithChallenges ( user , ch , uch ) ,
112
+ ...filter ,
113
+ } ) ) ;
128
114
}
129
115
130
116
/** TODO: Inspect if the 2 actions bellow can be removed?
@@ -182,12 +168,12 @@ function getActiveChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter
182
168
183
169
// Handle any errors on this endpoint so that the non-user specific challenges
184
170
// will still be loaded.
185
- calls . push ( service . getUserChallenges ( user , filter , { } )
186
- . catch ( ( ) => ( { challenges : [ ] } ) ) ) ;
171
+ calls . push ( getAll ( params => service . getUserChallenges ( user , filter , params )
172
+ . catch ( ( ) => ( { challenges : [ ] } ) ) ) ) ;
187
173
}
188
- return Promise . all ( calls ) . then ( ( [ ch ] ) => ( {
174
+ return Promise . all ( calls ) . then ( ( [ ch , uch ] ) => ( {
189
175
uuid,
190
- challenges : ch . challenges ,
176
+ challenges : mapUserWithChallenges ( user , ch . challenges , uch ) ,
191
177
meta : ch . meta ,
192
178
frontFilter,
193
179
} ) ) ;
0 commit comments