Skip to content

Commit b0525b3

Browse files
Fixed Issue of FirstOpen Time
1 parent 8b71c49 commit b0525b3

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

App/Components/Quiz/QuizStudentPage.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class QuizStudentPage extends Component {
3535
loading: true,
3636
appState: AppState.currentState,
3737
opens: 0,
38-
firstOpen: '',
38+
firstOpen: 0,
3939
};
4040
this.setOption = this.setOption.bind(this);
4141
this.quizresultData = this.quizresultData.bind(this);
@@ -46,28 +46,14 @@ export default class QuizStudentPage extends Component {
4646
'change',
4747
nextAppState => {
4848
if (
49-
this.state.appState.match(/inactive|background/) &&
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 (
6249
this.state.appState.match(/inactive|background/) &&
6350
nextAppState === 'active' &&
6451
this.props.currentQuiz
6552
) {
66-
console.log('Quiz has come to the foreground!');
67-
53+
console.log('Quiz has come to the foreground for First time!');
6854
this.setState({opens: this.state.opens + 1});
6955
console.log(this.state.opens);
70-
}
56+
}
7157
this.setState({appState: nextAppState});
7258
},
7359
);
@@ -143,13 +129,18 @@ export default class QuizStudentPage extends Component {
143129
);
144130
console.log(this.state.date);
145131

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;
150139
quiz_response_time = quiz_response_time.toFixed(2);
140+
first_open_time = first_open_time.toFixed(2);
151141
console.log('Response Time added');
152142
console.log(quiz_response_time);
143+
console.log(first_open_time);
153144

154145
await kbcresponse
155146
.getResponse(this.state.user.url, this.state.course.passCode)
@@ -165,7 +156,7 @@ export default class QuizStudentPage extends Component {
165156
this.state.user.name,
166157
quiz_response_time,
167158
this.state.opens,
168-
this.state.firstOpen,
159+
first_open_time,
169160
)
170161
.then(r => {
171162
console.log('create');
@@ -182,7 +173,7 @@ export default class QuizStudentPage extends Component {
182173
quiz_response_time,
183174
url,
184175
this.state.opens,
185-
this.state.firstOpen,
176+
first_open_time,
186177
)
187178
.then(r => {
188179
console.log('update');
@@ -193,8 +184,18 @@ export default class QuizStudentPage extends Component {
193184

194185
render() {
195186
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+
}
198199
return (
199200
<SafeAreaView style={styles.safeContainer}>
200201
{this.props.currentQuiz === false ? (
@@ -228,6 +229,7 @@ export default class QuizStudentPage extends Component {
228229
option: '',
229230
icon: '',
230231
error: null,
232+
opens: 0,
231233
});
232234
this.props.setQuizState();
233235
this.getCorrectAnswer().then(r => {

0 commit comments

Comments
 (0)