diff --git a/src/Progress.js b/src/Progress.js index 04ff357..1d4bd68 100644 --- a/src/Progress.js +++ b/src/Progress.js @@ -8,6 +8,7 @@ import Error404 from "./Error404"; import SettingsContent from "./SettingsContent"; import Footer from "./Footer"; import LineChart from './LineChart'; +import ProgressStats from './ProgressStats'; import "./css/PopUp.css"; import "./css/Progress.css"; @@ -63,6 +64,8 @@ export default withRouter(class Progress extends React.Component { setIds: [], attemptNumber: 1, attemptHistory: {}, + questions: [], + originalTotalQuestions: 1, }; let isMounted = true; @@ -98,6 +101,7 @@ export default withRouter(class Progress extends React.Component { mode: data.mode, nextPrompt: null, setIds: data.setIds, + originalTotalQuestions: [...new Set(data.questions)].length, }; if (data.lives) { @@ -189,7 +193,7 @@ export default withRouter(class Progress extends React.Component { } this.setState(newState, () => { - if (!setDone) this.answerInput.focus() + if (!setDone) this.answerInput.focus(); }); this.props.logEvent("select_content", { @@ -380,7 +384,9 @@ export default withRouter(class Progress extends React.Component { await Promise.all(promises); - this.setState(newState); + this.setState(newState, () => { + if (!newState.duration) this.answerInput.focus() + }); }).catch((error) => { console.log(`Couldn't process answer: ${error}`); this.setState({ @@ -443,11 +449,11 @@ export default withRouter(class Progress extends React.Component { : <> -
- { - this.state.currentAnswerStatus === null - ? - <> + { + this.state.currentAnswerStatus === null + ? +
+

{this.state.currentPrompt}

e.preventDefault()} > @@ -467,95 +473,97 @@ export default withRouter(class Progress extends React.Component { loading={this.state.loading} >
-
+
+ { + this.state.currentCorrect && this.state.currentCorrect.length > 0 + ? + <> +

+ { + this.state.moreAnswers + ? + "Correct so far:" + : + "Answers:" + } +

+ {this.state.currentCorrect.map((vocab, index) => +

{vocab}

+ )} + + : + "" + } +
+
+
+ : + this.state.nextPrompt === null && !this.state.moreAnswers + ? +
+ {/* DONE */} +

{this.state.setTitle}

+
+

You got

+

{`${(this.state.correct / this.state.totalQuestions * 100).toFixed(2)}%`}

+
+
+

{`${this.state.correct} of ${this.state.totalQuestions}`}

+

marks

+
+
+

You took

+

{this.msToTime(this.state.duration)}

+
+
+

Attempt #

+

{this.state.attemptNumber}

+
+ { + this.state.incorrectAnswers && Object.keys(this.state.incorrectAnswers).length > 0 && + <> +

Incorrect answers:

+
+
+

Prompt

+

Answer

+

Mistakes

+
{ - this.state.currentCorrect && this.state.currentCorrect.length > 0 - ? - <> -

- { - this.state.moreAnswers - ? - "Correct so far:" - : - "Answers:" - } -

- {this.state.currentCorrect.map((vocab, index) => -

{vocab}

- )} - - : - "" + Object.keys(this.state.incorrectAnswers).map(key => + [key, this.state.incorrectAnswers[key].count]) + .sort((a,b) => b[1] - a[1]).map(item => +
+

{this.state.incorrectAnswers[item[0]].prompt ? this.state.incorrectAnswers[item[0]].prompt : ""}

+

{this.state.incorrectAnswers[item[0]].answer ? this.state.incorrectAnswers[item[0]].answer.join("/") : ""}

+

{this.state.incorrectAnswers[item[0]].count}

+
+ ) }
- - : - this.state.nextPrompt === null && !this.state.moreAnswers - ? - <> - {/* DONE */} -

{this.state.setTitle}

-
-

You got

-

{`${(this.state.correct / this.state.totalQuestions * 100).toFixed(2)}%`}

-
-
-

{`${this.state.correct} of ${this.state.totalQuestions}`}

-

marks

-
-
-

You took

-

{this.msToTime(this.state.duration)}

-
-
-

Attempt #

-

{this.state.attemptNumber}

-
- { - this.state.incorrectAnswers && Object.keys(this.state.incorrectAnswers).length > 0 && - <> -

Incorrect answers:

-
-
-

Prompt

-

Answer

-

Mistakes

-
- { - Object.keys(this.state.incorrectAnswers).map(key => - [key, this.state.incorrectAnswers[key].count]) - .sort((a,b) => b[1] - a[1]).map(item => -
-

{this.state.incorrectAnswers[item[0]].prompt ? this.state.incorrectAnswers[item[0]].prompt : ""}

-

{this.state.incorrectAnswers[item[0]].answer ? this.state.incorrectAnswers[item[0]].answer.join("/") : ""}

-

{this.state.incorrectAnswers[item[0]].count}

-
- ) - } -
- - } + + } - {this.state.attemptNumber > 1 && - <> -

History

- - - } + {this.state.attemptNumber > 1 && + <> +

History

+ + + } -
- - Done - -
- - : - <> - {/* ANSWER PROCESSED */} +
+ + Done + +
+
+ : +
+ {/* ANSWER PROCESSED */} +

{this.state.currentPrompt}

e.preventDefault()} > @@ -564,6 +572,7 @@ export default withRouter(class Progress extends React.Component { name="answer_input" className={`answer-input ${this.state.currentAnswerStatus ? "answer-input--correct" : "answer-input--incorrect"}`} value={this.state.answerInput} + ref={inputEl => (this.answerInput = inputEl)} readOnly />
+ +
+ } + { + (this.state.currentAnswerStatus === null || + !(this.state.nextPrompt === null && !this.state.moreAnswers)) && + 0 ? this.state.correct / this.state.totalQuestions * 100 : 0} + /> + }