@@ -13,8 +13,6 @@ import { Transition, animated } from 'react-spring';
13
13
const { Meta } = Card ;
14
14
const { Option } = Select ;
15
15
16
- var countDownTimes = { }
17
-
18
16
class Challenges extends React . Component {
19
17
constructor ( props ) {
20
18
super ( props ) ;
@@ -80,27 +78,36 @@ class Challenges extends React.Component {
80
78
// Competition hasn't started
81
79
if ( currentTime < startTime ) {
82
80
const timeLeft = Math . ceil ( ( startTime - currentTime ) / 1000 )
83
- countDownTimes [ data [ x ] . _id ] = { time : timeLeft , tillStart : true } // time left in seconds till start
84
81
countDownTimerStrings [ data [ x ] . _id ] = this . getTimerString ( timeLeft , true )
85
82
}
86
83
else {
87
84
const timeLeft = Math . ceil ( ( endTime - currentTime ) / 1000 )
88
- countDownTimes [ data [ x ] . _id ] = { time : timeLeft , tillStart : false } // time left in seconds till end
89
85
countDownTimerStrings [ data [ x ] . _id ] = this . getTimerString ( timeLeft , false )
90
86
}
91
87
}
92
88
}
93
89
this . setState ( { countDownTimerStrings : countDownTimerStrings } )
94
- setInterval ( this . countDownTicker . bind ( this ) , 1000 * 10 )
90
+ setInterval ( this . countDownTicker . bind ( this ) , 1000 * 15 , data )
95
91
return [ challengeMetaInfo , data ] ;
96
92
}
97
93
98
- countDownTicker ( ) {
99
- let countDownTimerStrings = this . state . countDownTimerStrings
100
- for ( const key in countDownTimes ) {
101
- const current = countDownTimes [ key ]
102
- current . time -= 10
103
- countDownTimerStrings [ key ] = this . getTimerString ( current . time , current . tillStart )
94
+ countDownTicker ( data ) {
95
+ let countDownTimerStrings = { }
96
+ for ( let x = 0 ; x < data . length ; x ++ ) {
97
+ if ( "time" in data [ x ] . meta ) {
98
+ const startTime = new Date ( data [ x ] . meta . time [ 0 ] )
99
+ const endTime = new Date ( data [ x ] . meta . time [ 1 ] )
100
+ const currentTime = new Date ( )
101
+ // Competition hasn't started
102
+ if ( currentTime < startTime ) {
103
+ const timeLeft = Math . ceil ( ( startTime - currentTime ) / 1000 )
104
+ countDownTimerStrings [ data [ x ] . _id ] = this . getTimerString ( timeLeft , true )
105
+ }
106
+ else {
107
+ const timeLeft = Math . ceil ( ( endTime - currentTime ) / 1000 )
108
+ countDownTimerStrings [ data [ x ] . _id ] = this . getTimerString ( timeLeft , false )
109
+ }
110
+ }
104
111
}
105
112
this . setState ( { countDownTimerStrings : countDownTimerStrings } )
106
113
}
@@ -176,7 +183,7 @@ class Challenges extends React.Component {
176
183
for ( let i = 0 ; i < originalData . length ; i ++ ) {
177
184
originalDataDictionary [ originalData [ i ] . _id ] = originalData [ i ] . challenges
178
185
}
179
- this . setState ( { disableNonCatFB : data . disableNonCatFB , userCategories : data . userCategories , categories : categoryMetaInfo , originalData : originalDataDictionary , loadingChall : false } )
186
+ this . setState ( { disableNonCatFB : data . disableNonCatFB , userCategories : data . userCategories , categories : categoryMetaInfo , originalData : originalDataDictionary , loadingChall : false } )
180
187
let categoryChall = this . props . match . params . categoryChall ;
181
188
const mongoID = / ^ [ a - f \d ] { 24 } $ / i
182
189
if ( typeof categoryChall !== "undefined" ) {
@@ -196,7 +203,7 @@ class Challenges extends React.Component {
196
203
}
197
204
}
198
205
if ( foundChallenge ) {
199
- this . setState ( { currentCategory : foundChallenge . category , currentCategoryChallenges : [ originalDataDictionary [ foundChallenge . category ] ] , foundChallenge : foundChallenge } )
206
+ this . setState ( { currentCategory : foundChallenge . category , currentCategoryChallenges : [ originalDataDictionary [ foundChallenge . category ] ] , foundChallenge : foundChallenge } )
200
207
}
201
208
else message . error ( "Challenge with ID '" + challenge + "' not found." )
202
209
}
0 commit comments