@constructor-io/constructorio-ui-quizzes 1.17.16 → 1.17.17
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 +11 -11
- package/lib/cjs/hooks/usePrevious.js +13 -0
- package/lib/cjs/hooks/useQuiz.js +20 -0
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/hooks/usePrevious.js +10 -0
- package/lib/mjs/hooks/useQuiz.js +20 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/hooks/usePrevious.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
function usePrevious(value) {
|
|
5
|
+
const latest = (0, react_1.useRef)(value);
|
|
6
|
+
const previous = (0, react_1.useRef)();
|
|
7
|
+
if (latest.current !== value) {
|
|
8
|
+
previous.current = latest.current;
|
|
9
|
+
}
|
|
10
|
+
latest.current = value;
|
|
11
|
+
return previous.current;
|
|
12
|
+
}
|
|
13
|
+
exports.default = usePrevious;
|
package/lib/cjs/hooks/useQuiz.js
CHANGED
|
@@ -8,6 +8,9 @@ const usePropsGetters_1 = tslib_1.__importDefault(require("./usePropsGetters"));
|
|
|
8
8
|
const usePrimaryColorStyles_1 = tslib_1.__importDefault(require("./usePrimaryColorStyles"));
|
|
9
9
|
const useQuizEvents_1 = tslib_1.__importDefault(require("./useQuizEvents"));
|
|
10
10
|
const useQuizState_1 = tslib_1.__importDefault(require("./useQuizState"));
|
|
11
|
+
const usePrevious_1 = tslib_1.__importDefault(require("./usePrevious"));
|
|
12
|
+
const actions_1 = require("../components/CioQuiz/actions");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
11
14
|
const useQuiz = (quizOptions) => {
|
|
12
15
|
var _a;
|
|
13
16
|
const { apiKey, cioJsClient, primaryColor, resultsPageOptions } = quizOptions;
|
|
@@ -29,6 +32,23 @@ const useQuiz = (quizOptions) => {
|
|
|
29
32
|
quizEvents.hydrateQuiz();
|
|
30
33
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
34
|
}, []);
|
|
35
|
+
const { quizId } = quizOptions;
|
|
36
|
+
const { dispatchApiState, dispatchLocalState } = quizState;
|
|
37
|
+
const prevQuizId = (0, usePrevious_1.default)(quizId);
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
if (quizId === prevQuizId)
|
|
40
|
+
return;
|
|
41
|
+
if (!prevQuizId)
|
|
42
|
+
return;
|
|
43
|
+
dispatchLocalState({
|
|
44
|
+
type: actions_1.QuestionTypes.Reset,
|
|
45
|
+
});
|
|
46
|
+
dispatchApiState({
|
|
47
|
+
type: actions_1.QuizAPIActionTypes.RESET_QUIZ,
|
|
48
|
+
});
|
|
49
|
+
(0, utils_1.resetQuizSessionStorageState)(quizSessionStorageState.key);
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
+
}, [quizId, prevQuizId]);
|
|
32
52
|
return Object.assign(Object.assign({ cioClient, state: {
|
|
33
53
|
answers: {
|
|
34
54
|
inputs: quizLocalState.answerInputs,
|
package/lib/cjs/version.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
export default function usePrevious(value) {
|
|
3
|
+
const latest = useRef(value);
|
|
4
|
+
const previous = useRef();
|
|
5
|
+
if (latest.current !== value) {
|
|
6
|
+
previous.current = latest.current;
|
|
7
|
+
}
|
|
8
|
+
latest.current = value;
|
|
9
|
+
return previous.current;
|
|
10
|
+
}
|
package/lib/mjs/hooks/useQuiz.js
CHANGED
|
@@ -5,6 +5,9 @@ import usePropsGetters from './usePropsGetters';
|
|
|
5
5
|
import usePrimaryColorStyles from './usePrimaryColorStyles';
|
|
6
6
|
import useQuizEvents from './useQuizEvents';
|
|
7
7
|
import useQuizState from './useQuizState';
|
|
8
|
+
import usePrevious from './usePrevious';
|
|
9
|
+
import { QuestionTypes, QuizAPIActionTypes } from '../components/CioQuiz/actions';
|
|
10
|
+
import { resetQuizSessionStorageState } from '../utils';
|
|
8
11
|
const useQuiz = (quizOptions) => {
|
|
9
12
|
const { apiKey, cioJsClient, primaryColor, resultsPageOptions } = quizOptions;
|
|
10
13
|
// Log console errors for required parameters quizId
|
|
@@ -25,6 +28,23 @@ const useQuiz = (quizOptions) => {
|
|
|
25
28
|
quizEvents.hydrateQuiz();
|
|
26
29
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
30
|
}, []);
|
|
31
|
+
const { quizId } = quizOptions;
|
|
32
|
+
const { dispatchApiState, dispatchLocalState } = quizState;
|
|
33
|
+
const prevQuizId = usePrevious(quizId);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (quizId === prevQuizId)
|
|
36
|
+
return;
|
|
37
|
+
if (!prevQuizId)
|
|
38
|
+
return;
|
|
39
|
+
dispatchLocalState({
|
|
40
|
+
type: QuestionTypes.Reset,
|
|
41
|
+
});
|
|
42
|
+
dispatchApiState({
|
|
43
|
+
type: QuizAPIActionTypes.RESET_QUIZ,
|
|
44
|
+
});
|
|
45
|
+
resetQuizSessionStorageState(quizSessionStorageState.key);
|
|
46
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
|
+
}, [quizId, prevQuizId]);
|
|
28
48
|
return {
|
|
29
49
|
cioClient,
|
|
30
50
|
state: {
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.17.
|
|
1
|
+
export default '1.17.17';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function usePrevious<Type>(value: Type): Type | undefined;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.17.
|
|
1
|
+
declare const _default: "1.17.17";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED