|
|
@ -42,10 +42,10 @@ class Quiz extends React.Component { |
|
|
|
results: false |
|
|
|
} |
|
|
|
|
|
|
|
answer = correct => { |
|
|
|
answer = (correct, id) => { |
|
|
|
this.setState( |
|
|
|
state => { |
|
|
|
const nextState = { answered: true } |
|
|
|
const nextState = { answered: true, clickedId: id } |
|
|
|
|
|
|
|
if (correct) { |
|
|
|
nextState.correctCount = state.correctCount + 1 |
|
|
@ -58,7 +58,7 @@ class Quiz extends React.Component { |
|
|
|
return nextState |
|
|
|
}, |
|
|
|
() => { |
|
|
|
setTimeout(() => this.nextQuestion(), 750) |
|
|
|
setTimeout(() => this.nextQuestion(), correct ? 750 : 3000) |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
@ -102,11 +102,12 @@ class Quiz extends React.Component { |
|
|
|
<Text style={styles.text}>{question.question}</Text> |
|
|
|
|
|
|
|
<ButtonContainer> |
|
|
|
{question.answers.map(answer => ( |
|
|
|
{question.answers.map( (answer, index) => ( |
|
|
|
<Button |
|
|
|
key={answer.id} |
|
|
|
text={answer.text} |
|
|
|
onPress={() => this.answer(answer.correct)} |
|
|
|
colorize={{id: answer.id, clicked: this.state.clickedId, answered: this.state.answered, isCorrect: answer.correct}} |
|
|
|
onPress={() => this.answer(answer.correct, answer.id)} |
|
|
|
/> |
|
|
|
))} |
|
|
|
</ButtonContainer> |
|
|
@ -116,10 +117,7 @@ class Quiz extends React.Component { |
|
|
|
{`${this.state.correctCount+this.state.wrongCount}/${this.state.totalCount}`} |
|
|
|
</Text> |
|
|
|
</SafeAreaView> |
|
|
|
<Alert |
|
|
|
correct={this.state.answerCorrect} |
|
|
|
visible={this.state.answered} |
|
|
|
/> |
|
|
|
|
|
|
|
<Results |
|
|
|
total={this.state.totalCount} |
|
|
|
correct={this.state.correctCount} |
|
|
|