@@ -25,93 +25,29 @@ import './styles.scss';
25
25
// The container component
26
26
class DashboardPageContainer extends React . Component {
27
27
28
- constructor ( props ) {
29
- super ( props ) ;
30
- this . state = {
31
- loadingMyChallenges : false ,
32
- loadingMyMarathon : false ,
33
- loadingIosChallenges : false ,
34
- } ;
35
- }
36
-
37
28
componentDidMount ( ) {
38
29
if ( ! this . props . auth . tokenV2 ) {
30
+ /* TODO: dev/prod URLs should be generated based on the config,
31
+ * now it is hardcoded with dev URL - wrong! */
39
32
location . href = 'http://accounts.topcoder-dev.com/#!/member?retUrl=http:%2F%2Flocal.topcoder-dev.com:3000%2Fmy-dashboard' ;
40
33
return false ;
41
34
}
35
+ this . props . getAllActiveChallenges ( this . props . auth . tokenV3 ) ;
42
36
this . props . getBlogs ( ) ;
43
37
return true ;
44
38
}
45
39
46
40
componentDidUpdate ( prevProps ) {
47
41
const { user, tokenV3 } = this . props . auth ;
48
- const { challenges } = this . props . challengeListing ;
49
- const { iosRegistered } = this . props . dashboard ;
50
42
if ( tokenV3 && tokenV3 !== prevProps . auth . tokenV3 ) {
51
43
setImmediate ( ( ) => {
44
+ this . props . getAllActiveChallenges ( tokenV3 ) ;
52
45
this . props . getSubtrackRanks ( tokenV3 , user . handle ) ;
53
46
this . props . getSRMs ( tokenV3 , user . handle ) ;
54
47
this . props . getIosRegistration ( tokenV3 , user . userId ) ;
55
48
this . props . getUserFinancials ( tokenV3 , user . handle ) ;
56
49
} ) ;
57
50
}
58
- if ( user && ! prevProps . auth . user && ( ! challenges || ! challenges . length ) ) {
59
- setImmediate (
60
- ( ) => {
61
- this . setState ( { loadingMyChallenges : true } ) ;
62
- this . props . getChallenges (
63
- {
64
- status : 'ACTIVE' ,
65
- } , {
66
- limit : 8 ,
67
- orderBy : 'submissionEndDate' ,
68
- } , tokenV3 , 'active' , user . handle ,
69
- ) . then ( ( ) => {
70
- this . setState ( { loadingMyChallenges : false } ) ;
71
- } )
72
- . catch ( ( ) => {
73
- this . setState ( { loadingMyChallenges : false } ) ;
74
- } ) ;
75
-
76
- this . setState ( { loadingMyMarathon : true } ) ;
77
- this . props . getMarathonMatches (
78
- {
79
- status : 'ACTIVE' ,
80
- } , {
81
- limit : 8 ,
82
- } , tokenV3 , 'myActiveMM' , user . handle ,
83
- )
84
- . then ( ( ) => {
85
- this . setState ( { loadingMyMarathon : false } ) ;
86
- } )
87
- . catch ( ( ) => {
88
- this . setState ( { loadingMyMarathon : false } ) ;
89
- } ) ;
90
- } ,
91
- ) ;
92
- }
93
- if ( iosRegistered && ! prevProps . dashboard . iosRegistered ) {
94
- setImmediate (
95
- ( ) => {
96
- this . setState ( { loadingIosChallenges : true } ) ;
97
- this . props . getChallenges ( {
98
- platforms : 'ios' ,
99
- technologies : 'swift' ,
100
- status : 'active' ,
101
- } , {
102
- limit : 3 ,
103
- offset : 0 ,
104
- orderBy : 'submissionEndDate asc' ,
105
- } )
106
- . then ( ( ) => {
107
- this . setState ( { loadingIosChallenges : false } ) ;
108
- } )
109
- . catch ( ( ) => {
110
- this . setState ( { loadingIosChallenges : false } ) ;
111
- } ) ;
112
- } ,
113
- ) ;
114
- }
115
51
}
116
52
117
53
render ( ) {
@@ -131,7 +67,9 @@ class DashboardPageContainer extends React.Component {
131
67
_ . filter ( challenges , c => c . platforms === 'iOS' ) ,
132
68
) ;
133
69
134
- const { loadingMyChallenges, loadingMyMarathon, loadingIosChallenges } = this . state ;
70
+ const loadingActiveChallenges =
71
+ Boolean ( this . props . challengeListing . loadingActiveChallengesUUID ) ;
72
+
135
73
return (
136
74
< div styleName = "dashboard-container" >
137
75
< div styleName = "page-container" >
@@ -149,11 +87,11 @@ class DashboardPageContainer extends React.Component {
149
87
</ div >
150
88
< div styleName = "challenges" >
151
89
{
152
- ( loadingMyMarathon || loadingMyChallenges ) &&
90
+ loadingActiveChallenges &&
153
91
< LoadingIndicator theme = { { } } />
154
92
}
155
93
{
156
- ! loadingMyChallenges && ! loadingMyMarathon &&
94
+ ! loadingActiveChallenges &&
157
95
< MyChallenges
158
96
challenges = { myChallenges . slice ( 0 , 8 ) }
159
97
groups = { profile ? profile . groups : [ ] }
@@ -200,11 +138,11 @@ class DashboardPageContainer extends React.Component {
200
138
</ div >
201
139
< div styleName = "programs" >
202
140
{
203
- loadingIosChallenges &&
141
+ loadingActiveChallenges &&
204
142
< LoadingIndicator theme = { { } } />
205
143
}
206
144
{
207
- ! loadingIosChallenges &&
145
+ ! loadingActiveChallenges &&
208
146
< Program
209
147
challenges = { iosChallenges . slice ( 0 , 3 ) }
210
148
iosRegistered = { iosRegistered }
@@ -233,10 +171,9 @@ DashboardPageContainer.propTypes = {
233
171
auth : PT . shape ( ) ,
234
172
dashboard : PT . shape ( ) ,
235
173
challengeListing : PT . shape ( ) ,
174
+ getAllActiveChallenges : PT . func . isRequired ,
236
175
getSubtrackRanks : PT . func . isRequired ,
237
- getChallenges : PT . func . isRequired ,
238
176
getSRMs : PT . func . isRequired ,
239
- getMarathonMatches : PT . func . isRequired ,
240
177
getIosRegistration : PT . func . isRequired ,
241
178
registerIos : PT . func . isRequired ,
242
179
getBlogs : PT . func . isRequired ,
@@ -249,39 +186,6 @@ DashboardPageContainer.defaultProps = {
249
186
challengeListing : { } ,
250
187
} ;
251
188
252
- /**
253
- * Callback for loading challenges satisfying to the specified criteria.
254
- * All arguments starting from second should match corresponding arguments
255
- * of the getChallenges action.
256
- * @param {Function } dispatch
257
- */
258
- function getChallenges ( dispatch , ...rest ) {
259
- const uuid = shortid ( ) ;
260
- dispatch ( cActions . challengeListing . getInit ( uuid ) ) ;
261
- const action = cActions . challengeListing . getChallenges ( uuid , ...rest ) ;
262
- dispatch ( action ) ;
263
- return action . payload ;
264
- }
265
-
266
- /**
267
- * Callback for loading marathon matches satisfying to the specified criteria.
268
- * All arguments starting from second should match corresponding arguments
269
- * of the getChallenges action.
270
- * @param {Function } dispatch
271
- */
272
- function getMarathonMatches ( dispatch , filters , ...rest ) {
273
- const uuid = shortid ( ) ;
274
- dispatch ( cActions . challengeListing . getInit ( uuid ) ) ;
275
- const f = _ . clone ( filters ) ;
276
- if ( f . status === 'COMPLETED' ) f . status = 'PAST' ;
277
- const action = cActions . challengeListing . getMarathonMatches ( uuid , f , ...rest ) ;
278
- dispatch ( action ) ;
279
- // TODO: This is hack to make the Redux loading of challenges to work
280
- // with older code inside the InfiniteList, until it is properly
281
- // refactored.
282
- return action . payload ;
283
- }
284
-
285
189
const mapStateToProps = state => ( {
286
190
auth : state . auth ,
287
191
dashboard : state . dashboard ,
@@ -293,8 +197,11 @@ const mapDispatchToProps = dispatch => ({
293
197
dispatch ( actions . dashboard . getSubtrackRanksInit ( ) ) ;
294
198
dispatch ( actions . dashboard . getSubtrackRanksDone ( tokenV3 , handle ) ) ;
295
199
} ,
296
- getChallenges : ( ...rest ) => getChallenges ( dispatch , ...rest ) ,
297
- getMarathonMatches : ( ...rest ) => getMarathonMatches ( dispatch , ...rest ) ,
200
+ getAllActiveChallenges : ( tokenV3 ) => {
201
+ const uuid = shortid ( ) ;
202
+ dispatch ( cActions . challengeListing . getAllActiveChallengesInit ( uuid ) ) ;
203
+ dispatch ( cActions . challengeListing . getAllActiveChallengesDone ( uuid , tokenV3 ) ) ;
204
+ } ,
298
205
getSRMs : ( tokenV3 , handle ) => {
299
206
dispatch ( actions . dashboard . getSrmsInit ( ) ) ;
300
207
dispatch ( actions . dashboard . getSrmsDone ( tokenV3 , handle , {
0 commit comments