From 5014bd3effaf26fe512835e3e418fbb4a6f18cc9 Mon Sep 17 00:00:00 2001 From: Leung Cheng Date: Fri, 24 May 2024 20:56:13 +0800 Subject: [PATCH] Restructure ChoicesEditor --- src/app/components/editor.tsx | 188 +++++++++++++++++----------------- 1 file changed, 93 insertions(+), 95 deletions(-) diff --git a/src/app/components/editor.tsx b/src/app/components/editor.tsx index f945f47..519f3dc 100644 --- a/src/app/components/editor.tsx +++ b/src/app/components/editor.tsx @@ -303,45 +303,16 @@ function QuestionSetEditor({ }} /> -
-

Choices:

- - - - - - - - - - { - handleQuestionUpdate(question.id, (oldQuestion) => ({ - ...oldQuestion, - choices, - })) - }} - /> - -
AnswerCorrect - Fixed Position -
- - -
+ { + handleQuestionUpdate(question.id, (oldQuestion) => ({ + ...oldQuestion, + choices, + })) + }} + /> ) })} @@ -413,60 +384,87 @@ function ChoicesEditor(props: { onChoicesUpdate(newChoices) } - const choiceEditors = [] - for (let choiceIndex = 0; choiceIndex < choices.length; choiceIndex++) { - const choiceNumber = choiceIndex + 1 - const choice = choices[choiceIndex] - choiceEditors.push( - - - { - handleInternalChoiceUpdate(choice.id, { - answer: e.target.value, - }) - }} - aria-label={QuestionSetEditorAriaLabel.answerInput({ - choiceNumber, - questionNumber, - })} - /> - - - { - handleInternalChoiceUpdate(choice.id, { - isCorrect: e.target.checked, - }) - }} - aria-label={QuestionSetEditorAriaLabel.isCorrectAnswerCheckbox({ - choiceNumber, - questionNumber, - })} - /> - - - { - handleInternalChoiceUpdate(choice.id, { - isFixedPosition: e.target.checked, - }) - }} - /> - - , - ) - } - return choiceEditors + return ( +
+

Choices:

+ + + + + + + + + + {choices.map((choice, choiceIndex) => { + const choiceNumber = choiceIndex + 1 + return ( + + + + + + ) + })} + +
AnswerCorrectFixed Position
+ { + handleInternalChoiceUpdate(choice.id, { + answer: e.target.value, + }) + }} + aria-label={QuestionSetEditorAriaLabel.answerInput({ + choiceNumber, + questionNumber, + })} + /> + + { + handleInternalChoiceUpdate(choice.id, { + isCorrect: e.target.checked, + }) + }} + aria-label={QuestionSetEditorAriaLabel.isCorrectAnswerCheckbox( + { + choiceNumber, + questionNumber, + }, + )} + /> + + { + handleInternalChoiceUpdate(choice.id, { + isFixedPosition: e.target.checked, + }) + }} + /> +
+ + +
+ ) }