Skip to content

Commit 5e95a87

Browse files
authored
Merge pull request #191 from wingkwong/develop
0.7.1 Release
2 parents 211c56f + fbea58e commit 5e95a87

File tree

9 files changed

+285
-229
lines changed

9 files changed

+285
-229
lines changed

CHANGELOG.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# CHANGELOG
22

3+
## 0.7.1
4+
5+
- Bumped dependencies
6+
- Fixed duplicate question on shuffle
7+
- Fixed missing correct answers when setting showInstantfeedback to true
8+
39
## 0.7.0
410

5-
- Fix lint issues
6-
- Refactor webpack, filter design
7-
- Update demo site
8-
- Add rollup
9-
- Bump dependencies
11+
- Fixed lint issues
12+
- Refactored webpack, filter design
13+
- Updated demo site
14+
- Added rollup
15+
- Bumped dependencies
1016

1117
## 0.6.0
1218

13-
- Display marks in questions (marksOfQuestion)
14-
- Bump dependencies
15-
- Add renovate
16-
- Add ShuffleAnswer
17-
- Add total count of questions
19+
- Displayed marks in questions (marksOfQuestion)
20+
- Bumped dependencies
21+
- Added renovate
22+
- Added ShuffleAnswer
23+
- Added total count of questions
1824
- Responsive Design
19-
- Revise demo site
20-
- Fix Scrolling
25+
- Revised demo site
26+
- Fixed Scrolling
2127

2228
## 0.5.1
2329

dist/index.es.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+229-205
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-quiz-component",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "React Quiz Component",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",
@@ -37,7 +37,7 @@
3737
"eslint-plugin-jsx-a11y": "^6.5.1",
3838
"eslint-plugin-react": "^7.27.1",
3939
"eslint-plugin-react-hooks": "^4.3.0",
40-
"html-webpack-plugin": "5.5.3",
40+
"html-webpack-plugin": "5.6.0",
4141
"mini-css-extract-plugin": "^2.7.6",
4242
"css-minimizer-webpack-plugin": "^5.0.1",
4343
"prop-types": "^15.7.2",

src/docs/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function App() {
1515
quiz={quiz}
1616
shuffle
1717
shuffleAnswer
18-
// showInstantFeedback
18+
showInstantFeedback
1919
// continueTillCorrect
2020
onComplete={setQuizResult}
2121
onQuestionSubmit={(obj) => console.log('user question results:', obj)}

src/lib/Core.jsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Core({
3737

3838
useEffect(() => {
3939
setActiveQuestion(questions[currentQuestionIndex]);
40-
}, [currentQuestionIndex]);
40+
}, [currentQuestionIndex, questions]);
4141

4242
useEffect(() => {
4343
const { answerSelectionType } = activeQuestion;
@@ -166,6 +166,18 @@ function Core({
166166
);
167167
};
168168

169+
const isCorrectCheck = (index, correctAnswerIndex) => {
170+
if (typeof correctAnswerIndex === 'string') {
171+
return index === Number(correctAnswerIndex);
172+
}
173+
174+
if (typeof correctAnswerIndex === 'object') {
175+
return correctAnswerIndex.find((element) => element === index) !== undefined;
176+
}
177+
178+
return false;
179+
};
180+
169181
const renderQuizResultQuestions = useCallback(() => {
170182
let filteredQuestions;
171183
let filteredUserInput;
@@ -205,7 +217,7 @@ function Core({
205217
answers, correctAnswer, questionType, questionIndex,
206218
} = question;
207219
let { answerSelectionType } = question;
208-
const onClickAnswer = (index) => checkAnswer(index + 1, correctAnswer, answerSelectionType, {
220+
const onClickAnswer = (index) => checkAnswer(index + 1, correctAnswer, answerSelectionType, answers, {
209221
userInput,
210222
userAttempt,
211223
currentQuestionIndex,
@@ -255,7 +267,11 @@ function Core({
255267
<button
256268
type="button"
257269
disabled={answerButtons[index].disabled || false}
258-
className={`${answerButtons[index].className} answerBtn btn`}
270+
className={`${answerButtons[index].className} answerBtn btn ${
271+
isCorrectCheck(index + 1, correctAnswer) && showInstantFeedback
272+
? 'correct'
273+
: ''
274+
}`}
259275
onClick={() => (revealAnswerOnSubmit ? onSelectAnswer(index) : onClickAnswer(index))}
260276
>
261277
{questionType === 'text' && <span>{answer}</span>}

src/lib/core-components/helpers.jsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const rawMarkup = (data) => {
66
return { __html: snarkdown(sanitizer(data)) };
77
};
88

9-
export const checkAnswer = (index, correctAnswer, answerSelectionType, {
9+
export const checkAnswer = (index, correctAnswer, answerSelectionType, answers, {
1010
userInput,
1111
userAttempt,
1212
currentQuestionIndex,
@@ -125,6 +125,15 @@ export const checkAnswer = (index, correctAnswer, answerSelectionType, {
125125
}
126126
}
127127

128+
for (let i = 0; i < answers.length; i += 1) {
129+
if (correctAnswer.includes(i + 1)) {
130+
setButtons((prevState) => ({
131+
...prevState,
132+
[i]: {},
133+
}));
134+
}
135+
}
136+
128137
if (cnt === maxNumberOfMultipleSelection) {
129138
correct.push(currentQuestionIndex);
130139

@@ -210,6 +219,7 @@ export const selectAnswer = (index, correctAnswer, answerSelectionType, {
210219

211220
if (userInputCopy[currentQuestionIndex].length === correctAnswer.length) {
212221
let exactMatch = true;
222+
// eslint-disable-next-line no-restricted-syntax
213223
for (const input of userInput[currentQuestionIndex]) {
214224
if (!correctAnswer.includes(input)) {
215225
exactMatch = false;

0 commit comments

Comments
 (0)