Show next prompt immediately on correct answer

This commit is contained in:
2021-10-21 20:14:54 +01:00
parent 386c03205a
commit 5d2c3394e8

View File

@@ -328,7 +328,7 @@ export default withRouter(class Progress extends React.Component {
const data = result.data; const data = result.data;
let newState = { let newState = {
currentAnswerStatus: data.correct, currentAnswerStatus: data.correct ? null : false,
currentCorrect: data.correctAnswers, currentCorrect: data.correctAnswers,
moreAnswers: data.moreAnswers, moreAnswers: data.moreAnswers,
nextPrompt: data.nextPrompt ? data.nextPrompt.item : null, nextPrompt: data.nextPrompt ? data.nextPrompt.item : null,
@@ -356,16 +356,12 @@ export default withRouter(class Progress extends React.Component {
if (this.state.mode === "lives") newState.lives = data.lives; if (this.state.mode === "lives") newState.lives = data.lives;
if ((data.correct || data.lives === 0) && !data.moreAnswers && this.state.incorrectAnswers[data.currentVocabId]) { if (data.correct) {
// all answers to question given correctly // correct answer given
// answer was previously wrong
// store correct answer
newState.incorrectAnswers = this.state.incorrectAnswers;
newState.incorrectAnswers[data.currentVocabId].answer = data.correctAnswers;
} else if (data.correct && data.moreAnswers) {
newState.answerInput = ""; newState.answerInput = "";
newState.currentAnswerStatus = null; // show next question if there are no more answers
} else if (!data.correct) { if (!data.moreAnswers) newState = this.showNextQuestion(newState, newState);
} else {
// incorrect answer given // incorrect answer given
// store prompt and count=0 // store prompt and count=0
// store answer if in lives mode and no lives left // store answer if in lives mode and no lives left
@@ -377,6 +373,14 @@ export default withRouter(class Progress extends React.Component {
}; };
} }
if ((data.correct || data.lives === 0) && !data.moreAnswers && this.state.incorrectAnswers[data.currentVocabId]) {
// all answers to question given correctly
// answer was previously wrong
// store correct answer
newState.incorrectAnswers = this.state.incorrectAnswers;
newState.incorrectAnswers[data.currentVocabId].answer = data.correctAnswers;
}
let promises = []; let promises = [];
if (data.duration) { if (data.duration) {
@@ -475,6 +479,15 @@ export default withRouter(class Progress extends React.Component {
} }
} }
showNextQuestion = (newState, currentState) => {
if (currentState.nextPrompt === null) newState.setComplete = true;
newState.currentCorrect = [];
newState.currentPrompt = currentState.nextPrompt;
newState.currentSound = currentState.nextSound;
newState.currentSetOwner = currentState.nextSetOwner;
return newState;
}
nextQuestion = () => { nextQuestion = () => {
if (this.state.canProceed) { if (this.state.canProceed) {
this.startLoading(); this.startLoading();
@@ -487,11 +500,7 @@ export default withRouter(class Progress extends React.Component {
}; };
if (!this.state.moreAnswers) { if (!this.state.moreAnswers) {
if (this.state.nextPrompt === null) newState.setComplete = true; newState = this.showNextQuestion(newState, this.state);
newState.currentCorrect = [];
newState.currentPrompt = this.state.nextPrompt;
newState.currentSound = this.state.nextSound;
newState.currentSetOwner = this.state.nextSetOwner;
} }
this.setState(newState, () => (this.isMounted && !this.state.setComplete) && this.answerInput.focus()); this.setState(newState, () => (this.isMounted && !this.state.setComplete) && this.answerInput.focus());