@micromag/data 0.4.69 → 0.4.74
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 +915 -816
- package/package.json +8 -8
package/es/index.js
CHANGED
|
@@ -1,126 +1,100 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
4
|
-
import _callSuper from '@babel/runtime/helpers/callSuper';
|
|
5
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
6
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
1
|
+
import { c } from 'react/compiler-runtime';
|
|
2
|
+
import React, { useContext, useState, useCallback, useEffect, useRef, useMemo } from 'react';
|
|
7
3
|
import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
|
|
8
4
|
import { generatePath } from '@folklore/routes';
|
|
9
5
|
import queryString from 'query-string';
|
|
10
6
|
import { jsx } from 'react/jsx-runtime';
|
|
11
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
12
7
|
import { useVisitor, useStory } from '@micromag/core/contexts';
|
|
13
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
14
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
15
8
|
import isString from 'lodash/isString';
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
routes: {}
|
|
23
|
-
}, opts), {}, {
|
|
10
|
+
class Base {
|
|
11
|
+
constructor(opts = {}) {
|
|
12
|
+
this.options = {
|
|
13
|
+
routes: {},
|
|
14
|
+
...opts,
|
|
24
15
|
baseUrl: opts.baseUrl || 'https://micromag.ca/api'
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
requestGet(path, query = null) {
|
|
19
|
+
const finalQueryString = query !== null ? queryString.stringify(query, {
|
|
20
|
+
arrayFormat: 'bracket'
|
|
21
|
+
}) : null;
|
|
22
|
+
return getJSON(`${this.getFullUrl(path)}${finalQueryString !== null && finalQueryString.length > 0 ? `?${finalQueryString}` : ''}`, {
|
|
23
|
+
credentials: 'include',
|
|
24
|
+
headers: getCSRFHeaders()
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return this.requestPost(path, {
|
|
61
|
-
_method: 'DELETE'
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}, {
|
|
65
|
-
key: "route",
|
|
66
|
-
value: function route(_route, params) {
|
|
67
|
-
var routes = this.options.routes;
|
|
68
|
-
return generatePath(routes[_route] || _route, params);
|
|
69
|
-
}
|
|
70
|
-
}, {
|
|
71
|
-
key: "getFullUrl",
|
|
72
|
-
value: function getFullUrl(path) {
|
|
73
|
-
var baseUrl = this.options.baseUrl;
|
|
74
|
-
return "".concat(baseUrl.replace(/\/$/, ''), "/").concat(path.replace(/^\//, ''));
|
|
75
|
-
}
|
|
76
|
-
}]);
|
|
77
|
-
}();
|
|
27
|
+
requestPost(path, data) {
|
|
28
|
+
return postJSON(this.getFullUrl(path), data, {
|
|
29
|
+
credentials: 'include',
|
|
30
|
+
headers: getCSRFHeaders()
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
requestPut(path, data) {
|
|
34
|
+
return postJSON(this.getFullUrl(path), {
|
|
35
|
+
_method: 'PUT',
|
|
36
|
+
...data
|
|
37
|
+
}, {
|
|
38
|
+
credentials: 'include',
|
|
39
|
+
headers: getCSRFHeaders()
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
requestDelete(path) {
|
|
43
|
+
return this.requestPost(path, {
|
|
44
|
+
_method: 'DELETE'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
route(route, params) {
|
|
48
|
+
const {
|
|
49
|
+
routes
|
|
50
|
+
} = this.options;
|
|
51
|
+
return generatePath(routes[route] || route, params);
|
|
52
|
+
}
|
|
53
|
+
getFullUrl(path) {
|
|
54
|
+
const {
|
|
55
|
+
baseUrl
|
|
56
|
+
} = this.options;
|
|
57
|
+
return `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
78
60
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
routes: _objectSpread({
|
|
61
|
+
class ContributionsApi extends Base {
|
|
62
|
+
constructor(opts = {}) {
|
|
63
|
+
super({
|
|
64
|
+
...opts,
|
|
65
|
+
routes: {
|
|
85
66
|
index: '/contributions/:screen',
|
|
86
67
|
store: '/contributions',
|
|
87
68
|
update: '/contributions/:contribution',
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})]);
|
|
91
|
-
}
|
|
92
|
-
_inherits(ContributionsApi, _Base);
|
|
93
|
-
return _createClass(ContributionsApi, [{
|
|
94
|
-
key: "get",
|
|
95
|
-
value: function get(id) {
|
|
96
|
-
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
97
|
-
var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
98
|
-
var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
|
|
99
|
-
var finalQuery = _objectSpread({}, query);
|
|
100
|
-
if (page !== null) {
|
|
101
|
-
finalQuery.page = page;
|
|
69
|
+
delete: '/contributions/:contribution',
|
|
70
|
+
...(opts.routes || null)
|
|
102
71
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
get(id, query = {}, page = 1, count = 10) {
|
|
75
|
+
const finalQuery = {
|
|
76
|
+
...query
|
|
77
|
+
};
|
|
78
|
+
if (page !== null) {
|
|
79
|
+
finalQuery.page = page;
|
|
109
80
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
value: function create(data) {
|
|
113
|
-
return this.requestPost(this.route('store'), data);
|
|
81
|
+
if (count !== null) {
|
|
82
|
+
finalQuery.count = count;
|
|
114
83
|
}
|
|
115
|
-
|
|
116
|
-
|
|
84
|
+
return this.requestGet(this.route('index', {
|
|
85
|
+
screen: id
|
|
86
|
+
}), finalQuery);
|
|
87
|
+
}
|
|
88
|
+
create(data) {
|
|
89
|
+
return this.requestPost(this.route('store'), data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
117
92
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
routes: _objectSpread({
|
|
93
|
+
class MediasApi extends Base {
|
|
94
|
+
constructor(opts = {}) {
|
|
95
|
+
super({
|
|
96
|
+
...opts,
|
|
97
|
+
routes: {
|
|
124
98
|
index: 'medias',
|
|
125
99
|
tags: 'medias/tags',
|
|
126
100
|
authors: 'medias/authors',
|
|
@@ -128,189 +102,171 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
128
102
|
show: 'medias/:media',
|
|
129
103
|
store: 'medias',
|
|
130
104
|
update: 'medias/:media',
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})]);
|
|
134
|
-
}
|
|
135
|
-
_inherits(MediasApi, _Base);
|
|
136
|
-
return _createClass(MediasApi, [{
|
|
137
|
-
key: "find",
|
|
138
|
-
value: function find(id) {
|
|
139
|
-
return this.requestGet(this.route('show', {
|
|
140
|
-
media: id
|
|
141
|
-
}));
|
|
142
|
-
}
|
|
143
|
-
}, {
|
|
144
|
-
key: "get",
|
|
145
|
-
value: function get() {
|
|
146
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
147
|
-
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
148
|
-
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
149
|
-
var finalQuery = _objectSpread({}, query);
|
|
150
|
-
if (page !== null) {
|
|
151
|
-
finalQuery.page = page;
|
|
152
|
-
}
|
|
153
|
-
if (count !== null) {
|
|
154
|
-
finalQuery.count = count;
|
|
155
|
-
}
|
|
156
|
-
return this.requestGet(this.route('index'), finalQuery);
|
|
157
|
-
}
|
|
158
|
-
}, {
|
|
159
|
-
key: "getTags",
|
|
160
|
-
value: function getTags() {
|
|
161
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
162
|
-
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
163
|
-
var finalQuery = _objectSpread({}, query);
|
|
164
|
-
if (count !== null) {
|
|
165
|
-
finalQuery.count = count;
|
|
105
|
+
delete: 'medias/:media',
|
|
106
|
+
...(opts.routes || null)
|
|
166
107
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}, {
|
|
181
|
-
key: "create",
|
|
182
|
-
value: function create(data) {
|
|
183
|
-
return this.requestPost(this.route('store'), data);
|
|
184
|
-
}
|
|
185
|
-
}, {
|
|
186
|
-
key: "update",
|
|
187
|
-
value: function update(id, data) {
|
|
188
|
-
return this.requestPut(this.route('update', {
|
|
189
|
-
media: id
|
|
190
|
-
}), data);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
find(id) {
|
|
111
|
+
return this.requestGet(this.route('show', {
|
|
112
|
+
media: id
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
get(query = {}, page = 1, count = 10) {
|
|
116
|
+
const finalQuery = {
|
|
117
|
+
...query
|
|
118
|
+
};
|
|
119
|
+
if (page !== null) {
|
|
120
|
+
finalQuery.page = page;
|
|
191
121
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
value: function requestDeleteMedia(id) {
|
|
195
|
-
return this.requestPost(this.route('requestDelete', {
|
|
196
|
-
media: id
|
|
197
|
-
}));
|
|
122
|
+
if (count !== null) {
|
|
123
|
+
finalQuery.count = count;
|
|
198
124
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
125
|
+
return this.requestGet(this.route('index'), finalQuery);
|
|
126
|
+
}
|
|
127
|
+
getTags(query = {}, count = 10) {
|
|
128
|
+
const finalQuery = {
|
|
129
|
+
...query
|
|
130
|
+
};
|
|
131
|
+
if (count !== null) {
|
|
132
|
+
finalQuery.count = count;
|
|
205
133
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
134
|
+
return this.requestGet(this.route('tags'), finalQuery);
|
|
135
|
+
}
|
|
136
|
+
getAuthors(query = {}, count = 10) {
|
|
137
|
+
const finalQuery = {
|
|
138
|
+
...query
|
|
139
|
+
};
|
|
140
|
+
if (count !== null) {
|
|
141
|
+
finalQuery.count = count;
|
|
212
142
|
}
|
|
213
|
-
|
|
214
|
-
}
|
|
143
|
+
return this.requestGet(this.route('authors'), finalQuery);
|
|
144
|
+
}
|
|
145
|
+
create(data) {
|
|
146
|
+
return this.requestPost(this.route('store'), data);
|
|
147
|
+
}
|
|
148
|
+
update(id, data) {
|
|
149
|
+
return this.requestPut(this.route('update', {
|
|
150
|
+
media: id
|
|
151
|
+
}), data);
|
|
152
|
+
}
|
|
153
|
+
requestDeleteMedia(id) {
|
|
154
|
+
return this.requestPost(this.route('requestDelete', {
|
|
155
|
+
media: id
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
delete(id) {
|
|
159
|
+
return this.requestDelete(this.route('delete', {
|
|
160
|
+
media: id
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
replace(id, data) {
|
|
164
|
+
return this.requestPost(this.route('replace', {
|
|
165
|
+
media: id
|
|
166
|
+
}), data);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
215
169
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
routes: _objectSpread({
|
|
170
|
+
class QuizApi extends Base {
|
|
171
|
+
constructor(opts = {}) {
|
|
172
|
+
super({
|
|
173
|
+
...opts,
|
|
174
|
+
routes: {
|
|
222
175
|
results: '/quiz/:screen',
|
|
223
176
|
store: '/quiz',
|
|
224
177
|
update: '/quiz/:quiz',
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
178
|
+
delete: '/quiz/:quiz',
|
|
179
|
+
...(opts.routes || null)
|
|
180
|
+
}
|
|
181
|
+
});
|
|
228
182
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}, {
|
|
239
|
-
key: "create",
|
|
240
|
-
value: function create(data) {
|
|
241
|
-
return this.requestPost(this.route('store'), data);
|
|
242
|
-
}
|
|
243
|
-
}]);
|
|
244
|
-
}(Base);
|
|
183
|
+
results(screenId, query = {}) {
|
|
184
|
+
return this.requestGet(this.route('results', {
|
|
185
|
+
screen: screenId
|
|
186
|
+
}), query);
|
|
187
|
+
}
|
|
188
|
+
create(data) {
|
|
189
|
+
return this.requestPost(this.route('store'), data);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
245
192
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
_this.medias = new MediasApi(opts);
|
|
253
|
-
_this.contributions = new ContributionsApi(opts);
|
|
254
|
-
_this.quiz = new QuizApi(opts);
|
|
255
|
-
return _this;
|
|
193
|
+
class Api extends Base {
|
|
194
|
+
constructor(opts = {}) {
|
|
195
|
+
super(opts);
|
|
196
|
+
this.medias = new MediasApi(opts);
|
|
197
|
+
this.contributions = new ContributionsApi(opts);
|
|
198
|
+
this.quiz = new QuizApi(opts);
|
|
256
199
|
}
|
|
257
|
-
|
|
258
|
-
return _createClass(Api);
|
|
259
|
-
}(Base);
|
|
200
|
+
}
|
|
260
201
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var useApi = function useApi() {
|
|
202
|
+
const ApiContext = /*#__PURE__*/React.createContext(null);
|
|
203
|
+
const useApi = () => {
|
|
264
204
|
return useContext(ApiContext);
|
|
265
205
|
};
|
|
266
|
-
function ApiProvider(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
baseUrl
|
|
271
|
-
children
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
206
|
+
function ApiProvider(t0) {
|
|
207
|
+
const $ = c(7);
|
|
208
|
+
const {
|
|
209
|
+
api: t1,
|
|
210
|
+
baseUrl: t2,
|
|
211
|
+
children
|
|
212
|
+
} = t0;
|
|
213
|
+
const initialApi = t1 === undefined ? null : t1;
|
|
214
|
+
const baseUrl = t2 === undefined ? undefined : t2;
|
|
215
|
+
const previousApi = useApi();
|
|
216
|
+
let t3;
|
|
217
|
+
if ($[0] !== baseUrl || $[1] !== initialApi || $[2] !== previousApi) {
|
|
218
|
+
t3 = initialApi || previousApi || new Api({
|
|
219
|
+
baseUrl
|
|
277
220
|
});
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
221
|
+
$[0] = baseUrl;
|
|
222
|
+
$[1] = initialApi;
|
|
223
|
+
$[2] = previousApi;
|
|
224
|
+
$[3] = t3;
|
|
225
|
+
} else {
|
|
226
|
+
t3 = $[3];
|
|
227
|
+
}
|
|
228
|
+
const api = t3;
|
|
229
|
+
let t4;
|
|
230
|
+
if ($[4] !== api || $[5] !== children) {
|
|
231
|
+
t4 = /*#__PURE__*/jsx(ApiContext.Provider, {
|
|
232
|
+
value: api,
|
|
233
|
+
children: children
|
|
234
|
+
});
|
|
235
|
+
$[4] = api;
|
|
236
|
+
$[5] = children;
|
|
237
|
+
$[6] = t4;
|
|
238
|
+
} else {
|
|
239
|
+
t4 = $[6];
|
|
240
|
+
}
|
|
241
|
+
return t4;
|
|
283
242
|
}
|
|
284
243
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
var _ref3 = useStory() || {},
|
|
302
|
-
storyId = _ref3.id,
|
|
303
|
-
documentId = _ref3.document_id;
|
|
304
|
-
var create = useCallback(function (data) {
|
|
244
|
+
const useContributionCreate = ({
|
|
245
|
+
screenId,
|
|
246
|
+
visitorId: providedVisitorId = null,
|
|
247
|
+
storyId: providedStoryId = null,
|
|
248
|
+
onSuccess = null
|
|
249
|
+
} = {}) => {
|
|
250
|
+
const api = useApi();
|
|
251
|
+
const [creating, setCreating] = useState(false);
|
|
252
|
+
const {
|
|
253
|
+
id: visitorId
|
|
254
|
+
} = useVisitor() || {};
|
|
255
|
+
const {
|
|
256
|
+
id: storyId,
|
|
257
|
+
document_id: documentId
|
|
258
|
+
} = useStory() || {};
|
|
259
|
+
const create = useCallback(data => {
|
|
305
260
|
if (api === null) {
|
|
306
261
|
return null;
|
|
307
262
|
}
|
|
308
263
|
setCreating(true);
|
|
309
|
-
return api.contributions.create(
|
|
264
|
+
return api.contributions.create({
|
|
310
265
|
screen_id: screenId,
|
|
311
266
|
visitor_id: providedVisitorId || visitorId,
|
|
312
|
-
story_id: documentId || providedStoryId || storyId
|
|
313
|
-
|
|
267
|
+
story_id: documentId || providedStoryId || storyId,
|
|
268
|
+
...data
|
|
269
|
+
}).then(response => {
|
|
314
270
|
setCreating(false);
|
|
315
271
|
if (onSuccess !== null) {
|
|
316
272
|
onSuccess(response);
|
|
@@ -319,153 +275,165 @@ var useContributionCreate = function useContributionCreate() {
|
|
|
319
275
|
});
|
|
320
276
|
}, [api, setCreating, onSuccess, screenId, visitorId, storyId, providedVisitorId, providedStoryId]);
|
|
321
277
|
return {
|
|
322
|
-
create
|
|
323
|
-
creating
|
|
278
|
+
create,
|
|
279
|
+
creating
|
|
324
280
|
};
|
|
325
281
|
};
|
|
326
282
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
283
|
+
const useData = (loadData, t0) => {
|
|
284
|
+
const $ = c(13);
|
|
285
|
+
let t1;
|
|
286
|
+
if ($[0] !== t0) {
|
|
287
|
+
t1 = t0 === undefined ? {} : t0;
|
|
288
|
+
$[0] = t0;
|
|
289
|
+
$[1] = t1;
|
|
290
|
+
} else {
|
|
291
|
+
t1 = $[1];
|
|
292
|
+
}
|
|
293
|
+
const {
|
|
294
|
+
initialData: t2,
|
|
295
|
+
autoload: t3
|
|
296
|
+
} = t1;
|
|
297
|
+
const initialData = t2 === undefined ? null : t2;
|
|
298
|
+
const autoload = t3 === undefined ? true : t3;
|
|
299
|
+
const [loading, setLoading] = useState(false);
|
|
300
|
+
const [error, setError] = useState(false);
|
|
301
|
+
const [data, setData] = useState(initialData);
|
|
302
|
+
let t4;
|
|
303
|
+
if ($[2] !== loadData) {
|
|
304
|
+
t4 = (...t5) => {
|
|
305
|
+
const args = t5;
|
|
306
|
+
let canceled = false;
|
|
307
|
+
setLoading(true);
|
|
308
|
+
const promise = loadData(...args).then(newData => {
|
|
309
|
+
if (!canceled) {
|
|
310
|
+
setData(newData);
|
|
311
|
+
setLoading(false);
|
|
312
|
+
}
|
|
313
|
+
return newData;
|
|
314
|
+
}).catch(newError => {
|
|
315
|
+
setError(newError);
|
|
351
316
|
setLoading(false);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
promise.cancel = function () {
|
|
359
|
-
canceled = true;
|
|
360
|
-
setLoading(false);
|
|
317
|
+
});
|
|
318
|
+
promise.cancel = () => {
|
|
319
|
+
canceled = true;
|
|
320
|
+
setLoading(false);
|
|
321
|
+
};
|
|
322
|
+
return promise;
|
|
361
323
|
};
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
324
|
+
$[2] = loadData;
|
|
325
|
+
$[3] = t4;
|
|
326
|
+
} else {
|
|
327
|
+
t4 = $[3];
|
|
328
|
+
}
|
|
329
|
+
const load = t4;
|
|
330
|
+
let t5;
|
|
331
|
+
let t6;
|
|
332
|
+
if ($[4] !== autoload || $[5] !== load) {
|
|
333
|
+
t5 = () => {
|
|
334
|
+
let loader = null;
|
|
335
|
+
if (autoload) {
|
|
336
|
+
loader = load();
|
|
372
337
|
}
|
|
338
|
+
return () => {
|
|
339
|
+
if (loader !== null) {
|
|
340
|
+
loader.cancel();
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
t6 = [autoload, load];
|
|
345
|
+
$[4] = autoload;
|
|
346
|
+
$[5] = load;
|
|
347
|
+
$[6] = t5;
|
|
348
|
+
$[7] = t6;
|
|
349
|
+
} else {
|
|
350
|
+
t5 = $[6];
|
|
351
|
+
t6 = $[7];
|
|
352
|
+
}
|
|
353
|
+
useEffect(t5, t6);
|
|
354
|
+
let t7;
|
|
355
|
+
if ($[8] !== data || $[9] !== error || $[10] !== load || $[11] !== loading) {
|
|
356
|
+
t7 = {
|
|
357
|
+
data,
|
|
358
|
+
load,
|
|
359
|
+
loading,
|
|
360
|
+
error
|
|
373
361
|
};
|
|
374
|
-
|
|
362
|
+
$[8] = data;
|
|
363
|
+
$[9] = error;
|
|
364
|
+
$[10] = load;
|
|
365
|
+
$[11] = loading;
|
|
366
|
+
$[12] = t7;
|
|
367
|
+
} else {
|
|
368
|
+
t7 = $[12];
|
|
369
|
+
}
|
|
370
|
+
return t7;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const useContributions = (options = null) => {
|
|
374
|
+
const {
|
|
375
|
+
screenId,
|
|
376
|
+
storyId: providedStoryId = null,
|
|
377
|
+
opts = {}
|
|
378
|
+
} = options || {};
|
|
379
|
+
const api = useApi();
|
|
380
|
+
const {
|
|
381
|
+
id: storyId,
|
|
382
|
+
document_id: documentId
|
|
383
|
+
} = useStory() || {};
|
|
384
|
+
const [defaultContributions] = useState([...new Array(10)].map((el, i) => ({
|
|
385
|
+
name: `Nom ${i + 1}`,
|
|
386
|
+
message: `Message ${i + 1}`
|
|
387
|
+
})));
|
|
388
|
+
const loader = useCallback(() => api !== null ? api.contributions.get(screenId, {
|
|
389
|
+
story_id: documentId || providedStoryId || storyId
|
|
390
|
+
}) : null, [api, screenId, documentId, providedStoryId, storyId]);
|
|
391
|
+
const {
|
|
392
|
+
data,
|
|
393
|
+
...request
|
|
394
|
+
} = api !== null ? useData(loader, opts) : {
|
|
395
|
+
data: null
|
|
396
|
+
};
|
|
375
397
|
return {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
loading: loading,
|
|
379
|
-
error: error
|
|
398
|
+
contributions: data || defaultContributions,
|
|
399
|
+
...request
|
|
380
400
|
};
|
|
381
401
|
};
|
|
382
402
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
documentId = _ref2.document_id;
|
|
396
|
-
var _useState = useState(_toConsumableArray(new Array(10)).map(function (el, i) {
|
|
397
|
-
return {
|
|
398
|
-
name: "Nom ".concat(i + 1),
|
|
399
|
-
message: "Message ".concat(i + 1)
|
|
400
|
-
};
|
|
401
|
-
})),
|
|
402
|
-
_useState2 = _slicedToArray(_useState, 1),
|
|
403
|
-
defaultContributions = _useState2[0];
|
|
404
|
-
var loader = useCallback(function () {
|
|
405
|
-
return api !== null ? api.contributions.get(screenId, {
|
|
406
|
-
story_id: documentId || providedStoryId || storyId
|
|
407
|
-
}) : null;
|
|
408
|
-
}, [api, screenId, documentId, providedStoryId, storyId]);
|
|
409
|
-
var _ref3 = api !== null ? useData(loader, opts) : {
|
|
410
|
-
data: null
|
|
403
|
+
const useItems$1 = ({
|
|
404
|
+
getPage = null,
|
|
405
|
+
getItems = null,
|
|
406
|
+
page = null,
|
|
407
|
+
count = 10,
|
|
408
|
+
items: providedItems = null,
|
|
409
|
+
pages: initialPages = null,
|
|
410
|
+
getPageFromResponse = ({
|
|
411
|
+
meta: {
|
|
412
|
+
current_page: currentPage,
|
|
413
|
+
last_page: lastPage,
|
|
414
|
+
total
|
|
411
415
|
},
|
|
412
|
-
data
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
providedItems = _ref$items === void 0 ? null : _ref$items,
|
|
430
|
-
_ref$pages = _ref.pages,
|
|
431
|
-
initialPages = _ref$pages === void 0 ? null : _ref$pages,
|
|
432
|
-
_ref$getPageFromRespo = _ref.getPageFromResponse,
|
|
433
|
-
getPageFromResponse = _ref$getPageFromRespo === void 0 ? function (_ref2) {
|
|
434
|
-
var _ref2$meta = _ref2.meta,
|
|
435
|
-
currentPage = _ref2$meta.current_page,
|
|
436
|
-
lastPage = _ref2$meta.last_page,
|
|
437
|
-
total = _ref2$meta.total,
|
|
438
|
-
items = _ref2.data;
|
|
439
|
-
return {
|
|
440
|
-
page: parseInt(currentPage, 10),
|
|
441
|
-
lastPage: parseInt(lastPage, 10),
|
|
442
|
-
total: parseInt(total, 10),
|
|
443
|
-
items: items
|
|
444
|
-
};
|
|
445
|
-
} : _ref$getPageFromRespo,
|
|
446
|
-
_ref$getItemsFromResp = _ref.getItemsFromResponse,
|
|
447
|
-
getItemsFromResponse = _ref$getItemsFromResp === void 0 ? function (data) {
|
|
448
|
-
return data;
|
|
449
|
-
} : _ref$getItemsFromResp,
|
|
450
|
-
_ref$onItemsLoaded = _ref.onItemsLoaded,
|
|
451
|
-
onItemsLoaded = _ref$onItemsLoaded === void 0 ? null : _ref$onItemsLoaded,
|
|
452
|
-
_ref$onPageLoaded = _ref.onPageLoaded,
|
|
453
|
-
onPageLoaded = _ref$onPageLoaded === void 0 ? null : _ref$onPageLoaded,
|
|
454
|
-
_ref$onLoaded = _ref.onLoaded,
|
|
455
|
-
onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
|
|
456
|
-
_ref$onError = _ref.onError,
|
|
457
|
-
onError = _ref$onError === void 0 ? null : _ref$onError;
|
|
458
|
-
var isPaginated = getPage !== null || initialPages !== null;
|
|
459
|
-
var lastState = useRef(null);
|
|
460
|
-
var initialState = useMemo(function () {
|
|
461
|
-
var finalInitialPages = initialPages !== null ? initialPages.map(function (it) {
|
|
462
|
-
return getPageFromResponse(it);
|
|
463
|
-
}) : null;
|
|
416
|
+
data: items
|
|
417
|
+
}) => ({
|
|
418
|
+
page: parseInt(currentPage, 10),
|
|
419
|
+
lastPage: parseInt(lastPage, 10),
|
|
420
|
+
total: parseInt(total, 10),
|
|
421
|
+
items
|
|
422
|
+
}),
|
|
423
|
+
getItemsFromResponse = data => data,
|
|
424
|
+
onItemsLoaded = null,
|
|
425
|
+
onPageLoaded = null,
|
|
426
|
+
onLoaded = null,
|
|
427
|
+
onError = null
|
|
428
|
+
}) => {
|
|
429
|
+
const isPaginated = getPage !== null || initialPages !== null;
|
|
430
|
+
const lastState = useRef(null);
|
|
431
|
+
const initialState = useMemo(() => {
|
|
432
|
+
const finalInitialPages = initialPages !== null ? initialPages.map(it => getPageFromResponse(it)) : null;
|
|
464
433
|
return {
|
|
465
|
-
lastPage: finalInitialPages !== null ? finalInitialPages.reduce(
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}, -1) : -1,
|
|
434
|
+
lastPage: finalInitialPages !== null ? finalInitialPages.reduce((currentLastPage, {
|
|
435
|
+
lastPage: initialLastPage
|
|
436
|
+
}) => initialLastPage > currentLastPage ? initialLastPage : currentLastPage, -1) : -1,
|
|
469
437
|
total: finalInitialPages !== null ? finalInitialPages[0].total : (providedItems || []).length,
|
|
470
438
|
loaded: providedItems !== null,
|
|
471
439
|
loading: false,
|
|
@@ -473,26 +441,23 @@ var useItems$1 = function useItems(_ref) {
|
|
|
473
441
|
items: null
|
|
474
442
|
};
|
|
475
443
|
}, [initialPages, providedItems]);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
var updateFromResponse = function updateFromResponse(response) {
|
|
494
|
-
var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
495
|
-
var reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
444
|
+
const [state, setState] = useState(initialState);
|
|
445
|
+
const {
|
|
446
|
+
lastPage: lastPage_0,
|
|
447
|
+
loaded,
|
|
448
|
+
loading,
|
|
449
|
+
items: stateItems,
|
|
450
|
+
pages,
|
|
451
|
+
total: total_0
|
|
452
|
+
} = state;
|
|
453
|
+
const items_0 = providedItems || (isPaginated && pages !== null ? pages.reduce((pagesItems, {
|
|
454
|
+
items: pageItems
|
|
455
|
+
}) => pagesItems.concat(pageItems), []) : stateItems) || null;
|
|
456
|
+
const updateState = update => setState({
|
|
457
|
+
...state,
|
|
458
|
+
...update
|
|
459
|
+
});
|
|
460
|
+
const updateFromResponse = (response, error = null, reset = false) => {
|
|
496
461
|
if (error !== null) {
|
|
497
462
|
updateState({
|
|
498
463
|
loaded: false,
|
|
@@ -501,10 +466,8 @@ var useItems$1 = function useItems(_ref) {
|
|
|
501
466
|
throw error;
|
|
502
467
|
}
|
|
503
468
|
if (isPaginated) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
return it.page !== newPage.page;
|
|
507
|
-
})), [newPage])).sort(function (a, b) {
|
|
469
|
+
const newPage = getPageFromResponse(response);
|
|
470
|
+
const newPages = (reset ? [newPage] : [...(pages || []).filter(it_0 => it_0.page !== newPage.page), newPage]).sort((a, b) => {
|
|
508
471
|
if (a === b) {
|
|
509
472
|
return 0;
|
|
510
473
|
}
|
|
@@ -519,7 +482,7 @@ var useItems$1 = function useItems(_ref) {
|
|
|
519
482
|
});
|
|
520
483
|
return newPage;
|
|
521
484
|
}
|
|
522
|
-
|
|
485
|
+
const newItems = [...getItemsFromResponse(response)];
|
|
523
486
|
updateState({
|
|
524
487
|
loaded: true,
|
|
525
488
|
loading: false,
|
|
@@ -528,257 +491,256 @@ var useItems$1 = function useItems(_ref) {
|
|
|
528
491
|
});
|
|
529
492
|
return newItems;
|
|
530
493
|
};
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
var remainingPages = allPages.filter(function (pageNumber) {
|
|
536
|
-
return pages.findIndex(function (it) {
|
|
537
|
-
return it.page === pageNumber;
|
|
538
|
-
}) === -1;
|
|
539
|
-
});
|
|
540
|
-
var firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
|
|
494
|
+
const getNextPage = () => {
|
|
495
|
+
const allPages = lastPage_0 !== -1 ? Array.call(null, ...Array(lastPage_0)).map((it_1, index) => index + 1) : [];
|
|
496
|
+
const remainingPages = allPages.filter(pageNumber => pages.findIndex(it_2 => it_2.page === pageNumber) === -1);
|
|
497
|
+
const firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
|
|
541
498
|
return firstItem !== null ? firstItem : null;
|
|
542
499
|
};
|
|
543
|
-
|
|
500
|
+
const loadItems = requestPage => {
|
|
544
501
|
updateState({
|
|
545
502
|
loading: true
|
|
546
503
|
});
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
return !canceled ? updateFromResponse(response) : Promise.reject();
|
|
551
|
-
})["catch"](function (error) {
|
|
552
|
-
return !canceled ? updateFromResponse(null, error) : Promise.reject();
|
|
553
|
-
}).then(function (response) {
|
|
504
|
+
let canceled = false;
|
|
505
|
+
const request = isPaginated ? getPage(requestPage, count) : getItems();
|
|
506
|
+
const promise = request.then(response_0 => !canceled ? updateFromResponse(response_0) : Promise.reject()).catch(error_0 => !canceled ? updateFromResponse(null, error_0) : Promise.reject()).then(response_1 => {
|
|
554
507
|
if (isPaginated && onPageLoaded !== null) {
|
|
555
|
-
onPageLoaded(
|
|
508
|
+
onPageLoaded(response_1);
|
|
556
509
|
} else if (!isPaginated && onItemsLoaded !== null) {
|
|
557
|
-
onItemsLoaded(
|
|
510
|
+
onItemsLoaded(response_1);
|
|
558
511
|
}
|
|
559
512
|
if (onLoaded !== null) {
|
|
560
|
-
onLoaded(
|
|
513
|
+
onLoaded(response_1);
|
|
561
514
|
}
|
|
562
|
-
return
|
|
563
|
-
})
|
|
515
|
+
return response_1;
|
|
516
|
+
}).catch(error_1 => {
|
|
564
517
|
if (!canceled && onError !== null) {
|
|
565
|
-
onError(
|
|
518
|
+
onError(error_1);
|
|
566
519
|
}
|
|
567
520
|
});
|
|
568
|
-
promise.cancel =
|
|
521
|
+
promise.cancel = () => {
|
|
569
522
|
canceled = true;
|
|
570
523
|
};
|
|
571
524
|
return promise;
|
|
572
525
|
};
|
|
573
|
-
|
|
526
|
+
const loadPage = pageToLoad => {
|
|
574
527
|
if (loading) {
|
|
575
528
|
return Promise.reject();
|
|
576
529
|
}
|
|
577
|
-
if (pages.find(
|
|
578
|
-
return it.page === pageToLoad;
|
|
579
|
-
}) !== -1) {
|
|
530
|
+
if (pages.find(it_3 => it_3.page === pageToLoad) !== -1) {
|
|
580
531
|
return Promise.reject();
|
|
581
532
|
}
|
|
582
533
|
return loadItems(pageToLoad);
|
|
583
534
|
};
|
|
584
|
-
|
|
535
|
+
const loadNextPage = () => {
|
|
585
536
|
if (loading) {
|
|
586
537
|
return Promise.reject();
|
|
587
538
|
}
|
|
588
|
-
|
|
539
|
+
const nextPage = getNextPage();
|
|
589
540
|
return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
|
|
590
541
|
};
|
|
591
|
-
useEffect(
|
|
592
|
-
|
|
542
|
+
useEffect(() => {
|
|
543
|
+
const hadState = lastState.current !== null;
|
|
593
544
|
lastState.current = initialState;
|
|
594
545
|
if (hadState) {
|
|
595
546
|
setState(initialState);
|
|
596
547
|
}
|
|
597
548
|
}, [initialState]);
|
|
598
|
-
useEffect(
|
|
549
|
+
useEffect(() => {
|
|
599
550
|
if (getPage === null && getItems === null || providedItems !== null) {
|
|
600
|
-
return
|
|
551
|
+
return () => {};
|
|
601
552
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
if (!isPaginated ||
|
|
605
|
-
loadPromise = loadItems(
|
|
553
|
+
let loadPromise = null;
|
|
554
|
+
const pageToLoad_0 = isPaginated && initialPages === null && page === null ? 1 : page;
|
|
555
|
+
if (!isPaginated || pageToLoad_0 !== null) {
|
|
556
|
+
loadPromise = loadItems(pageToLoad_0);
|
|
606
557
|
}
|
|
607
|
-
return
|
|
558
|
+
return () => {
|
|
608
559
|
if (loadPromise !== null) {
|
|
609
560
|
loadPromise.cancel();
|
|
610
561
|
}
|
|
611
562
|
};
|
|
612
563
|
}, [getPage, getItems, page]);
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}) || null : null;
|
|
564
|
+
const currentPage_0 = isPaginated && pages !== null ? pages.find(({
|
|
565
|
+
page: pageNumber_0
|
|
566
|
+
}) => parseInt(pageNumber_0, 10) === parseInt(page, 10)) || null : null;
|
|
617
567
|
return {
|
|
618
|
-
items:
|
|
619
|
-
pages
|
|
620
|
-
pageItems:
|
|
621
|
-
total:
|
|
622
|
-
lastPage:
|
|
623
|
-
loaded
|
|
624
|
-
allLoaded: !isPaginated && loaded ||
|
|
625
|
-
loading
|
|
626
|
-
loadNextPage
|
|
627
|
-
loadPage
|
|
568
|
+
items: items_0,
|
|
569
|
+
pages,
|
|
570
|
+
pageItems: currentPage_0 !== null ? currentPage_0.items : null,
|
|
571
|
+
total: total_0,
|
|
572
|
+
lastPage: lastPage_0,
|
|
573
|
+
loaded,
|
|
574
|
+
allLoaded: !isPaginated && loaded || lastPage_0 !== -1 && isPaginated && pages.length === lastPage_0,
|
|
575
|
+
loading,
|
|
576
|
+
loadNextPage,
|
|
577
|
+
loadPage
|
|
628
578
|
};
|
|
629
579
|
};
|
|
630
580
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
}
|
|
581
|
+
const useMedia = (id, opts) => {
|
|
582
|
+
const $ = c(9);
|
|
583
|
+
const api = useApi();
|
|
584
|
+
let t0;
|
|
585
|
+
if ($[0] !== api.medias || $[1] !== id) {
|
|
586
|
+
t0 = () => api.medias.find(id);
|
|
587
|
+
$[0] = api.medias;
|
|
588
|
+
$[1] = id;
|
|
589
|
+
$[2] = t0;
|
|
590
|
+
} else {
|
|
591
|
+
t0 = $[2];
|
|
592
|
+
}
|
|
593
|
+
const loader = t0;
|
|
594
|
+
const t1 = useData(loader, opts);
|
|
595
|
+
let data;
|
|
596
|
+
let request;
|
|
597
|
+
if ($[3] !== t1) {
|
|
598
|
+
({
|
|
599
|
+
data,
|
|
600
|
+
...request
|
|
601
|
+
} = t1);
|
|
602
|
+
$[3] = t1;
|
|
603
|
+
$[4] = data;
|
|
604
|
+
$[5] = request;
|
|
605
|
+
} else {
|
|
606
|
+
data = $[4];
|
|
607
|
+
request = $[5];
|
|
608
|
+
}
|
|
609
|
+
let t2;
|
|
610
|
+
if ($[6] !== data || $[7] !== request) {
|
|
611
|
+
t2 = {
|
|
612
|
+
story: data,
|
|
613
|
+
...request
|
|
614
|
+
};
|
|
615
|
+
$[6] = data;
|
|
616
|
+
$[7] = request;
|
|
617
|
+
$[8] = t2;
|
|
618
|
+
} else {
|
|
619
|
+
t2 = $[8];
|
|
620
|
+
}
|
|
621
|
+
return t2;
|
|
643
622
|
};
|
|
644
623
|
|
|
645
|
-
// import { useCallback } from 'react';
|
|
646
|
-
|
|
647
624
|
// import useItems from './useItems';
|
|
648
625
|
|
|
649
626
|
// eslint-disable-next-line
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
627
|
+
const useMediaAuthors = (t0, t1, opts) => {
|
|
628
|
+
const $ = c(1);
|
|
629
|
+
useApi();
|
|
630
|
+
let t2;
|
|
631
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
632
|
+
t2 = {
|
|
633
|
+
authors: []
|
|
634
|
+
};
|
|
635
|
+
$[0] = t2;
|
|
636
|
+
} else {
|
|
637
|
+
t2 = $[0];
|
|
638
|
+
}
|
|
639
|
+
return t2;
|
|
662
640
|
};
|
|
663
641
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
642
|
+
const useMediaCreate = () => {
|
|
643
|
+
const $ = c(5);
|
|
644
|
+
const [creating, setCreating] = useState(false);
|
|
645
|
+
const api = useApi();
|
|
646
|
+
let t0;
|
|
647
|
+
if ($[0] !== api) {
|
|
648
|
+
t0 = data => {
|
|
649
|
+
setCreating(true);
|
|
650
|
+
return api.medias.create(data).then(response => {
|
|
651
|
+
setCreating(false);
|
|
652
|
+
return response;
|
|
653
|
+
});
|
|
654
|
+
};
|
|
655
|
+
$[0] = api;
|
|
656
|
+
$[1] = t0;
|
|
657
|
+
} else {
|
|
658
|
+
t0 = $[1];
|
|
659
|
+
}
|
|
660
|
+
const create = t0;
|
|
661
|
+
let t1;
|
|
662
|
+
if ($[2] !== create || $[3] !== creating) {
|
|
663
|
+
t1 = {
|
|
664
|
+
create,
|
|
665
|
+
creating
|
|
666
|
+
};
|
|
667
|
+
$[2] = create;
|
|
668
|
+
$[3] = creating;
|
|
669
|
+
$[4] = t1;
|
|
670
|
+
} else {
|
|
671
|
+
t1 = $[4];
|
|
672
|
+
}
|
|
673
|
+
return t1;
|
|
681
674
|
};
|
|
682
675
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return {
|
|
706
|
-
pageNumber: cp,
|
|
707
|
-
pageCount: pp,
|
|
708
|
-
lastPage: lp,
|
|
709
|
-
total: total
|
|
710
|
-
};
|
|
711
|
-
} : _ref$getPagination,
|
|
712
|
-
_ref$onLoaded = _ref.onLoaded,
|
|
713
|
-
onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
|
|
714
|
-
_ref$onError = _ref.onError,
|
|
715
|
-
onError = _ref$onError === void 0 ? null : _ref$onError;
|
|
676
|
+
const useItems = ({
|
|
677
|
+
getPage = null,
|
|
678
|
+
page = 1,
|
|
679
|
+
count = 10,
|
|
680
|
+
query: pageQuery = null,
|
|
681
|
+
// string or object
|
|
682
|
+
pages: startingPages = null,
|
|
683
|
+
getPageFromResponse = newPage => newPage,
|
|
684
|
+
getPagination = ({
|
|
685
|
+
current_page: cp,
|
|
686
|
+
per_page: pp,
|
|
687
|
+
last_page: lp,
|
|
688
|
+
total
|
|
689
|
+
} = {}) => ({
|
|
690
|
+
pageNumber: cp,
|
|
691
|
+
pageCount: pp,
|
|
692
|
+
lastPage: lp,
|
|
693
|
+
total
|
|
694
|
+
}),
|
|
695
|
+
onLoaded = null,
|
|
696
|
+
onError = null
|
|
697
|
+
}) => {
|
|
716
698
|
// Pagination
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}, {
|
|
745
|
-
data: [],
|
|
746
|
-
pagination: {}
|
|
747
|
-
});
|
|
748
|
-
}, [startingPages]),
|
|
749
|
-
initialPages = _useMemo.data,
|
|
750
|
-
initialPagination = _useMemo.pagination;
|
|
751
|
-
var _useState5 = useState(startingPages === null),
|
|
752
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
753
|
-
canLoad = _useState6[0],
|
|
754
|
-
setCanLoad = _useState6[1];
|
|
755
|
-
var _useState7 = useState(false),
|
|
756
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
757
|
-
loading = _useState8[0],
|
|
758
|
-
setLoading = _useState8[1];
|
|
699
|
+
const [paginated, setPaginated] = useState(page !== null);
|
|
700
|
+
const [pagination, setPagination] = useState(null);
|
|
701
|
+
const {
|
|
702
|
+
pageNumber = page,
|
|
703
|
+
pageCount = count,
|
|
704
|
+
lastPage = null,
|
|
705
|
+
total: total_0 = null
|
|
706
|
+
} = getPagination(pagination || {});
|
|
707
|
+
const {
|
|
708
|
+
data: initialPages,
|
|
709
|
+
pagination: initialPagination
|
|
710
|
+
} = useMemo(() => (startingPages || []).reduce((paginatedData, it) => {
|
|
711
|
+
const {
|
|
712
|
+
data: items,
|
|
713
|
+
pagination: currentPagination
|
|
714
|
+
} = it || {};
|
|
715
|
+
// eslint-disable-next-line no-param-reassign
|
|
716
|
+
paginatedData.data = paginatedData.data.concat(items);
|
|
717
|
+
// eslint-disable-next-line no-param-reassign
|
|
718
|
+
paginatedData.pagination = currentPagination;
|
|
719
|
+
return paginatedData;
|
|
720
|
+
}, {
|
|
721
|
+
data: [],
|
|
722
|
+
pagination: {}
|
|
723
|
+
}), [startingPages]);
|
|
724
|
+
const [canLoad, setCanLoad] = useState(startingPages === null);
|
|
725
|
+
const [loading, setLoading] = useState(false);
|
|
759
726
|
|
|
760
727
|
// Query
|
|
761
|
-
|
|
762
|
-
|
|
728
|
+
const query = useMemo(() => ({
|
|
729
|
+
...(isString(pageQuery) ? queryString.parse(pageQuery || null, {
|
|
763
730
|
arrayFormat: 'bracket'
|
|
764
|
-
}) : pageQuery)
|
|
765
|
-
}, [pageQuery]);
|
|
731
|
+
}) : pageQuery)
|
|
732
|
+
}), [pageQuery]);
|
|
766
733
|
|
|
767
734
|
// Items
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
items = _useState0[0],
|
|
771
|
-
setItems = _useState0[1];
|
|
772
|
-
var getPages = useCallback(function (newQuery, newPageNumber, newPageCount) {
|
|
773
|
-
return getPage(newQuery, newPageNumber, newPageCount);
|
|
774
|
-
}, [getPage]);
|
|
735
|
+
const [items_0, setItems] = useState(null);
|
|
736
|
+
const getPages = useCallback((newQuery, newPageNumber, newPageCount) => getPage(newQuery, newPageNumber, newPageCount), [getPage]);
|
|
775
737
|
|
|
776
738
|
// Api has changed, reset to beginning
|
|
777
|
-
useEffect(
|
|
739
|
+
useEffect(() => {
|
|
778
740
|
setItems(initialPages);
|
|
779
741
|
setPagination(initialPagination);
|
|
780
742
|
}, [getPages, setItems, setPagination]);
|
|
781
|
-
useEffect(
|
|
743
|
+
useEffect(() => {
|
|
782
744
|
// eslint-disable-next-line
|
|
783
745
|
// console.log('try to load');
|
|
784
746
|
if (!canLoad || loading || lastPage !== null && pageNumber > lastPage) {
|
|
@@ -790,33 +752,28 @@ var useItems = function useItems(_ref) {
|
|
|
790
752
|
setLoading(true);
|
|
791
753
|
setCanLoad(false);
|
|
792
754
|
// TODO: make this a cancellable promise
|
|
793
|
-
getPages(query, pageNumber, pageCount).then(
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
data = _ref4$data === void 0 ? null : _ref4$data,
|
|
799
|
-
_ref4$meta = _ref4.meta,
|
|
800
|
-
meta = _ref4$meta === void 0 ? null : _ref4$meta;
|
|
755
|
+
getPages(query, pageNumber, pageCount).then(response => getPageFromResponse(response)).then(response_0 => {
|
|
756
|
+
const {
|
|
757
|
+
data = null,
|
|
758
|
+
meta = null
|
|
759
|
+
} = response_0 || {};
|
|
801
760
|
// console.log('response --- ', response);
|
|
802
761
|
// This is not a paginated list so we dont care anymore
|
|
803
762
|
if (data === null && meta === null) {
|
|
804
|
-
setItems(
|
|
763
|
+
setItems(response_0);
|
|
805
764
|
setPaginated(false);
|
|
806
765
|
} else {
|
|
807
|
-
setItems(
|
|
808
|
-
return [].concat(_toConsumableArray(old || null), _toConsumableArray(data));
|
|
809
|
-
});
|
|
766
|
+
setItems(old => [...(old || null), ...data]);
|
|
810
767
|
setPagination(meta);
|
|
811
768
|
setPaginated(true);
|
|
812
769
|
}
|
|
813
|
-
return
|
|
814
|
-
}).then(
|
|
770
|
+
return response_0;
|
|
771
|
+
}).then(response_1 => {
|
|
815
772
|
setLoading(false);
|
|
816
773
|
if (onLoaded !== null) {
|
|
817
|
-
onLoaded(
|
|
774
|
+
onLoaded(response_1);
|
|
818
775
|
}
|
|
819
|
-
})
|
|
776
|
+
}).catch(e => {
|
|
820
777
|
// Error is real
|
|
821
778
|
setLoading(false);
|
|
822
779
|
if (onError !== null) {
|
|
@@ -824,229 +781,358 @@ var useItems = function useItems(_ref) {
|
|
|
824
781
|
}
|
|
825
782
|
});
|
|
826
783
|
}, [query, pageNumber, canLoad, getPages, setLoading, setItems, setPagination, onLoaded, onError]);
|
|
827
|
-
|
|
784
|
+
const reset = useCallback(() => {
|
|
828
785
|
setItems([]);
|
|
829
786
|
setPagination(null);
|
|
830
787
|
setCanLoad(true);
|
|
831
788
|
}, [setItems, setPagination, setCanLoad]);
|
|
832
789
|
|
|
833
790
|
// Resets the game, "natural" refresh
|
|
834
|
-
|
|
791
|
+
const onQueryChange = useEffect(() => {
|
|
835
792
|
reset();
|
|
836
793
|
}, [query, page, count, reset]);
|
|
837
794
|
|
|
838
795
|
// Handle to Load next
|
|
839
|
-
|
|
796
|
+
const loadNextPage = useCallback(() => {
|
|
840
797
|
if (!loading && pageNumber < lastPage) {
|
|
841
|
-
|
|
798
|
+
const params = {
|
|
799
|
+
...pagination,
|
|
842
800
|
current_page: pageNumber + 1,
|
|
843
801
|
per_page: pageCount
|
|
844
|
-
}
|
|
802
|
+
};
|
|
845
803
|
setPagination(params);
|
|
846
804
|
setCanLoad(true);
|
|
847
805
|
}
|
|
848
806
|
}, [query, pagination, pageNumber, pageCount, loading, lastPage, onQueryChange, setCanLoad]);
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
807
|
+
const disabled = (items_0 || []).length === 0 || loading || pageNumber >= lastPage || lastPage === null || lastPage === 1;
|
|
808
|
+
const regularLoaded = !paginated && items_0 !== null;
|
|
809
|
+
const paginatedLoaded = !loading && items_0 !== null && (items_0.length === total_0 || pageNumber >= lastPage);
|
|
852
810
|
return {
|
|
853
|
-
items:
|
|
854
|
-
total:
|
|
811
|
+
items: items_0,
|
|
812
|
+
total: total_0,
|
|
855
813
|
page: pageNumber,
|
|
856
814
|
count: pageCount,
|
|
857
|
-
lastPage
|
|
858
|
-
loading
|
|
815
|
+
lastPage,
|
|
816
|
+
loading,
|
|
859
817
|
loaded: !loading,
|
|
860
818
|
allLoaded: regularLoaded || paginatedLoaded,
|
|
861
|
-
disabled
|
|
862
|
-
loadNextPage
|
|
863
|
-
reset
|
|
819
|
+
disabled,
|
|
820
|
+
loadNextPage,
|
|
821
|
+
reset
|
|
864
822
|
};
|
|
865
823
|
};
|
|
866
824
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}
|
|
825
|
+
const useMedias = (t0, t1, t2, t3) => {
|
|
826
|
+
const $ = c(8);
|
|
827
|
+
const query = t0 === undefined ? null : t0;
|
|
828
|
+
const page = t1 === undefined ? 1 : t1;
|
|
829
|
+
const count = t2 === undefined ? 10 : t2;
|
|
830
|
+
const opts = t3 === undefined ? null : t3;
|
|
831
|
+
const api = useApi();
|
|
832
|
+
let t4;
|
|
833
|
+
if ($[0] !== api) {
|
|
834
|
+
t4 = (newQuery, t5, t6) => {
|
|
835
|
+
const requestedPage = t5 === undefined ? null : t5;
|
|
836
|
+
const requestedCount = t6 === undefined ? null : t6;
|
|
837
|
+
return api.medias.get(newQuery, requestedPage, requestedCount);
|
|
838
|
+
};
|
|
839
|
+
$[0] = api;
|
|
840
|
+
$[1] = t4;
|
|
841
|
+
} else {
|
|
842
|
+
t4 = $[1];
|
|
843
|
+
}
|
|
844
|
+
const getPage = t4;
|
|
845
|
+
let t5;
|
|
846
|
+
if ($[2] !== count || $[3] !== getPage || $[4] !== opts || $[5] !== page || $[6] !== query) {
|
|
847
|
+
t5 = {
|
|
848
|
+
getPage,
|
|
849
|
+
query,
|
|
850
|
+
page,
|
|
851
|
+
count,
|
|
852
|
+
...opts
|
|
853
|
+
};
|
|
854
|
+
$[2] = count;
|
|
855
|
+
$[3] = getPage;
|
|
856
|
+
$[4] = opts;
|
|
857
|
+
$[5] = page;
|
|
858
|
+
$[6] = query;
|
|
859
|
+
$[7] = t5;
|
|
860
|
+
} else {
|
|
861
|
+
t5 = $[7];
|
|
862
|
+
}
|
|
863
|
+
return useItems(t5);
|
|
884
864
|
};
|
|
885
865
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
866
|
+
const useMediasRecent = (opts, t0) => {
|
|
867
|
+
const $ = c(7);
|
|
868
|
+
const key = t0 === undefined ? "media-gallery-recent-searches" : t0;
|
|
869
|
+
let t1;
|
|
870
|
+
if ($[0] !== key) {
|
|
871
|
+
t1 = value => {
|
|
872
|
+
if (typeof window !== "undefined" && value) {
|
|
873
|
+
const recent = window.localStorage.getItem(key) || null;
|
|
874
|
+
const current = recent !== null ? JSON.parse(recent || "[]") : [];
|
|
875
|
+
const encoded = JSON.stringify([value, ...current]);
|
|
876
|
+
window.localStorage.setItem(key, encoded);
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
return false;
|
|
880
|
+
};
|
|
881
|
+
$[0] = key;
|
|
882
|
+
$[1] = t1;
|
|
883
|
+
} else {
|
|
884
|
+
t1 = $[1];
|
|
885
|
+
}
|
|
886
|
+
const createSearch = t1;
|
|
887
|
+
let t2;
|
|
888
|
+
if ($[2] !== key) {
|
|
889
|
+
t2 = t3 => {
|
|
890
|
+
const count = t3 === undefined ? 5 : t3;
|
|
891
|
+
if (typeof window !== "undefined") {
|
|
892
|
+
const recent_0 = window.localStorage.getItem(key) || null;
|
|
893
|
+
const current_0 = recent_0 !== null ? JSON.parse(recent_0 || "[]") : [];
|
|
894
|
+
return current_0.slice(0, count);
|
|
895
|
+
}
|
|
896
|
+
return [];
|
|
897
|
+
};
|
|
898
|
+
$[2] = key;
|
|
899
|
+
$[3] = t2;
|
|
900
|
+
} else {
|
|
901
|
+
t2 = $[3];
|
|
902
|
+
}
|
|
903
|
+
const getSearches = t2;
|
|
904
|
+
let t3;
|
|
905
|
+
if ($[4] !== createSearch || $[5] !== getSearches) {
|
|
906
|
+
t3 = {
|
|
907
|
+
createSearch,
|
|
908
|
+
getSearches
|
|
909
|
+
};
|
|
910
|
+
$[4] = createSearch;
|
|
911
|
+
$[5] = getSearches;
|
|
912
|
+
$[6] = t3;
|
|
913
|
+
} else {
|
|
914
|
+
t3 = $[6];
|
|
915
|
+
}
|
|
916
|
+
return t3;
|
|
911
917
|
};
|
|
912
918
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
919
|
+
const useMediaTags = (t0, t1, t2) => {
|
|
920
|
+
const $ = c(13);
|
|
921
|
+
const query = t0 === undefined ? null : t0;
|
|
922
|
+
const count = t1 === undefined ? 5 : t1;
|
|
923
|
+
const opts = t2 === undefined ? null : t2;
|
|
924
|
+
const api = useApi();
|
|
925
|
+
let t3;
|
|
926
|
+
if ($[0] !== api || $[1] !== count || $[2] !== query) {
|
|
927
|
+
t3 = () => api.medias.getTags(query, count);
|
|
928
|
+
$[0] = api;
|
|
929
|
+
$[1] = count;
|
|
930
|
+
$[2] = query;
|
|
931
|
+
$[3] = t3;
|
|
932
|
+
} else {
|
|
933
|
+
t3 = $[3];
|
|
934
|
+
}
|
|
935
|
+
const getItems = t3;
|
|
936
|
+
let t4;
|
|
937
|
+
if ($[4] !== getItems || $[5] !== opts) {
|
|
938
|
+
t4 = {
|
|
939
|
+
getItems,
|
|
940
|
+
...opts
|
|
941
|
+
};
|
|
942
|
+
$[4] = getItems;
|
|
943
|
+
$[5] = opts;
|
|
944
|
+
$[6] = t4;
|
|
945
|
+
} else {
|
|
946
|
+
t4 = $[6];
|
|
947
|
+
}
|
|
948
|
+
const t5 = useItems$1(t4);
|
|
949
|
+
let items;
|
|
950
|
+
let request;
|
|
951
|
+
if ($[7] !== t5) {
|
|
952
|
+
const {
|
|
953
|
+
items: t6,
|
|
954
|
+
pageItems,
|
|
955
|
+
...t7
|
|
956
|
+
} = t5;
|
|
957
|
+
items = t6;
|
|
958
|
+
request = t7;
|
|
959
|
+
$[7] = t5;
|
|
960
|
+
$[8] = items;
|
|
961
|
+
$[9] = request;
|
|
962
|
+
} else {
|
|
963
|
+
items = $[8];
|
|
964
|
+
request = $[9];
|
|
965
|
+
}
|
|
966
|
+
let t6;
|
|
967
|
+
if ($[10] !== items || $[11] !== request) {
|
|
968
|
+
t6 = {
|
|
969
|
+
tags: items,
|
|
970
|
+
...request
|
|
971
|
+
};
|
|
972
|
+
$[10] = items;
|
|
973
|
+
$[11] = request;
|
|
974
|
+
$[12] = t6;
|
|
975
|
+
} else {
|
|
976
|
+
t6 = $[12];
|
|
977
|
+
}
|
|
978
|
+
return t6;
|
|
931
979
|
};
|
|
932
980
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
981
|
+
const useMediaUpdate = () => {
|
|
982
|
+
const $ = c(5);
|
|
983
|
+
const [updating, setUpdating] = useState(false);
|
|
984
|
+
const api = useApi();
|
|
985
|
+
let t0;
|
|
986
|
+
if ($[0] !== api) {
|
|
987
|
+
t0 = (id, data) => {
|
|
988
|
+
setUpdating(true);
|
|
989
|
+
return api.medias.update(id, data).then(response => {
|
|
990
|
+
setUpdating(false);
|
|
991
|
+
return response;
|
|
992
|
+
});
|
|
993
|
+
};
|
|
994
|
+
$[0] = api;
|
|
995
|
+
$[1] = t0;
|
|
996
|
+
} else {
|
|
997
|
+
t0 = $[1];
|
|
998
|
+
}
|
|
999
|
+
const update = t0;
|
|
1000
|
+
let t1;
|
|
1001
|
+
if ($[2] !== update || $[3] !== updating) {
|
|
1002
|
+
t1 = {
|
|
1003
|
+
update,
|
|
1004
|
+
updating
|
|
1005
|
+
};
|
|
1006
|
+
$[2] = update;
|
|
1007
|
+
$[3] = updating;
|
|
1008
|
+
$[4] = t1;
|
|
1009
|
+
} else {
|
|
1010
|
+
t1 = $[4];
|
|
1011
|
+
}
|
|
1012
|
+
return t1;
|
|
950
1013
|
};
|
|
951
1014
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1015
|
+
const useMediaRequestDelete = () => {
|
|
1016
|
+
const $ = c(5);
|
|
1017
|
+
const [requesting, setRequesting] = useState(false);
|
|
1018
|
+
const api = useApi();
|
|
1019
|
+
let t0;
|
|
1020
|
+
if ($[0] !== api) {
|
|
1021
|
+
t0 = id => {
|
|
1022
|
+
setRequesting(true);
|
|
1023
|
+
return api.medias.requestDeleteMedia(id).then(response => {
|
|
1024
|
+
setRequesting(false);
|
|
1025
|
+
return response;
|
|
1026
|
+
});
|
|
1027
|
+
};
|
|
1028
|
+
$[0] = api;
|
|
1029
|
+
$[1] = t0;
|
|
1030
|
+
} else {
|
|
1031
|
+
t0 = $[1];
|
|
1032
|
+
}
|
|
1033
|
+
const requestDeleteMedia = t0;
|
|
1034
|
+
let t1;
|
|
1035
|
+
if ($[2] !== requestDeleteMedia || $[3] !== requesting) {
|
|
1036
|
+
t1 = {
|
|
1037
|
+
requestDeleteMedia,
|
|
1038
|
+
requesting
|
|
1039
|
+
};
|
|
1040
|
+
$[2] = requestDeleteMedia;
|
|
1041
|
+
$[3] = requesting;
|
|
1042
|
+
$[4] = t1;
|
|
1043
|
+
} else {
|
|
1044
|
+
t1 = $[4];
|
|
1045
|
+
}
|
|
1046
|
+
return t1;
|
|
969
1047
|
};
|
|
970
1048
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1049
|
+
const useMediaDelete = () => {
|
|
1050
|
+
const $ = c(5);
|
|
1051
|
+
const [deleting, setDeleting] = useState(false);
|
|
1052
|
+
const api = useApi();
|
|
1053
|
+
let t0;
|
|
1054
|
+
if ($[0] !== api) {
|
|
1055
|
+
t0 = id => {
|
|
1056
|
+
setDeleting(true);
|
|
1057
|
+
return api.medias.delete(id).then(response => {
|
|
1058
|
+
setDeleting(false);
|
|
1059
|
+
return response;
|
|
1060
|
+
});
|
|
1061
|
+
};
|
|
1062
|
+
$[0] = api;
|
|
1063
|
+
$[1] = t0;
|
|
1064
|
+
} else {
|
|
1065
|
+
t0 = $[1];
|
|
1066
|
+
}
|
|
1067
|
+
const deleteMedia = t0;
|
|
1068
|
+
let t1;
|
|
1069
|
+
if ($[2] !== deleteMedia || $[3] !== deleting) {
|
|
1070
|
+
t1 = {
|
|
1071
|
+
deleteMedia,
|
|
1072
|
+
deleting
|
|
1073
|
+
};
|
|
1074
|
+
$[2] = deleteMedia;
|
|
1075
|
+
$[3] = deleting;
|
|
1076
|
+
$[4] = t1;
|
|
1077
|
+
} else {
|
|
1078
|
+
t1 = $[4];
|
|
1079
|
+
}
|
|
1080
|
+
return t1;
|
|
988
1081
|
};
|
|
989
1082
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
return _objectSpread({
|
|
1015
|
-
quiz: data || []
|
|
1016
|
-
}, request);
|
|
1083
|
+
const useQuiz = (options = null) => {
|
|
1084
|
+
const {
|
|
1085
|
+
screenId = null,
|
|
1086
|
+
storyId: providedStoryId = null,
|
|
1087
|
+
opts = {}
|
|
1088
|
+
} = options || {};
|
|
1089
|
+
const api = useApi();
|
|
1090
|
+
const {
|
|
1091
|
+
id: storyId,
|
|
1092
|
+
document_id: documentId
|
|
1093
|
+
} = useStory() || {};
|
|
1094
|
+
const loader = useCallback(() => api !== null ? api.quiz.results(screenId, {
|
|
1095
|
+
story_id: documentId || providedStoryId || storyId
|
|
1096
|
+
}) : null, [api, screenId, documentId, providedStoryId, storyId]);
|
|
1097
|
+
const {
|
|
1098
|
+
data,
|
|
1099
|
+
...request
|
|
1100
|
+
} = api !== null ? useData(loader, opts) : {
|
|
1101
|
+
data: null
|
|
1102
|
+
};
|
|
1103
|
+
return {
|
|
1104
|
+
quiz: data || [],
|
|
1105
|
+
...request
|
|
1106
|
+
};
|
|
1017
1107
|
};
|
|
1018
1108
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
visitorId = _ref2.id;
|
|
1037
|
-
var _ref3 = useStory() || {},
|
|
1038
|
-
storyId = _ref3.id,
|
|
1039
|
-
documentId = _ref3.document_id;
|
|
1040
|
-
var create = useCallback(function (data) {
|
|
1109
|
+
const useQuizCreate = (options = null) => {
|
|
1110
|
+
const {
|
|
1111
|
+
screenId = null,
|
|
1112
|
+
visitorId: providedVisitorId = null,
|
|
1113
|
+
storyId: providedStoryId = null,
|
|
1114
|
+
onSuccess = null
|
|
1115
|
+
} = options || {};
|
|
1116
|
+
const api = useApi();
|
|
1117
|
+
const [creating, setCreating] = useState(false);
|
|
1118
|
+
const {
|
|
1119
|
+
id: visitorId
|
|
1120
|
+
} = useVisitor() || {};
|
|
1121
|
+
const {
|
|
1122
|
+
id: storyId,
|
|
1123
|
+
document_id: documentId
|
|
1124
|
+
} = useStory() || {};
|
|
1125
|
+
const create = useCallback(data => {
|
|
1041
1126
|
if (api === null) {
|
|
1042
1127
|
return null;
|
|
1043
1128
|
}
|
|
1044
1129
|
setCreating(true);
|
|
1045
|
-
return api.quiz.create(
|
|
1130
|
+
return api.quiz.create({
|
|
1046
1131
|
screen_id: screenId,
|
|
1047
1132
|
visitor_id: providedVisitorId || visitorId,
|
|
1048
|
-
story_id: documentId || providedStoryId || storyId
|
|
1049
|
-
|
|
1133
|
+
story_id: documentId || providedStoryId || storyId,
|
|
1134
|
+
...data
|
|
1135
|
+
}).then(response => {
|
|
1050
1136
|
setCreating(false);
|
|
1051
1137
|
if (onSuccess !== null) {
|
|
1052
1138
|
onSuccess(response);
|
|
@@ -1055,23 +1141,36 @@ var useQuizCreate = function useQuizCreate() {
|
|
|
1055
1141
|
});
|
|
1056
1142
|
}, [api, setCreating, onSuccess, screenId, visitorId, storyId, providedVisitorId, providedStoryId]);
|
|
1057
1143
|
return {
|
|
1058
|
-
create
|
|
1059
|
-
creating
|
|
1144
|
+
create,
|
|
1145
|
+
creating
|
|
1060
1146
|
};
|
|
1061
1147
|
};
|
|
1062
1148
|
|
|
1063
|
-
function DataProvider(
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
apiBaseUrl
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1149
|
+
function DataProvider(t0) {
|
|
1150
|
+
const $ = c(4);
|
|
1151
|
+
const {
|
|
1152
|
+
api: t1,
|
|
1153
|
+
apiBaseUrl: t2,
|
|
1154
|
+
children: t3
|
|
1155
|
+
} = t0;
|
|
1156
|
+
const api = t1 === undefined ? null : t1;
|
|
1157
|
+
const apiBaseUrl = t2 === undefined ? undefined : t2;
|
|
1158
|
+
const children = t3 === undefined ? null : t3;
|
|
1159
|
+
let t4;
|
|
1160
|
+
if ($[0] !== api || $[1] !== apiBaseUrl || $[2] !== children) {
|
|
1161
|
+
t4 = /*#__PURE__*/jsx(ApiProvider, {
|
|
1162
|
+
api: api,
|
|
1163
|
+
baseUrl: apiBaseUrl,
|
|
1164
|
+
children: children
|
|
1165
|
+
});
|
|
1166
|
+
$[0] = api;
|
|
1167
|
+
$[1] = apiBaseUrl;
|
|
1168
|
+
$[2] = children;
|
|
1169
|
+
$[3] = t4;
|
|
1170
|
+
} else {
|
|
1171
|
+
t4 = $[3];
|
|
1172
|
+
}
|
|
1173
|
+
return t4;
|
|
1075
1174
|
}
|
|
1076
1175
|
|
|
1077
1176
|
export { Api, ApiProvider, Base as BaseApi, DataProvider, useApi, useContributionCreate, useContributions, useData, useItems$1 as useItems, useMedia, useMediaAuthors, useMediaCreate, useMediaDelete, useMediaRequestDelete, useMediaTags, useMediaUpdate, useMedias, useMediasRecent as useMediasRecentSearches, useQuiz, useQuizCreate };
|