@@ -80,26 +80,25 @@ function getActiveChallengesInit(uuid, page, frontFilter) {
80
80
return { uuid, page, frontFilter } ;
81
81
}
82
82
83
- /** TODO: Inspect if the 2 actions bellow can be removed?
84
- * They do duplicate what is done in `getActiveChallengesDone` but fetch all challenges
85
- * which was refactored in listing-improve
83
+ /**
84
+ * Get all challenges and match with user challenges
85
+ * @param {String } uuid progress id
86
+ * @param {String } tokenV3 token v3
87
+ * @param {Object } filter filter object
88
+ * @param {number } page start page
86
89
*/
87
- function getAllActiveChallengesInit ( uuid ) {
88
- return uuid ;
89
- }
90
- function getAllActiveChallengesDone ( uuid , tokenV3 ) {
91
- const filter = { status : 'ACTIVE' } ;
90
+ function getAllActiveChallengesWithUsersDone ( uuid , tokenV3 , filter , page = 0 ) {
92
91
const service = getService ( tokenV3 ) ;
93
92
const calls = [
94
- getAll ( params => service . getChallenges ( filter , params ) ) ,
93
+ getAll ( params => service . getChallenges ( filter , params ) , page ) ,
95
94
] ;
96
95
let user ;
97
96
if ( tokenV3 ) {
98
97
user = decodeToken ( tokenV3 ) . handle ;
99
98
// Handle any errors on this endpoint so that the non-user specific challenges
100
99
// will still be loaded.
101
100
calls . push ( getAll ( params => service . getUserChallenges ( user , filter , params )
102
- . catch ( ( ) => ( { challenges : [ ] } ) ) ) ) ;
101
+ . catch ( ( ) => ( { challenges : [ ] } ) ) ) , page ) ;
103
102
}
104
103
return Promise . all ( calls ) . then ( ( [ ch , uch ] ) => {
105
104
/* uch array contains challenges where the user is participating in
@@ -120,10 +119,22 @@ function getAllActiveChallengesDone(uuid, tokenV3) {
120
119
} ) ;
121
120
}
122
121
123
- return { uuid, challenges : ch } ;
122
+ return { uuid, challenges : ch , ... filter } ;
124
123
} ) ;
125
124
}
126
125
126
+ /** TODO: Inspect if the 2 actions bellow can be removed?
127
+ * They do duplicate what is done in `getActiveChallengesDone` but fetch all challenges
128
+ * which was refactored in listing-improve
129
+ */
130
+ function getAllActiveChallengesInit ( uuid ) {
131
+ return uuid ;
132
+ }
133
+ function getAllActiveChallengesDone ( uuid , tokenV3 ) {
134
+ const filter = { status : 'ACTIVE' } ;
135
+ return getAllActiveChallengesWithUsersDone ( uuid , tokenV3 , filter ) ;
136
+ }
137
+
127
138
/**
128
139
* Gets 1 page of active challenges (including marathon matches) from the backend.
129
140
* Once this action is completed any active challenges saved to the state before
@@ -200,43 +211,33 @@ function getRestActiveChallengesInit(uuid) {
200
211
201
212
/**
202
213
* Loading all challenges
203
- * @param {* } uuid
204
- * @param {* } tokenV3
214
+ * @param {String } uuid progress id
215
+ * @param {String } tokenV3 token v3
205
216
*/
206
217
function getRestActiveChallengesDone ( uuid , tokenV3 ) {
207
218
const filter = { status : 'ACTIVE' } ;
208
- const service = getService ( tokenV3 ) ;
209
- const calls = [
210
- getAll ( params => service . getChallenges ( filter , params ) , 1 ) ,
211
- ] ;
212
- let user ;
213
- if ( tokenV3 ) {
214
- user = decodeToken ( tokenV3 ) . handle ;
215
- calls . push ( getAll ( params => service . getUserChallenges ( user , filter , params )
216
- . catch ( ( ) => ( { challenges : [ ] } ) ) ) , 1 ) ;
217
- }
218
- return Promise . all ( calls ) . then ( ( [ ch , uch ] ) => {
219
- /* uch array contains challenges where the user is participating in
220
- * some role. The same challenge are already listed in res array, but they
221
- * are not attributed to the user there. This block of code marks user
222
- * challenges in an efficient way. */
223
- if ( uch ) {
224
- const map = { } ;
225
- uch . forEach ( ( item ) => { map [ item . id ] = item ; } ) ;
226
- ch . forEach ( ( item ) => {
227
- if ( map [ item . id ] ) {
228
- /* It is fine to reassing, as the array we modifying is created just
229
- * above within the same function. */
230
- /* eslint-disable no-param-reassign */
231
- item . users [ user ] = true ;
232
- item . userDetails = map [ item . id ] . userDetails ;
233
- /* eslint-enable no-param-reassign */
234
- }
235
- } ) ;
236
- }
219
+ return getAllActiveChallengesWithUsersDone ( uuid , tokenV3 , filter , 1 ) ;
220
+ }
237
221
238
- return { uuid, challenges : ch } ;
239
- } ) ;
222
+ /**
223
+ * Prepare for getting all recommended challenges
224
+ * @param {String } uuid progress id
225
+ */
226
+ function getAllRecommendedChallengesInit ( uuid ) {
227
+ return uuid ;
228
+ }
229
+ /**
230
+ * Get all recommended challenges
231
+ * @param {String } uuid progress id
232
+ * @param {String } tokenV3 token v3
233
+ * @param {* } recommendedTechnology recommended technoloty
234
+ */
235
+ function getAllRecommendedChallengesDone ( uuid , tokenV3 , recommendedTechnology ) {
236
+ const filter = {
237
+ status : 'ACTIVE' ,
238
+ technologies : recommendedTechnology ,
239
+ } ;
240
+ return getAllActiveChallengesWithUsersDone ( uuid , tokenV3 , filter ) ;
240
241
}
241
242
242
243
/**
@@ -333,6 +334,9 @@ export default createActions({
333
334
GET_ALL_ACTIVE_CHALLENGES_INIT : getAllActiveChallengesInit ,
334
335
GET_ALL_ACTIVE_CHALLENGES_DONE : getAllActiveChallengesDone ,
335
336
337
+ GET_ALL_RECOMMENDED_CHALLENGES_INIT : getAllRecommendedChallengesInit ,
338
+ GET_ALL_RECOMMENDED_CHALLENGES_DONE : getAllRecommendedChallengesDone ,
339
+
336
340
GET_ACTIVE_CHALLENGES_INIT : getActiveChallengesInit ,
337
341
GET_ACTIVE_CHALLENGES_DONE : getActiveChallengesDone ,
338
342
0 commit comments