From 18740fbaf06f4d34ed464540481de5e584bb2374 Mon Sep 17 00:00:00 2001 From: ndittren <36773036+ndittren@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:51:10 -0500 Subject: [PATCH] Set up state for answers --- .../simulations/simulation1/criticalValue.jsx | 7 +- .../simulation1/hypothesisTest.jsx | 7 +- .../simulation1/pvalueComponent.jsx | 5 +- media/js/src/simulations/simulation1/quiz.jsx | 6 +- .../simulations/simulation1/simulationOne.jsx | 4 + .../simulation1/simulationOneQuiz.jsx | 88 +++++++++++-------- 6 files changed, 71 insertions(+), 46 deletions(-) diff --git a/media/js/src/simulations/simulation1/criticalValue.jsx b/media/js/src/simulations/simulation1/criticalValue.jsx index 0abbf5c..4ffa4ba 100644 --- a/media/js/src/simulations/simulation1/criticalValue.jsx +++ b/media/js/src/simulations/simulation1/criticalValue.jsx @@ -5,8 +5,8 @@ import { saveAnswer } from '../../utils/utils'; export const CriticalValue = ({ hypothesisTest2validate, tvalue, n, alpha, hypothesisTest, hypothesis, - nullHypothesis, submissionId, plotType, - setHypothesisTest2validate, criticalValues, isRedo, + nullHypothesis, submissionId, plotType, criticalValues, isRedo, + setHypothesisTest2validate, answers }) => { const [nullHypothesisChoice2, setNullHypothesisChoice2] = useState(null); const [userCriticalValue, setUserCriticalValue] = useState(''); @@ -448,5 +448,6 @@ CriticalValue.propTypes = { plotType: PropTypes.string.isRequired, setHypothesisTest2validate: PropTypes.func.isRequired, criticalValues: PropTypes.object, - isRedo: PropTypes.bool + isRedo: PropTypes.bool, + answers: PropTypes.array }; \ No newline at end of file diff --git a/media/js/src/simulations/simulation1/hypothesisTest.jsx b/media/js/src/simulations/simulation1/hypothesisTest.jsx index 0b2b02e..8abab6a 100644 --- a/media/js/src/simulations/simulation1/hypothesisTest.jsx +++ b/media/js/src/simulations/simulation1/hypothesisTest.jsx @@ -7,7 +7,8 @@ import axios from 'axios'; export const HypothesisTest = ({ selectedAltHypothesis, appRvalue, tvalue, hypothesizedSlope, n, completedChoices, submissionId, plotType, setSelectedAltHypothesis, - setIsHypothesisCompleted, isRedo, setIsRedo, isHypothesisCompleted + setIsHypothesisCompleted, isRedo, setIsRedo, isHypothesisCompleted, + answers }) => { const [pvalues, setPvalues] = useState(null); const [alpha, setAlpha] = useState(null); @@ -161,6 +162,7 @@ export const HypothesisTest = ({ setIsRedo={setIsRedo} tvalue={tvalue} pvalue={parseFloat(pvalue)} + answers={answers} alpha={alpha} hypothesis={hypothesis} nullHypothesis={nullHypothesis} @@ -194,5 +196,6 @@ HypothesisTest.propTypes = { setIsHypothesisCompleted: PropTypes.func, isRedo: PropTypes.bool, setIsRedo: PropTypes.func, - isHypothesisCompleted: PropTypes.bool + isHypothesisCompleted: PropTypes.bool, + answers: PropTypes.array }; \ No newline at end of file diff --git a/media/js/src/simulations/simulation1/pvalueComponent.jsx b/media/js/src/simulations/simulation1/pvalueComponent.jsx index f630d72..7497d73 100644 --- a/media/js/src/simulations/simulation1/pvalueComponent.jsx +++ b/media/js/src/simulations/simulation1/pvalueComponent.jsx @@ -7,7 +7,7 @@ import PropTypes from 'prop-types'; export const PvalueComponent = ({ pvalue, tvalue, submissionId, hypothesis, nullHypothesis, alpha, hypothesisTest1validate, setHypothesisTest1validate, - plotType, isRedo, hypothesisTest + plotType, isRedo, hypothesisTest, answers }) => { const [userPvalue, setUserPvalue] = useState(''); @@ -392,5 +392,6 @@ PvalueComponent.propTypes = { setHypothesisTest1validate: PropTypes.func, plotType: PropTypes.string, isRedo: PropTypes.bool, - hypothesisTest: PropTypes.string + hypothesisTest: PropTypes.string, + answers: PropTypes.array }; \ No newline at end of file diff --git a/media/js/src/simulations/simulation1/quiz.jsx b/media/js/src/simulations/simulation1/quiz.jsx index 131a06d..05f1df5 100644 --- a/media/js/src/simulations/simulation1/quiz.jsx +++ b/media/js/src/simulations/simulation1/quiz.jsx @@ -8,7 +8,8 @@ import { CriticalValue } from './criticalValue.jsx'; export const Quiz = ({ tvalue, pvalue, alpha, hypothesisTest, hypothesis, nullHypothesis, n, completedChoices, submissionId, - plotType, isRedo, setIsRedo, setIsHypothesisCompleted, isHypothesisCompleted + plotType, isRedo, setIsRedo, setIsHypothesisCompleted, + isHypothesisCompleted, answers }) => { // eslint-disable-next-line max-len const [hypothesisTest1validate, setHypothesisTest1validate] = useState(null); @@ -65,6 +66,7 @@ export const Quiz = ({ hypothesisTest={hypothesisTest} hypothesis={hypothesis} nullHypothesis={nullHypothesis} + answers={answers} plotType={plotType} isRedo={isRedo} submissionId={submissionId} /> @@ -78,6 +80,7 @@ export const Quiz = ({ hypothesis={hypothesis} nullHypothesis={nullHypothesis} isRedo={isRedo} + answers={answers} n={n} hypothesisTest2validate={hypothesisTest2validate} setHypothesisTest2validate={setHypothesisTest2validate} @@ -130,4 +133,5 @@ Quiz.propTypes = { setIsRedo: PropTypes.func, setIsHypothesisCompleted: PropTypes.func, isHypothesisCompleted: PropTypes.bool, + answers: PropTypes.array }; diff --git a/media/js/src/simulations/simulation1/simulationOne.jsx b/media/js/src/simulations/simulation1/simulationOne.jsx index f7eb54d..d343e4d 100644 --- a/media/js/src/simulations/simulation1/simulationOne.jsx +++ b/media/js/src/simulations/simulation1/simulationOne.jsx @@ -39,6 +39,7 @@ export const SimulationOne = () => { const [completedChoices3d, setCompletedChoices3d] = useState([]); const [selectedAltHypothesis, setSelectedAltHypothesis] = useState(null); const [isNInvalid, setIsNInvalid] = useState(false); + const [answers, setAnswers] = useState([]); const createSubmission = async() => { @@ -159,6 +160,7 @@ export const SimulationOne = () => { setStartQuiz2(true); } setSubmissionId(data.submission_id); + setAnswers(data.answers); } }); }, []); @@ -404,6 +406,7 @@ export const SimulationOne = () => { { { const [isSubmitted, setIsSubmitted] = useState(false); const [isTakeawayCorrect, setIsTakeawayCorrect] = useState({ @@ -145,46 +145,56 @@ export const SimulationOneQuiz = ({ const renderTakeawayQuestion = ( choiceKey, question, options, answer, correctFeedback, - incorrectFeedback, questionNumber) => ( - handleTakeawaySubmit(choiceKey, correct)} - questionStyle={{}} - optionStyle={{}} - answerStyle={{}} - correctFeedback={correctFeedback} - incorrectFeedback={incorrectFeedback} - idkey={`${choiceKey}-${plotType}`} - /> - ); + incorrectFeedback, questionNumber) => { + const userAnswer = answers.find( + answer => answer.question_number === questionNumber); + return ( + handleTakeawaySubmit(choiceKey, correct)} + questionStyle={{}} + optionStyle={{}} + answerStyle={{}} + userAnswer={userAnswer} + correctFeedback={correctFeedback} + incorrectFeedback={incorrectFeedback} + idkey={`${choiceKey}-${plotType}`} + /> + ); + }; const renderQualifierQuestion = ( question, options, answer, correctFeedback, - incorrectFeedback, questionNumber) => ( - - ); + incorrectFeedback, questionNumber) => { + const userAnswer = answers.find( + answer => answer.question_number === questionNumber); + return ( + + ); + }; useEffect(() => { isCompletedfunc(); @@ -273,6 +283,7 @@ export const SimulationOneQuiz = ({ isHypothesisCompleted={isHypothesisCompleted} isRedo={isRedo} setIsRedo={setIsRedo} + answers={answers} /> )} {isHypothesisCompleted && selectedAltHypothesis === 'A' @@ -613,4 +624,5 @@ SimulationOneQuiz.propTypes = { selectedAltHypothesis: PropTypes.string, setSelectedAltHypothesis: PropTypes.func, coursePk: PropTypes.number.isRequired, + answers: PropTypes.array }; \ No newline at end of file