| @@ -40,8 +40,23 @@ | ||
| 40 | 40 | }, |
| 41 | 41 | }; |
| 42 | 42 | }; |
| 43 | 43 | |
| 44 | +const updateUserQuestionFibAnswer = ( state, action ) => { | |
| 45 | + const { id } = state; | |
| 46 | + const { questionId, idInput, valueInput } = action; | |
| 47 | + | |
| 48 | + if ( state.answered.hasOwnProperty( questionId ) ) { | |
| 49 | + state.answered[ questionId ].answered[ idInput ] = valueInput; | |
| 50 | + } else { | |
| 51 | + state.answered[ action.questionId ] = { answered: { [ idInput ]: valueInput }, temp: true }; | |
| 52 | + } | |
| 53 | + | |
| 54 | + localStorage.setItem( `LP_Quiz_${ id }_Answered`, JSON.stringify( state.answered ) ); | |
| 55 | + | |
| 56 | + return state; | |
| 57 | +}; | |
| 58 | + | |
| 44 | 59 | const markQuestionRendered = ( state, action ) => { |
| 45 | 60 | const { |
| 46 | 61 | questionsRendered, |
| 47 | 62 | } = state; |
| @@ -108,9 +123,9 @@ | ||
| 108 | 123 | if ( newAnswered ) { |
| 109 | 124 | newAnswered = { |
| 110 | 125 | ...JSON.parse( newAnswered ), |
| 111 | 126 | ...answered, |
| 112 | - } | |
| 127 | + }; | |
| 113 | 128 | |
| 114 | 129 | localStorage.setItem( `LP_Quiz_${ state.id }_Answered`, JSON.stringify( newAnswered ) ); |
| 115 | 130 | } |
| 116 | 131 | |
| @@ -116,9 +131,9 @@ | ||
| 116 | 131 | |
| 117 | 132 | return { |
| 118 | 133 | ...state, |
| 119 | 134 | questions: [ ...questions ], |
| 120 | - answered: answered, | |
| 135 | + answered, | |
| 121 | 136 | checkedQuestions: [ ...state.checkedQuestions, action.questionId ], |
| 122 | 137 | }; |
| 123 | 138 | }; |
| 124 | 139 | |
| @@ -126,15 +141,14 @@ | ||
| 126 | 141 | localStorage.removeItem( `LP_Quiz_${ state.id }_Answered` ); |
| 127 | 142 | |
| 128 | 143 | const questions = state.questions.map( ( question ) => { |
| 129 | 144 | const newArgs = {}; |
| 130 | - | |
| 131 | 145 | if ( state.reviewQuestions ) { |
| 132 | - if ( action.results.questions[ question.id ].explanation ) { | |
| 146 | + if ( action.results.questions[ question.id ]?.explanation ) { | |
| 133 | 147 | newArgs.explanation = action.results.questions[ question.id ].explanation; |
| 134 | 148 | } |
| 135 | 149 | |
| 136 | - if ( action.results.questions[ question.id ].options ) { | |
| 150 | + if ( action.results.questions[ question.id ]?.options ) { | |
| 137 | 151 | newArgs.options = action.results.questions[ question.id ].options; |
| 138 | 152 | } |
| 139 | 153 | } |
| 140 | 154 | |
| @@ -152,8 +166,11 @@ | ||
| 152 | 166 | const startQuizz = ( state, action ) => { |
| 153 | 167 | const successResponse = ( action.results.success ) !== undefined ? action.results.success : false; |
| 154 | 168 | const messageResponse = action.results.message || false; |
| 155 | 169 | |
| 170 | + const chunks = chunk( action.results.results.questionIds, state.questionsPerPage ); | |
| 171 | + state.numPages = chunks.length; | |
| 172 | + | |
| 156 | 173 | return resetCurrentPage( state, { |
| 157 | 174 | checkedQuestions: [], |
| 158 | 175 | hintedQuestions: [], |
| 159 | 176 | mode: '', |
| @@ -205,8 +222,10 @@ | ||
| 205 | 222 | case 'SUBMIT_QUIZ_SUCCESS': |
| 206 | 223 | return submitQuiz( state, action ); |
| 207 | 224 | case 'UPDATE_USER_QUESTION_ANSWERS': |
| 208 | 225 | return state.status === 'started' ? updateUserQuestionAnswer( state, action ) : state; |
| 226 | + case 'UPDATE_USER_QUESTION_FIB_ANSWERS': | |
| 227 | + return state.status === 'started' ? updateUserQuestionFibAnswer( state, action ) : state; | |
| 209 | 228 | case 'MARK_QUESTION_RENDERED': |
| 210 | 229 | return markQuestionRendered( state, action ); |
| 211 | 230 | case 'SET_QUIZ_MODE': |
| 212 | 231 | if ( action.mode == 'reviewing' ) { |