@@ -25,93 +25,29 @@ import './styles.scss';
2525// The container component
2626class DashboardPageContainer extends React . Component {
2727
28- constructor ( props ) {
29- super ( props ) ;
30- this . state = {
31- loadingMyChallenges : false ,
32- loadingMyMarathon : false ,
33- loadingIosChallenges : false ,
34- } ;
35- }
36-
3728 componentDidMount ( ) {
3829 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! */
3932 location . href = 'http://accounts.topcoder-dev.com/#!/member?retUrl=http:%2F%2Flocal.topcoder-dev.com:3000%2Fmy-dashboard' ;
4033 return false ;
4134 }
35+ this . props . getAllActiveChallenges ( this . props . auth . tokenV3 ) ;
4236 this . props . getBlogs ( ) ;
4337 return true ;
4438 }
4539
4640 componentDidUpdate ( prevProps ) {
4741 const { user, tokenV3 } = this . props . auth ;
48- const { challenges } = this . props . challengeListing ;
49- const { iosRegistered } = this . props . dashboard ;
5042 if ( tokenV3 && tokenV3 !== prevProps . auth . tokenV3 ) {
5143 setImmediate ( ( ) => {
44+ this . props . getAllActiveChallenges ( tokenV3 ) ;
5245 this . props . getSubtrackRanks ( tokenV3 , user . handle ) ;
5346 this . props . getSRMs ( tokenV3 , user . handle ) ;
5447 this . props . getIosRegistration ( tokenV3 , user . userId ) ;
5548 this . props . getUserFinancials ( tokenV3 , user . handle ) ;
5649 } ) ;
5750 }
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- }
11551 }
11652
11753 render ( ) {
@@ -131,7 +67,9 @@ class DashboardPageContainer extends React.Component {
13167 _ . filter ( challenges , c => c . platforms === 'iOS' ) ,
13268 ) ;
13369
134- const { loadingMyChallenges, loadingMyMarathon, loadingIosChallenges } = this . state ;
70+ const loadingActiveChallenges =
71+ Boolean ( this . props . challengeListing . loadingActiveChallengesUUID ) ;
72+
13573 return (
13674 < div styleName = "dashboard-container" >
13775 < div styleName = "page-container" >
@@ -149,11 +87,11 @@ class DashboardPageContainer extends React.Component {
14987 </ div >
15088 < div styleName = "challenges" >
15189 {
152- ( loadingMyMarathon || loadingMyChallenges ) &&
90+ loadingActiveChallenges &&
15391 < LoadingIndicator theme = { { } } />
15492 }
15593 {
156- ! loadingMyChallenges && ! loadingMyMarathon &&
94+ ! loadingActiveChallenges &&
15795 < MyChallenges
15896 challenges = { myChallenges . slice ( 0 , 8 ) }
15997 groups = { profile ? profile . groups : [ ] }
@@ -200,11 +138,11 @@ class DashboardPageContainer extends React.Component {
200138 </ div >
201139 < div styleName = "programs" >
202140 {
203- loadingIosChallenges &&
141+ loadingActiveChallenges &&
204142 < LoadingIndicator theme = { { } } />
205143 }
206144 {
207- ! loadingIosChallenges &&
145+ ! loadingActiveChallenges &&
208146 < Program
209147 challenges = { iosChallenges . slice ( 0 , 3 ) }
210148 iosRegistered = { iosRegistered }
@@ -233,10 +171,9 @@ DashboardPageContainer.propTypes = {
233171 auth : PT . shape ( ) ,
234172 dashboard : PT . shape ( ) ,
235173 challengeListing : PT . shape ( ) ,
174+ getAllActiveChallenges : PT . func . isRequired ,
236175 getSubtrackRanks : PT . func . isRequired ,
237- getChallenges : PT . func . isRequired ,
238176 getSRMs : PT . func . isRequired ,
239- getMarathonMatches : PT . func . isRequired ,
240177 getIosRegistration : PT . func . isRequired ,
241178 registerIos : PT . func . isRequired ,
242179 getBlogs : PT . func . isRequired ,
@@ -249,39 +186,6 @@ DashboardPageContainer.defaultProps = {
249186 challengeListing : { } ,
250187} ;
251188
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-
285189const mapStateToProps = state => ( {
286190 auth : state . auth ,
287191 dashboard : state . dashboard ,
@@ -293,8 +197,11 @@ const mapDispatchToProps = dispatch => ({
293197 dispatch ( actions . dashboard . getSubtrackRanksInit ( ) ) ;
294198 dispatch ( actions . dashboard . getSubtrackRanksDone ( tokenV3 , handle ) ) ;
295199 } ,
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+ } ,
298205 getSRMs : ( tokenV3 , handle ) => {
299206 dispatch ( actions . dashboard . getSrmsInit ( ) ) ;
300207 dispatch ( actions . dashboard . getSrmsDone ( tokenV3 , handle , {
0 commit comments