Skip to content

Commit

Permalink
Merge pull request #212 from wingkwong/fix/dynamic-disabledAll
Browse files Browse the repository at this point in the history
fix: dynamic disabled all / select buttons
  • Loading branch information
wingkwong authored Feb 6, 2024
2 parents 884e6f5 + 02a95d7 commit e40ffd7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lib/Core.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 3 additions & 13 deletions src/lib/core-components/helpers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -169,12 +164,7 @@ export const selectAnswer = (index, correctAnswer, answerSelectionType, {
setIncorrect,
setUserInput,
}) => {
const selectedButtons = {
0: { selected: false },
1: { selected: false },
2: { selected: false },
3: { selected: false },
};
const selectedButtons = Object.keys(answers).map(() => ({ selected: false }));
const userInputCopy = [...userInput];
if (answerSelectionType === 'single') {
correctAnswer = Number(correctAnswer);
Expand Down

0 comments on commit e40ffd7

Please sign in to comment.