@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.
@@ -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, _b, _c, _d, _e;
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), isLastAnswer: !!((_a = action.payload) === null || _a === void 0 ? void 0 : _a.isLastQuestion), isQuizCompleted: false });
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), isLastAnswer: !!((_b = action.payload) === null || _b === void 0 ? void 0 : _b.isLastQuestion), isQuizCompleted: false });
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), isLastAnswer: !!((_c = action.payload) === null || _c === void 0 ? void 0 : _c.isLastQuestion), isQuizCompleted: false });
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), isLastAnswer: !!((_d = action.payload) === null || _d === void 0 ? void 0 : _d.isLastQuestion), isQuizCompleted: false });
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 = (_e = Object.values(state.answerInputs)) === null || _e === void 0 ? void 0 : _e[lastAnswerInputIndex];
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)], isLastAnswer: false, isQuizCompleted: false });
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);
@@ -31,7 +31,6 @@ const useQuiz = (quizOptions) => {
31
31
  return Object.assign(Object.assign({ cioClient, state: {
32
32
  answers: {
33
33
  inputs: quizLocalState.answerInputs,
34
- isLastAnswer: quizLocalState.isLastAnswer,
35
34
  },
36
35
  quiz: {
37
36
  requestState: quizApiState.quizRequestState,
@@ -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 (quizLocalState.isLastAnswer || skipToResults) {
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,
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.9.6';
3
+ exports.default = '1.9.7';
@@ -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
  }
@@ -30,7 +30,6 @@ const useQuiz = (quizOptions) => {
30
30
  state: {
31
31
  answers: {
32
32
  inputs: quizLocalState.answerInputs,
33
- isLastAnswer: quizLocalState.isLastAnswer,
34
33
  },
35
34
  quiz: {
36
35
  requestState: quizApiState.quizRequestState,
@@ -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 (quizLocalState.isLastAnswer || skipToResults) {
41
+ if (skipToResults) {
42
42
  await dispatchQuizResults();
43
43
  }
44
44
  else {
@@ -60,8 +60,7 @@ export const getMockState = (question) => ({
60
60
  type: question?.type,
61
61
  value: '',
62
62
  },
63
- },
64
- isLastAnswer: false,
63
+ }, // Key is the question Id and value is the answer input
65
64
  },
66
65
  quiz: {
67
66
  requestState: RequestStates.Success,
@@ -1 +1 @@
1
- export default '1.9.6';
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>;
@@ -5,7 +5,6 @@ export type QuizLocalReducerState = {
5
5
  answers: Answers;
6
6
  answerInputs: AnswerInputState;
7
7
  prevAnswerInputs: AnswerInputState;
8
- isLastAnswer: boolean;
9
8
  isQuizCompleted: boolean;
10
9
  quizVersionId?: string;
11
10
  quizSessionId?: string;
@@ -58,7 +58,6 @@ export interface IQuizProps {
58
58
  export interface QuizReturnState {
59
59
  answers: {
60
60
  inputs: AnswerInputState;
61
- isLastAnswer: boolean;
62
61
  };
63
62
  quiz: {
64
63
  requestState: RequestStates;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.9.6";
1
+ declare const _default: "1.9.7";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.9.6",
3
+ "version": "1.9.7",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",