@@ -3,6 +3,7 @@ import { QuestionPoolType, AnswerType, QuestionTypes } from '../types';
33import { isAlreadySelected , validateSelectionIsCorrect } from '../util' ;
44import Answers from './Answers' ;
55import Question from './Question' ;
6+ import ProgressBar from './ProgressBar' ;
67import { Context } from '../Context' ;
78import Button from './Button' ;
89import styles from './Form.module.scss' ;
@@ -31,6 +32,7 @@ const Form = ({
3132 const [ showConfirmation , setShowConfirmation ] = useState ( false ) ;
3233 const [ submitted , setSubmitted ] = useState ( false ) ;
3334 const [ selections , setSelections ] = useState < AnswerType [ ] > ( [ ] ) ;
35+ const [ progress , setProgress ] = useState ( 0 ) ;
3436
3537 useEffect ( ( ) => {
3638 if ( ! submitted ) {
@@ -98,6 +100,12 @@ const Form = ({
98100 }
99101 } ;
100102
103+ const handleProgressBar = ( question : QuestionPoolType ) => {
104+ if ( question . correctlyAnswered || question . remainingAttempts === 0 ) {
105+ setProgress ( progress + 100 / numberOfQuestions ) ;
106+ }
107+ } ;
108+
101109 const submitHandler = ( event : FormEvent ) => {
102110 event . preventDefault ( ) ;
103111
@@ -109,6 +117,7 @@ const Form = ({
109117 setSubmitted ( true ) ;
110118 updatePool ( correctlyAnswered ) ;
111119 addToResult ( updatedQuestion ( correctlyAnswered ) ) ;
120+ handleProgressBar ( updatedQuestion ( correctlyAnswered ) ) ;
112121 setSelections ( [ ] ) ;
113122 } ;
114123
@@ -139,6 +148,7 @@ const Form = ({
139148
140149 return (
141150 < form onSubmit = { submitHandler } className = { styles . form } >
151+ < ProgressBar progress = { progress } />
142152 < fieldset className = { `${ styles . form } ${ styles . fieldset } ` } >
143153 < legend className = { `${ styles . form } ${ styles . legend } ` } >
144154 { questionIndexText } { t ( 'form.of' ) } { numberOfQuestions }
0 commit comments