From d0d02707010625e8e13aa10fd90999e7aa002c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=C9=A8=D5=BC=C9=A2=D3=84=D5=A1=D6=85=D5=BC=C9=A2?= Date: Tue, 6 Feb 2024 21:41:38 +0800 Subject: [PATCH 1/4] chore(lib): pass answers to onSelectAnswer --- src/lib/Core.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Core.jsx b/src/lib/Core.jsx index 3d0151a..1c6457b 100644 --- a/src/lib/Core.jsx +++ b/src/lib/Core.jsx @@ -270,7 +270,7 @@ function Core({ setUserAttempt, }); - const onSelectAnswer = (index) => selectAnswer(index + 1, correctAnswer, answerSelectionType, { + const onSelectAnswer = (index) => selectAnswer(index + 1, correctAnswer, answerSelectionType, answers, { userInput, currentQuestionIndex, setButtons, From 7728b4c8136d15c2e90db4df29da7f9d6d76734e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=C9=A8=D5=BC=C9=A2=D3=84=D5=A1=D6=85=D5=BC=C9=A2?= Date: Tue, 6 Feb 2024 21:41:56 +0800 Subject: [PATCH 2/4] fix(lib): dynamic disableAll / selectedButtons --- src/lib/core-components/helpers.jsx | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/lib/core-components/helpers.jsx b/src/lib/core-components/helpers.jsx index a795205..70bd9b7 100644 --- a/src/lib/core-components/helpers.jsx +++ b/src/lib/core-components/helpers.jsx @@ -24,12 +24,7 @@ export const checkAnswer = (index, correctAnswer, answerSelectionType, answers, setUserAttempt, }) => { const indexStr = `${index}`; - const disabledAll = { - 0: { disabled: true }, - 1: { disabled: true }, - 2: { disabled: true }, - 3: { disabled: true }, - }; + const disabledAll = Object.keys(answers).map(() => ({ disabled: true })); const userInputCopy = [...userInput]; if (answerSelectionType === 'single') { if (userInputCopy[currentQuestionIndex] === undefined) { @@ -158,7 +153,7 @@ export const checkAnswer = (index, correctAnswer, answerSelectionType, answers, setUserInput(userInputCopy); }; -export const selectAnswer = (index, correctAnswer, answerSelectionType, { +export const selectAnswer = (index, correctAnswer, answerSelectionType, answers, { userInput, currentQuestionIndex, setButtons, @@ -169,12 +164,8 @@ export const selectAnswer = (index, correctAnswer, answerSelectionType, { setIncorrect, setUserInput, }) => { - const selectedButtons = { - 0: { selected: false }, - 1: { selected: false }, - 2: { selected: false }, - 3: { selected: false }, - }; + console.log('userInput', userInput); + const selectedButtons = Object.keys(answers).map(() => ({ selected: true })); const userInputCopy = [...userInput]; if (answerSelectionType === 'single') { correctAnswer = Number(correctAnswer); From 09b5ee4230f3bebec68b8b10e33c02cdfaca47c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=C9=A8=D5=BC=C9=A2=D3=84=D5=A1=D6=85=D5=BC=C9=A2?= Date: Tue, 6 Feb 2024 21:42:36 +0800 Subject: [PATCH 3/4] chore(lib): remove console log --- src/lib/core-components/helpers.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/core-components/helpers.jsx b/src/lib/core-components/helpers.jsx index 70bd9b7..ee84dc4 100644 --- a/src/lib/core-components/helpers.jsx +++ b/src/lib/core-components/helpers.jsx @@ -164,7 +164,6 @@ export const selectAnswer = (index, correctAnswer, answerSelectionType, answers, setIncorrect, setUserInput, }) => { - console.log('userInput', userInput); const selectedButtons = Object.keys(answers).map(() => ({ selected: true })); const userInputCopy = [...userInput]; if (answerSelectionType === 'single') { From 02a95d7c8aac8bcdf5ae2f7ff1254a4350ead600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=C9=A8=D5=BC=C9=A2=D3=84=D5=A1=D6=85=D5=BC=C9=A2?= Date: Tue, 6 Feb 2024 21:43:12 +0800 Subject: [PATCH 4/4] fix(lib): set selected to false --- src/lib/core-components/helpers.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/core-components/helpers.jsx b/src/lib/core-components/helpers.jsx index ee84dc4..7b4e492 100644 --- a/src/lib/core-components/helpers.jsx +++ b/src/lib/core-components/helpers.jsx @@ -164,7 +164,7 @@ export const selectAnswer = (index, correctAnswer, answerSelectionType, answers, setIncorrect, setUserInput, }) => { - const selectedButtons = Object.keys(answers).map(() => ({ selected: true })); + const selectedButtons = Object.keys(answers).map(() => ({ selected: false })); const userInputCopy = [...userInput]; if (answerSelectionType === 'single') { correctAnswer = Number(correctAnswer);