Avoid race condition when simulator change
parent
497a675d06
commit
ca4af46cc7
|
@ -13,6 +13,7 @@ import {
|
|||
import {
|
||||
answeredQuestionsSelector,
|
||||
currentQuestionSelector,
|
||||
urlSelector,
|
||||
useMissingVariables,
|
||||
} from '@/store/selectors/simulationSelectors'
|
||||
|
||||
|
@ -21,6 +22,7 @@ export function useNavigateQuestions(engines?: Array<Engine<DottedName>>) {
|
|||
const engine = useEngine()
|
||||
const nextQuestion = useNextQuestions(engines)[0]
|
||||
const currentQuestion = useSelector(currentQuestionSelector)
|
||||
const url = useSelector(urlSelector)
|
||||
|
||||
const missingVariables = useMissingVariables({ engines: engines ?? [engine] })
|
||||
const currentQuestionIsAnswered =
|
||||
|
@ -45,6 +47,10 @@ export function useNavigateQuestions(engines?: Array<Engine<DottedName>>) {
|
|||
}
|
||||
}, [nextQuestion, currentQuestion])
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(goToQuestion(nextQuestion))
|
||||
}, [url])
|
||||
|
||||
return {
|
||||
currentQuestion: currentQuestion ?? nextQuestion,
|
||||
currentQuestionIsAnswered,
|
||||
|
|
|
@ -83,7 +83,7 @@ export const useNextQuestions = function (
|
|||
return next.filter(
|
||||
(question) => engine.getRule(question).rawNode.question !== undefined
|
||||
)
|
||||
}, [missingVariables, config, answeredQuestions, engine])
|
||||
}, [missingVariables, config.questions, answeredQuestions, engine])
|
||||
|
||||
return nextQuestions
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ export const answeredQuestionsSelector = (state: RootState) =>
|
|||
export const shouldFocusFieldSelector = (state: RootState) =>
|
||||
state.simulation?.shouldFocusField ?? false
|
||||
|
||||
export const urlSelector = (state: RootState) => state.simulation?.url
|
||||
|
||||
/**
|
||||
* Merge objectifs missings that depends on the same input field.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue