fix(curriculum): add feedback for unanswered multiple choice questions (#57707)

This commit is contained in:
Sem Bauke
2024-12-23 11:56:20 +01:00
committed by GitHub
parent 73a6004f99
commit f048a7f377
2 changed files with 14 additions and 1 deletions

View File

@@ -425,6 +425,7 @@
"assignments": "Assignments",
"question": "Question",
"questions": "Questions",
"answered-mcq": "You have unanswered questions and/or incorrect answers.",
"explanation": "Explanation",
"solution-link": "Solution Link",
"source-code-link": "Source Code Link",

View File

@@ -156,6 +156,9 @@ const ShowGeneric = ({
const [submittedMcqAnswers, setSubmittedMcqAnswers] = useState(
questions.map<number | null>(() => null)
);
const [hasAnsweredMcqCorrectly, sethasAnsweredMcqCorrectly] = useState(true);
const [showFeedback, setShowFeedback] = useState(false);
const showNextCurriculum = useFeature('fcc-10').on;
@@ -171,7 +174,6 @@ const ShowGeneric = ({
);
};
// submit
const handleSubmit = () => {
const hasCompletedAssignments =
assignments.length === 0 || allAssignmentsCompleted;
@@ -183,6 +185,12 @@ const ShowGeneric = ({
if (hasCompletedAssignments && mcqCorrect) {
openCompletionModal();
}
if (mcqSolutions.length > selectedMcqOptions.length || !mcqCorrect) {
sethasAnsweredMcqCorrectly(false);
} else {
sethasAnsweredMcqCorrectly(true);
}
};
const sceneSubject = new SceneSubject();
@@ -258,6 +266,10 @@ const ShowGeneric = ({
<ChallengeExplanation explanation={explanation} />
) : null}
{!hasAnsweredMcqCorrectly && (
<p className='text-center'>{t('learn.answered-mcq')}</p>
)}
<Button block={true} variant='primary' onClick={handleSubmit}>
{blockType === BlockTypes.review
? t('buttons.submit')