@@ -35,7 +35,7 @@ export default class QuizStudentPage extends Component {
35
35
loading : true ,
36
36
appState : AppState . currentState ,
37
37
opens : 0 ,
38
- firstOpen : '' ,
38
+ firstOpen : 0 ,
39
39
} ;
40
40
this . setOption = this . setOption . bind ( this ) ;
41
41
this . quizresultData = this . quizresultData . bind ( this ) ;
@@ -46,28 +46,14 @@ export default class QuizStudentPage extends Component {
46
46
'change' ,
47
47
nextAppState => {
48
48
if (
49
- this . state . appState . match ( / i n a c t i v e | b a c k g r o u n d / ) &&
50
- nextAppState === 'active' &&
51
- this . props . currentQuiz &&
52
- this . state . firstOpen === ''
53
- ) {
54
- console . log ( 'Quiz has come to the foreground for First time!' ) ;
55
- this . setState ( { opens : this . state . opens + 1 } ) ;
56
- console . log ( this . state . opens ) ;
57
- const timestamp_first = moment
58
- . utc ( database ( ) . getServerTime ( ) )
59
- . format ( 'DD/MM/YYYY HH:mm:ss' ) ;
60
- this . setState ( { firstOpen : timestamp_first } ) ;
61
- } else if (
62
49
this . state . appState . match ( / i n a c t i v e | b a c k g r o u n d / ) &&
63
50
nextAppState === 'active' &&
64
51
this . props . currentQuiz
65
52
) {
66
- console . log ( 'Quiz has come to the foreground!' ) ;
67
-
53
+ console . log ( 'Quiz has come to the foreground for First time!' ) ;
68
54
this . setState ( { opens : this . state . opens + 1 } ) ;
69
55
console . log ( this . state . opens ) ;
70
- }
56
+ }
71
57
this . setState ( { appState : nextAppState } ) ;
72
58
} ,
73
59
) ;
@@ -143,13 +129,18 @@ export default class QuizStudentPage extends Component {
143
129
) ;
144
130
console . log ( this . state . date ) ;
145
131
146
- var date1 = new Date ( this . state . date ) ;
147
- var date2 = new Date ( timestamp ) ;
148
- var difference = date2 . getTime ( ) - date1 . getTime ( ) ;
149
- var quiz_response_time = ( difference / 60000 ) * 60 ;
132
+ const date1 = new Date ( this . state . date ) ;
133
+ const date2 = new Date ( timestamp ) ;
134
+ const date3 = new Date ( this . state . firstOpen )
135
+ const difference = date2 . getTime ( ) - date1 . getTime ( ) ;
136
+ const differenceOpen = date3 . getTime ( ) - date1 . getTime ( ) ;
137
+ let quiz_response_time = ( difference / 60000 ) * 60 ;
138
+ let first_open_time = ( differenceOpen / 60000 ) * 60 ;
150
139
quiz_response_time = quiz_response_time . toFixed ( 2 ) ;
140
+ first_open_time = first_open_time . toFixed ( 2 ) ;
151
141
console . log ( 'Response Time added' ) ;
152
142
console . log ( quiz_response_time ) ;
143
+ console . log ( first_open_time ) ;
153
144
154
145
await kbcresponse
155
146
. getResponse ( this . state . user . url , this . state . course . passCode )
@@ -165,7 +156,7 @@ export default class QuizStudentPage extends Component {
165
156
this . state . user . name ,
166
157
quiz_response_time ,
167
158
this . state . opens ,
168
- this . state . firstOpen ,
159
+ first_open_time ,
169
160
)
170
161
. then ( r => {
171
162
console . log ( 'create' ) ;
@@ -182,7 +173,7 @@ export default class QuizStudentPage extends Component {
182
173
quiz_response_time ,
183
174
url ,
184
175
this . state . opens ,
185
- this . state . firstOpen ,
176
+ first_open_time ,
186
177
)
187
178
. then ( r => {
188
179
console . log ( 'update' ) ;
@@ -193,8 +184,18 @@ export default class QuizStudentPage extends Component {
193
184
194
185
render ( ) {
195
186
if ( ! this . state . loading ) {
196
- // console.log("Debugging");
197
- // console.log(this.props.quizType);
187
+
188
+ console . log ( 'Printing line-> 197, QuizStudentPage.js' ) ;
189
+ console . log ( this . state . opens , this . props . currentQuiz , this . state . appState ) ;
190
+ if ( this . props . currentQuiz && this . state . opens === 0 ) {
191
+ const timestamp_first = moment
192
+ . utc ( database ( ) . getServerTime ( ) )
193
+ . format ( 'DD/MM/YYYY HH:mm:ss' ) ;
194
+ console . log ( 'Printing line-> 203, QuizStudentPage.js' ) ;
195
+ this . setState ( { firstOpen : timestamp_first } ) ;
196
+ this . setState ( { opens : this . state . opens + 1 } ) ;
197
+ console . log ( this . state . firstOpen ) ;
198
+ }
198
199
return (
199
200
< SafeAreaView style = { styles . safeContainer } >
200
201
{ this . props . currentQuiz === false ? (
@@ -228,6 +229,7 @@ export default class QuizStudentPage extends Component {
228
229
option : '' ,
229
230
icon : '' ,
230
231
error : null ,
232
+ opens : 0 ,
231
233
} ) ;
232
234
this . props . setQuizState ( ) ;
233
235
this . getCorrectAnswer ( ) . then ( r => {
0 commit comments