@constructor-io/constructorio-ui-quizzes 1.9.6 → 1.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constructorio-ui-quizzes-bundled.js +9 -9
- package/lib/cjs/components/CioQuiz/quizLocalReducer.js +7 -8
- package/lib/cjs/hooks/useQuiz.js +0 -1
- package/lib/cjs/hooks/useQuizEvents/useQuizAnswerChangeHandler.js +0 -3
- package/lib/cjs/hooks/useQuizState/useQuizApiState.js +1 -1
- package/lib/cjs/stories/Quiz/tests/mocks.js +1 -2
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CioQuiz/quizLocalReducer.js +0 -6
- package/lib/mjs/hooks/useQuiz.js +0 -1
- package/lib/mjs/hooks/useQuizEvents/useQuizAnswerChangeHandler.js +0 -3
- package/lib/mjs/hooks/useQuizState/useQuizApiState.js +1 -1
- package/lib/mjs/stories/Quiz/tests/mocks.js +1 -2
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/CioQuiz/actions.d.ts +0 -1
- package/lib/types/components/CioQuiz/quizLocalReducer.d.ts +0 -1
- package/lib/types/types.d.ts +0 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,6 @@ exports.initialState = {
|
|
|
6
6
|
answers: [],
|
|
7
7
|
answerInputs: {},
|
|
8
8
|
prevAnswerInputs: {},
|
|
9
|
-
isLastAnswer: false,
|
|
10
9
|
isQuizCompleted: false,
|
|
11
10
|
};
|
|
12
11
|
function answerInputReducer(state, action) {
|
|
@@ -16,21 +15,21 @@ function answerInputReducer(state, action) {
|
|
|
16
15
|
} });
|
|
17
16
|
}
|
|
18
17
|
function quizLocalReducer(state, action) {
|
|
19
|
-
var _a
|
|
18
|
+
var _a;
|
|
20
19
|
switch (action.type) {
|
|
21
20
|
case actions_1.QuestionTypes.OpenText:
|
|
22
|
-
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action),
|
|
21
|
+
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action), isQuizCompleted: false });
|
|
23
22
|
case actions_1.QuestionTypes.Cover:
|
|
24
|
-
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action),
|
|
23
|
+
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action), isQuizCompleted: false });
|
|
25
24
|
case actions_1.QuestionTypes.SingleSelect:
|
|
26
|
-
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action),
|
|
25
|
+
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action), isQuizCompleted: false });
|
|
27
26
|
case actions_1.QuestionTypes.MultipleSelect:
|
|
28
|
-
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action),
|
|
27
|
+
return Object.assign(Object.assign({}, state), { answerInputs: answerInputReducer(state.answerInputs, action), isQuizCompleted: false });
|
|
29
28
|
case actions_1.QuestionTypes.Next: {
|
|
30
29
|
const { answers, answerInputs } = state;
|
|
31
30
|
const newAnswers = [...answers];
|
|
32
31
|
const lastAnswerInputIndex = answers.length;
|
|
33
|
-
const currentAnswerInput = (
|
|
32
|
+
const currentAnswerInput = (_a = Object.values(state.answerInputs)) === null || _a === void 0 ? void 0 : _a[lastAnswerInputIndex];
|
|
34
33
|
switch (currentAnswerInput.type) {
|
|
35
34
|
case actions_1.QuestionTypes.OpenText:
|
|
36
35
|
newAnswers.push(['true']);
|
|
@@ -72,7 +71,7 @@ function quizLocalReducer(state, action) {
|
|
|
72
71
|
}
|
|
73
72
|
case actions_1.QuestionTypes.Back: {
|
|
74
73
|
const prevAnswerInputs = Object.assign({}, state.prevAnswerInputs);
|
|
75
|
-
return Object.assign(Object.assign({}, state), { answerInputs: prevAnswerInputs, answers: [...state.answers.slice(0, -1)],
|
|
74
|
+
return Object.assign(Object.assign({}, state), { answerInputs: prevAnswerInputs, answers: [...state.answers.slice(0, -1)], isQuizCompleted: false });
|
|
76
75
|
}
|
|
77
76
|
case actions_1.QuestionTypes.Reset:
|
|
78
77
|
return Object.assign({}, exports.initialState);
|
package/lib/cjs/hooks/useQuiz.js
CHANGED
|
@@ -15,7 +15,6 @@ const useQuizAnswerChangeHandler = (quizApiState, dispatchLocalState) => {
|
|
|
15
15
|
payload: {
|
|
16
16
|
questionId: currentQuestion.next_question.id,
|
|
17
17
|
input: '',
|
|
18
|
-
isLastQuestion: currentQuestion.is_last_question,
|
|
19
18
|
},
|
|
20
19
|
});
|
|
21
20
|
break;
|
|
@@ -25,7 +24,6 @@ const useQuizAnswerChangeHandler = (quizApiState, dispatchLocalState) => {
|
|
|
25
24
|
payload: {
|
|
26
25
|
questionId: currentQuestion.next_question.id,
|
|
27
26
|
input: payload,
|
|
28
|
-
isLastQuestion: currentQuestion.is_last_question,
|
|
29
27
|
},
|
|
30
28
|
});
|
|
31
29
|
break;
|
|
@@ -36,7 +34,6 @@ const useQuizAnswerChangeHandler = (quizApiState, dispatchLocalState) => {
|
|
|
36
34
|
payload: {
|
|
37
35
|
questionId: currentQuestion.next_question.id,
|
|
38
36
|
input: payload,
|
|
39
|
-
isLastQuestion: currentQuestion.is_last_question,
|
|
40
37
|
},
|
|
41
38
|
});
|
|
42
39
|
break;
|
|
@@ -41,7 +41,7 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults,
|
|
|
41
41
|
dispatchApiState({
|
|
42
42
|
type: actions_1.QuizAPIActionTypes.SET_IS_LOADING,
|
|
43
43
|
});
|
|
44
|
-
if (
|
|
44
|
+
if (skipToResults) {
|
|
45
45
|
yield dispatchQuizResults();
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
@@ -48,8 +48,7 @@ const getMockState = (question) => ({
|
|
|
48
48
|
type: question === null || question === void 0 ? void 0 : question.type,
|
|
49
49
|
value: '',
|
|
50
50
|
},
|
|
51
|
-
},
|
|
52
|
-
isLastAnswer: false,
|
|
51
|
+
}, // Key is the question Id and value is the answer input
|
|
53
52
|
},
|
|
54
53
|
quiz: {
|
|
55
54
|
requestState: constants_1.RequestStates.Success,
|
package/lib/cjs/version.js
CHANGED
|
@@ -3,7 +3,6 @@ export const initialState = {
|
|
|
3
3
|
answers: [],
|
|
4
4
|
answerInputs: {},
|
|
5
5
|
prevAnswerInputs: {},
|
|
6
|
-
isLastAnswer: false,
|
|
7
6
|
isQuizCompleted: false,
|
|
8
7
|
};
|
|
9
8
|
function answerInputReducer(state, action) {
|
|
@@ -21,28 +20,24 @@ export default function quizLocalReducer(state, action) {
|
|
|
21
20
|
return {
|
|
22
21
|
...state,
|
|
23
22
|
answerInputs: answerInputReducer(state.answerInputs, action),
|
|
24
|
-
isLastAnswer: !!action.payload?.isLastQuestion,
|
|
25
23
|
isQuizCompleted: false,
|
|
26
24
|
};
|
|
27
25
|
case QuestionTypes.Cover:
|
|
28
26
|
return {
|
|
29
27
|
...state,
|
|
30
28
|
answerInputs: answerInputReducer(state.answerInputs, action),
|
|
31
|
-
isLastAnswer: !!action.payload?.isLastQuestion,
|
|
32
29
|
isQuizCompleted: false,
|
|
33
30
|
};
|
|
34
31
|
case QuestionTypes.SingleSelect:
|
|
35
32
|
return {
|
|
36
33
|
...state,
|
|
37
34
|
answerInputs: answerInputReducer(state.answerInputs, action),
|
|
38
|
-
isLastAnswer: !!action.payload?.isLastQuestion,
|
|
39
35
|
isQuizCompleted: false,
|
|
40
36
|
};
|
|
41
37
|
case QuestionTypes.MultipleSelect:
|
|
42
38
|
return {
|
|
43
39
|
...state,
|
|
44
40
|
answerInputs: answerInputReducer(state.answerInputs, action),
|
|
45
|
-
isLastAnswer: !!action.payload?.isLastQuestion,
|
|
46
41
|
isQuizCompleted: false,
|
|
47
42
|
};
|
|
48
43
|
case QuestionTypes.Next: {
|
|
@@ -103,7 +98,6 @@ export default function quizLocalReducer(state, action) {
|
|
|
103
98
|
...state,
|
|
104
99
|
answerInputs: prevAnswerInputs,
|
|
105
100
|
answers: [...state.answers.slice(0, -1)],
|
|
106
|
-
isLastAnswer: false,
|
|
107
101
|
isQuizCompleted: false,
|
|
108
102
|
};
|
|
109
103
|
}
|
package/lib/mjs/hooks/useQuiz.js
CHANGED
|
@@ -12,7 +12,6 @@ const useQuizAnswerChangeHandler = (quizApiState, dispatchLocalState) => {
|
|
|
12
12
|
payload: {
|
|
13
13
|
questionId: currentQuestion.next_question.id,
|
|
14
14
|
input: '',
|
|
15
|
-
isLastQuestion: currentQuestion.is_last_question,
|
|
16
15
|
},
|
|
17
16
|
});
|
|
18
17
|
break;
|
|
@@ -22,7 +21,6 @@ const useQuizAnswerChangeHandler = (quizApiState, dispatchLocalState) => {
|
|
|
22
21
|
payload: {
|
|
23
22
|
questionId: currentQuestion.next_question.id,
|
|
24
23
|
input: payload,
|
|
25
|
-
isLastQuestion: currentQuestion.is_last_question,
|
|
26
24
|
},
|
|
27
25
|
});
|
|
28
26
|
break;
|
|
@@ -33,7 +31,6 @@ const useQuizAnswerChangeHandler = (quizApiState, dispatchLocalState) => {
|
|
|
33
31
|
payload: {
|
|
34
32
|
questionId: currentQuestion.next_question.id,
|
|
35
33
|
input: payload,
|
|
36
|
-
isLastQuestion: currentQuestion.is_last_question,
|
|
37
34
|
},
|
|
38
35
|
});
|
|
39
36
|
break;
|
|
@@ -38,7 +38,7 @@ const useQuizApiState = (quizOptions, cioClient, quizLocalState, skipToResults,
|
|
|
38
38
|
dispatchApiState({
|
|
39
39
|
type: QuizAPIActionTypes.SET_IS_LOADING,
|
|
40
40
|
});
|
|
41
|
-
if (
|
|
41
|
+
if (skipToResults) {
|
|
42
42
|
await dispatchQuizResults();
|
|
43
43
|
}
|
|
44
44
|
else {
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.9.
|
|
1
|
+
export default '1.9.7';
|
|
@@ -15,7 +15,6 @@ export declare enum QuestionTypes {
|
|
|
15
15
|
export interface QuestionAnswer<Value> {
|
|
16
16
|
questionId: number;
|
|
17
17
|
input: Value;
|
|
18
|
-
isLastQuestion?: boolean;
|
|
19
18
|
}
|
|
20
19
|
export type SelectQuestionPayload = QuestionAnswer<Omit<QuestionOption, 'attribute' | 'images'>[]>;
|
|
21
20
|
export type OpenTextQuestionPayload = QuestionAnswer<string>;
|
package/lib/types/types.d.ts
CHANGED
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.9.
|
|
1
|
+
declare const _default: "1.9.7";
|
|
2
2
|
export default _default;
|