Skip to content

Commit

Permalink
fix bug reading test last item of last set
Browse files Browse the repository at this point in the history
  • Loading branch information
ducvugithub committed May 15, 2024
1 parent 9dd415a commit 859304d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
30 changes: 25 additions & 5 deletions client/components/Tests/ReadingTest/ReadingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React, { useState, useEffect } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { Segment } from 'semantic-ui-react'
import { Spinner, Button } from 'react-bootstrap'
import { useHistory } from 'react-router-dom'
import {
sendReadingTestAnswer,
finishExhaustiveTest,
updateTestFeedbacks,
updateReadingTestElicitation,
nextReadingTestQuestion,
finishReadingTest,
markAnsweredChoice,
sendReadingTestQuestionnaireResponses,
} from 'Utilities/redux/testReducer'
Expand Down Expand Up @@ -56,6 +58,8 @@ const ReadingTest = () => {
const learningLanguage = useSelector(learningLanguageSelector)
const { groups } = useSelector(({ groups }) => groups)

const history = useHistory()

let in_experimental_grp = false;
let in_control_grp = false;

Expand All @@ -78,7 +82,15 @@ const ReadingTest = () => {
setShowSelfReflect(false)
setCurrentAnswer(null)
setCurrentElicatedConstruct(null)
dispatch(nextReadingTestQuestion())
if (currentReadingQuestionIndex === readingTestQuestions.length - 1){
dispatch(finishReadingTest())
} else {
dispatch(nextReadingTestQuestion())
}
}

const goToHomePage = () => {
history.push('/home')
}

const submitSelfReflectionResponse = (response_json) => {
Expand All @@ -87,7 +99,11 @@ const ReadingTest = () => {
setFirstMediationSelfReflectionDone(true)
}
else {
setShowNextSetDialog(true)
if (currentReadingQuestionIndex === readingTestQuestions.length - 1){
goToHomePage()
} else {
setShowNextSetDialog(true)
}
}
setShowSelfReflect(false)
if (currentReadingSet !== prevReadingSet && prevReadingSet !== null && currentReadingSet !== null) {
Expand Down Expand Up @@ -169,7 +185,7 @@ const ReadingTest = () => {
setQuestionDone(true)
setCurrentAnswer(null)
}
}
}

if (!isSelectedChoice){
dispatch(
Expand Down Expand Up @@ -302,10 +318,14 @@ const ReadingTest = () => {
className="next-reading-question-button"
style={{ marginLeft: '0.5em' }}
onClick={() => nextQuestion()}
disabled={!questionDone || showFeedbacks || currentReadingQuestionIndex === readingTestQuestions.length - 1}
disabled={!questionDone || showFeedbacks } // || currentReadingQuestionIndex === readingTestQuestions.length - 1
>
<span>
<FormattedMessage id="next-reading-question" />
{currentReadingQuestionIndex === readingTestQuestions.length - 1 ? (
<FormattedMessage id="finish-reading-question" />
) : (
<FormattedMessage id="next-reading-question" />
)}
</span>
</Button>
)}
Expand Down
11 changes: 11 additions & 0 deletions client/util/redux/testReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export const nextTestQuestion = () => ({ type: 'NEXT_TEST_QUESTION' })

export const nextReadingTestQuestion = () => ({ type: 'NEXT_READING_TEST_QUESTION' })

export const finishReadingTest = () => ({ type: 'FINISH_READING_TEST' })

export const markAnsweredChoice = (answer) => ({ type: 'MARK_ANSWERED_CHOICE', answer })

export default (state = initialState, action) => {
Expand Down Expand Up @@ -300,6 +302,15 @@ export default (state = initialState, action) => {
feedbacks: [],
}

case 'FINISH_READING_TEST':
let _lastSet = readingTestQuestions[currentReadingQuestionIndex].set;
let _finishedSet = _lastSet + 1;
return {
...state,
currentReadingSet: _finishedSet,
prevReadingSet: _lastSet,
}

case 'NEXT_READING_TEST_QUESTION':
if (currentReadingQuestionIndex < readingTestQuestions.length - 1){
let _currentReadingSet = readingTestQuestions[currentReadingQuestionIndex + 1].set;
Expand Down

0 comments on commit 859304d

Please sign in to comment.