Skip to content

Commit

Permalink
Update quizStep.tsx (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
GradleD authored Oct 25, 2024
1 parent c559051 commit 866c9a1
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions components/admin/taskSteps/quizStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,37 +102,36 @@ const QuizStep: FunctionComponent<QuizStepProps> = ({
[steps]
);

const handleCorrectAnswer = useCallback(
(optionIndex: number, questionIndex: number) => {
const updatedSteps = steps.map((step, i) => {
if (i === index && step.type === "Quiz") {
const updatedQuestions = step.data.questions.map(
(questionObj: typeof QuizQuestionDefaultInput, qIndex: number) => {
if (qIndex === questionIndex) {
return {
...questionObj,
correct_answers: [optionIndex],
};
}
return questionObj;
const handleCorrectAnswer = useCallback(
(optionIndex: number, questionIndex: number) => {
const updatedSteps = steps.map((step, i) => {
if (i === index && step.type === "Quiz") {
const updatedQuestions = step.data.questions.map(
(questionObj: typeof QuizQuestionDefaultInput, qIndex: number) => {
if (qIndex === questionIndex) {
return {
...questionObj,
correct_answers: [optionIndex - 1], // Subtract 1 to map to API
};
}
);

return {
...step,
data: {
...step.data,
questions: updatedQuestions,
},
};
}
return step;
});
setSteps(updatedSteps);
},
[steps]
);
return questionObj;
}
);

return {
...step,
data: {
...step.data,
questions: updatedQuestions,
},
};
}
return step;
});
setSteps(updatedSteps);
},
[steps, index, setSteps]
);
const handleAddQuestion = useCallback(() => {
const updatedSteps = steps.map((step, i) => {
if (i === index && step.type === "Quiz") {
Expand Down

0 comments on commit 866c9a1

Please sign in to comment.