@@ -8,32 +8,69 @@ async function doGetChallenges(filter) {
8
8
}
9
9
10
10
async function getAllActiveChallenges ( filter ) {
11
- const activeFilter = {
11
+ const BUCKET_ALL_ACTIVE_CHALLENGES = constants . FILTER_BUCKETS [ 0 ] ;
12
+ let page ;
13
+
14
+ if ( util . isDisplayingBucket ( filter , BUCKET_ALL_ACTIVE_CHALLENGES ) ) {
15
+ page = filter . page ;
16
+ } else {
17
+ page = 1 ;
18
+ }
19
+
20
+ const allActiveFilter = {
12
21
...util . createChallengeCriteria ( filter ) ,
13
22
...util . createAllActiveChallengeCriteria ( ) ,
23
+ page,
14
24
} ;
15
- return doGetChallenges ( activeFilter ) ;
25
+ return doGetChallenges ( allActiveFilter ) ;
16
26
}
17
27
18
28
async function getOpenForRegistrationChallenges ( filter ) {
29
+ const BUCKET_OPEN_FOR_REGISTRATION = constants . FILTER_BUCKETS [ 1 ] ;
30
+ let page ;
31
+
32
+ if ( util . isDisplayingBucket ( filter , BUCKET_OPEN_FOR_REGISTRATION ) ) {
33
+ page = filter . page ;
34
+ } else {
35
+ page = 1 ;
36
+ }
37
+
19
38
const openForRegistrationFilter = {
20
39
...util . createChallengeCriteria ( filter ) ,
21
40
...util . createOpenForRegistrationChallengeCriteria ( ) ,
41
+ page,
22
42
} ;
23
43
return doGetChallenges ( openForRegistrationFilter ) ;
24
44
}
25
45
26
46
async function getClosedChallenges ( filter ) {
27
- const pastFilter = {
47
+ const BUCKET_CLOSED_CHALLENGES = constants . FILTER_BUCKETS [ 1 ] ;
48
+ let page ;
49
+
50
+ if ( util . isDisplayingBucket ( filter , BUCKET_CLOSED_CHALLENGES ) ) {
51
+ page = filter . page ;
52
+ } else {
53
+ page = 1 ;
54
+ }
55
+
56
+ const closedFilter = {
28
57
...util . createChallengeCriteria ( filter ) ,
29
58
...util . createClosedChallengeCriteria ( ) ,
59
+ page,
30
60
} ;
31
- return doGetChallenges ( pastFilter ) ;
61
+ return doGetChallenges ( closedFilter ) ;
32
62
}
33
63
34
64
async function getRecommendedChallenges ( filter ) {
35
- const result = [ ]
36
- result . meta = { total : 0 }
65
+ let result = [ ] ;
66
+ result . meta = { total : 0 } ;
67
+
68
+ if ( result . length === 0 ) {
69
+ const failbackFilter = { ...filter } ;
70
+ result = await getOpenForRegistrationChallenges ( failbackFilter ) ;
71
+ result . loadingRecommendedChallengesError = true ;
72
+ }
73
+
37
74
return result ;
38
75
}
39
76
@@ -51,35 +88,58 @@ async function getChallenges(filter, change) {
51
88
const FILTER_BUCKETS = constants . FILTER_BUCKETS ;
52
89
const BUCKET_ALL_ACTIVE_CHALLENGES = FILTER_BUCKETS [ 0 ] ;
53
90
const BUCKET_OPEN_FOR_REGISTRATION = FILTER_BUCKETS [ 1 ] ;
54
- const BUCKET_PAST_CHALLENGES = FILTER_BUCKETS [ 2 ] ;
91
+ const BUCKET_CLOSED_CHALLENGES = FILTER_BUCKETS [ 2 ] ;
55
92
const filterChange = change ;
56
93
const bucket = filter . bucket ;
57
94
58
95
const getChallengesByBuckets = async ( f ) => {
59
96
return FILTER_BUCKETS . includes ( f . bucket )
60
97
? Promise . all ( [
61
- getAllActiveChallenges ( f ) ,
62
- f . recommended ? getRecommendedChallenges ( ) : getOpenForRegistrationChallenges ( f ) ,
63
- getClosedChallenges ( f )
64
- ] )
65
- : [ [ ] , [ ] , [ ] ]
98
+ getAllActiveChallenges ( f ) ,
99
+ f . recommended
100
+ ? getRecommendedChallenges ( f )
101
+ : getOpenForRegistrationChallenges ( f ) ,
102
+ getClosedChallenges ( f ) ,
103
+ ] )
104
+ : [ [ ] , [ ] , [ ] ] ;
66
105
} ;
67
106
68
107
if ( ! filterChange ) {
69
- let [ allActiveChallenges , openForRegistrationChallenges , closedChallenges ] = await getChallengesByBuckets ( filter )
108
+ let [
109
+ allActiveChallenges ,
110
+ openForRegistrationChallenges ,
111
+ closedChallenges ,
112
+ ] = await getChallengesByBuckets ( filter ) ;
70
113
let challenges ;
71
114
let openForRegistrationCount ;
72
115
let total ;
116
+ let loadingRecommendedChallengesError ;
73
117
74
118
switch ( bucket ) {
75
- case BUCKET_ALL_ACTIVE_CHALLENGES : challenges = allActiveChallenges ; break ;
76
- case BUCKET_OPEN_FOR_REGISTRATION : challenges = openForRegistrationChallenges ; break ;
77
- case BUCKET_PAST_CHALLENGES : challenges = closedChallenges ; break ;
119
+ case BUCKET_ALL_ACTIVE_CHALLENGES :
120
+ challenges = allActiveChallenges ;
121
+ break ;
122
+ case BUCKET_OPEN_FOR_REGISTRATION :
123
+ challenges = openForRegistrationChallenges ;
124
+ break ;
125
+ case BUCKET_CLOSED_CHALLENGES :
126
+ challenges = closedChallenges ;
127
+ break ;
78
128
}
79
129
openForRegistrationCount = openForRegistrationChallenges . meta . total ;
80
130
total = challenges . meta . total ;
81
-
82
- return { challenges, total, openForRegistrationCount, allActiveChallenges, openForRegistrationChallenges, closedChallenges } ;
131
+ loadingRecommendedChallengesError =
132
+ challenges . loadingRecommendedChallengesError ;
133
+
134
+ return {
135
+ challenges,
136
+ total,
137
+ openForRegistrationCount,
138
+ loadingRecommendedChallengesError,
139
+ allActiveChallenges,
140
+ openForRegistrationChallenges,
141
+ closedChallenges,
142
+ } ;
83
143
}
84
144
85
145
if ( ! util . checkRequiredFilterAttributes ( filter ) ) {
@@ -92,26 +152,47 @@ async function getChallenges(filter, change) {
92
152
let challenges ;
93
153
let openForRegistrationCount ;
94
154
let total ;
155
+ let loadingRecommendedChallengesError ;
95
156
96
157
if ( util . shouldFetchChallenges ( filterChange ) ) {
97
- [ allActiveChallenges , openForRegistrationChallenges , closedChallenges ] = await getChallengesByBuckets ( filter )
158
+ [
159
+ allActiveChallenges ,
160
+ openForRegistrationChallenges ,
161
+ closedChallenges ,
162
+ ] = await getChallengesByBuckets ( filter ) ;
98
163
switch ( bucket ) {
99
- case BUCKET_ALL_ACTIVE_CHALLENGES : challenges = allActiveChallenges ; break ;
100
- case BUCKET_OPEN_FOR_REGISTRATION : challenges = openForRegistrationChallenges ; break ;
101
- case BUCKET_PAST_CHALLENGES : challenges = closedChallenges ; break ;
164
+ case BUCKET_ALL_ACTIVE_CHALLENGES :
165
+ challenges = allActiveChallenges ;
166
+ break ;
167
+ case BUCKET_OPEN_FOR_REGISTRATION :
168
+ challenges = openForRegistrationChallenges ;
169
+ break ;
170
+ case BUCKET_CLOSED_CHALLENGES :
171
+ challenges = closedChallenges ;
172
+ break ;
102
173
}
103
174
}
104
175
105
176
openForRegistrationCount = openForRegistrationChallenges . meta . total ;
106
177
total = challenges . meta . total ;
178
+ loadingRecommendedChallengesError =
179
+ challenges . loadingRecommendedChallengesError ;
107
180
108
181
if ( util . shouldFilterChallenges ( filterChange ) ) {
109
182
challenges = doFilterBySubSommunities ( challenges ) ;
110
183
challenges = doFilterByPrizeFrom ( challenges ) ;
111
184
challenges = doFilterByPrizeTo ( challenges ) ;
112
185
}
113
186
114
- return { challenges, total, openForRegistrationCount, allActiveChallenges, openForRegistrationChallenges, closedChallenges } ;
187
+ return {
188
+ challenges,
189
+ total,
190
+ openForRegistrationCount,
191
+ loadingRecommendedChallengesError,
192
+ allActiveChallenges,
193
+ openForRegistrationChallenges,
194
+ closedChallenges,
195
+ } ;
115
196
}
116
197
117
198
export default createActions ( {
0 commit comments