@micromag/data 0.3.679 → 0.3.699
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/es/index.js +43 -16
- package/package.json +2 -2
package/es/index.js
CHANGED
|
@@ -9,10 +9,10 @@ import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
|
|
|
9
9
|
import { generatePath } from '@folklore/routes';
|
|
10
10
|
import queryString from 'query-string';
|
|
11
11
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
12
|
+
import { useVisitor, useStory } from '@micromag/core/contexts';
|
|
12
13
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
13
14
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
14
15
|
import isString from 'lodash/isString';
|
|
15
|
-
import { useVisitor, useStory } from '@micromag/core/contexts';
|
|
16
16
|
|
|
17
17
|
var Base = /*#__PURE__*/function () {
|
|
18
18
|
function Base() {
|
|
@@ -230,9 +230,10 @@ var QuizApi = /*#__PURE__*/function (_Base) {
|
|
|
230
230
|
return _createClass(QuizApi, [{
|
|
231
231
|
key: "results",
|
|
232
232
|
value: function results(screenId) {
|
|
233
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
233
234
|
return this.requestGet(this.route('results', {
|
|
234
235
|
screen: screenId
|
|
235
|
-
}));
|
|
236
|
+
}), query);
|
|
236
237
|
}
|
|
237
238
|
}, {
|
|
238
239
|
key: "create",
|
|
@@ -292,6 +293,10 @@ ApiProvider.defaultProps = defaultProps$1;
|
|
|
292
293
|
var useContributionCreate = function useContributionCreate() {
|
|
293
294
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
294
295
|
screenId = _ref.screenId,
|
|
296
|
+
_ref$visitorId = _ref.visitorId,
|
|
297
|
+
providedVisitorId = _ref$visitorId === void 0 ? null : _ref$visitorId,
|
|
298
|
+
_ref$storyId = _ref.storyId,
|
|
299
|
+
providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
|
|
295
300
|
_ref$onSuccess = _ref.onSuccess,
|
|
296
301
|
onSuccess = _ref$onSuccess === void 0 ? null : _ref$onSuccess;
|
|
297
302
|
var api = useApi();
|
|
@@ -299,13 +304,20 @@ var useContributionCreate = function useContributionCreate() {
|
|
|
299
304
|
_useState2 = _slicedToArray(_useState, 2),
|
|
300
305
|
creating = _useState2[0],
|
|
301
306
|
setCreating = _useState2[1];
|
|
307
|
+
var _ref2 = useVisitor() || {},
|
|
308
|
+
visitorId = _ref2.id;
|
|
309
|
+
var _ref3 = useStory() || {},
|
|
310
|
+
storyId = _ref3.id,
|
|
311
|
+
documentId = _ref3.document_id;
|
|
302
312
|
var create = useCallback(function (data) {
|
|
303
313
|
if (api === null) {
|
|
304
314
|
return null;
|
|
305
315
|
}
|
|
306
316
|
setCreating(true);
|
|
307
317
|
return api.contributions.create(_objectSpread({
|
|
308
|
-
screen_id: screenId
|
|
318
|
+
screen_id: screenId,
|
|
319
|
+
visitor_id: providedVisitorId || visitorId,
|
|
320
|
+
story_id: documentId || providedStoryId || storyId
|
|
309
321
|
}, data)).then(function (response) {
|
|
310
322
|
setCreating(false);
|
|
311
323
|
if (onSuccess !== null) {
|
|
@@ -313,7 +325,7 @@ var useContributionCreate = function useContributionCreate() {
|
|
|
313
325
|
}
|
|
314
326
|
return response;
|
|
315
327
|
});
|
|
316
|
-
}, [api, setCreating, onSuccess, screenId]);
|
|
328
|
+
}, [api, setCreating, onSuccess, screenId, visitorId, storyId, providedVisitorId, providedStoryId]);
|
|
317
329
|
return {
|
|
318
330
|
create: create,
|
|
319
331
|
creating: creating
|
|
@@ -380,9 +392,14 @@ var _excluded$3 = ["data"];
|
|
|
380
392
|
var useContributions = function useContributions() {
|
|
381
393
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
382
394
|
screenId = _ref.screenId,
|
|
395
|
+
_ref$storyId = _ref.storyId,
|
|
396
|
+
providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
|
|
383
397
|
_ref$opts = _ref.opts,
|
|
384
398
|
opts = _ref$opts === void 0 ? {} : _ref$opts;
|
|
385
399
|
var api = useApi();
|
|
400
|
+
var _ref2 = useStory() || {},
|
|
401
|
+
storyId = _ref2.id,
|
|
402
|
+
documentId = _ref2.document_id;
|
|
386
403
|
var _useState = useState(_toConsumableArray(new Array(10)).map(function (el, i) {
|
|
387
404
|
return {
|
|
388
405
|
name: "Nom ".concat(i + 1),
|
|
@@ -392,13 +409,15 @@ var useContributions = function useContributions() {
|
|
|
392
409
|
_useState2 = _slicedToArray(_useState, 1),
|
|
393
410
|
defaultContributions = _useState2[0];
|
|
394
411
|
var loader = useCallback(function () {
|
|
395
|
-
return api !== null ? api.contributions.get(screenId
|
|
396
|
-
|
|
397
|
-
|
|
412
|
+
return api !== null ? api.contributions.get(screenId, {
|
|
413
|
+
story_id: documentId || providedStoryId || storyId
|
|
414
|
+
}) : null;
|
|
415
|
+
}, [api, screenId, documentId, providedStoryId, storyId]);
|
|
416
|
+
var _ref3 = api !== null ? useData(loader, opts) : {
|
|
398
417
|
data: null
|
|
399
418
|
},
|
|
400
|
-
data =
|
|
401
|
-
request = _objectWithoutProperties(
|
|
419
|
+
data = _ref3.data,
|
|
420
|
+
request = _objectWithoutProperties(_ref3, _excluded$3);
|
|
402
421
|
return _objectSpread({
|
|
403
422
|
contributions: data || defaultContributions
|
|
404
423
|
}, request);
|
|
@@ -979,17 +998,24 @@ var _excluded = ["data"];
|
|
|
979
998
|
var useQuiz = function useQuiz() {
|
|
980
999
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
981
1000
|
screenId = _ref.screenId,
|
|
1001
|
+
_ref$storyId = _ref.storyId,
|
|
1002
|
+
providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
|
|
982
1003
|
_ref$opts = _ref.opts,
|
|
983
1004
|
opts = _ref$opts === void 0 ? {} : _ref$opts;
|
|
984
1005
|
var api = useApi();
|
|
1006
|
+
var _ref2 = useStory() || {},
|
|
1007
|
+
storyId = _ref2.id,
|
|
1008
|
+
documentId = _ref2.document_id;
|
|
985
1009
|
var loader = useCallback(function () {
|
|
986
|
-
return api !== null ? api.quiz.results(screenId
|
|
987
|
-
|
|
988
|
-
|
|
1010
|
+
return api !== null ? api.quiz.results(screenId, {
|
|
1011
|
+
story_id: documentId || providedStoryId || storyId
|
|
1012
|
+
}) : null;
|
|
1013
|
+
}, [api, screenId, documentId, providedStoryId, storyId]);
|
|
1014
|
+
var _ref3 = api !== null ? useData(loader, opts) : {
|
|
989
1015
|
data: null
|
|
990
1016
|
},
|
|
991
|
-
data =
|
|
992
|
-
request = _objectWithoutProperties(
|
|
1017
|
+
data = _ref3.data,
|
|
1018
|
+
request = _objectWithoutProperties(_ref3, _excluded);
|
|
993
1019
|
return _objectSpread({
|
|
994
1020
|
quiz: data || []
|
|
995
1021
|
}, request);
|
|
@@ -1012,7 +1038,8 @@ var useQuizCreate = function useQuizCreate() {
|
|
|
1012
1038
|
var _ref2 = useVisitor() || {},
|
|
1013
1039
|
visitorId = _ref2.id;
|
|
1014
1040
|
var _ref3 = useStory() || {},
|
|
1015
|
-
storyId = _ref3.id
|
|
1041
|
+
storyId = _ref3.id,
|
|
1042
|
+
documentId = _ref3.document_id;
|
|
1016
1043
|
var create = useCallback(function (data) {
|
|
1017
1044
|
if (api === null) {
|
|
1018
1045
|
return null;
|
|
@@ -1021,7 +1048,7 @@ var useQuizCreate = function useQuizCreate() {
|
|
|
1021
1048
|
return api.quiz.create(_objectSpread({
|
|
1022
1049
|
screen_id: screenId,
|
|
1023
1050
|
visitor_id: providedVisitorId || visitorId,
|
|
1024
|
-
story_id: providedStoryId || storyId
|
|
1051
|
+
story_id: documentId || providedStoryId || storyId
|
|
1025
1052
|
}, data)).then(function (response) {
|
|
1026
1053
|
setCreating(false);
|
|
1027
1054
|
if (onSuccess !== null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/data",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.699",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"access": "public",
|
|
69
69
|
"registry": "https://registry.npmjs.org/"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "8d69620bde11630e19004ac76f6ed1454fc33516"
|
|
72
72
|
}
|