@panneau/data 2.0.40 → 2.0.44
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 +49 -3
- package/lib/index.js +49 -3
- package/package.json +3 -3
package/es/index.js
CHANGED
|
@@ -244,6 +244,49 @@ var useItems = function useItems(_ref) {
|
|
|
244
244
|
var nextPage = getNextPage();
|
|
245
245
|
return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
|
|
246
246
|
};
|
|
247
|
+
var reloadPage = function reloadPage() {
|
|
248
|
+
if (loading) {
|
|
249
|
+
return Promise.reject();
|
|
250
|
+
}
|
|
251
|
+
return loadItems(page);
|
|
252
|
+
};
|
|
253
|
+
var reload = function reload() {
|
|
254
|
+
if (loading) {
|
|
255
|
+
return Promise.reject();
|
|
256
|
+
}
|
|
257
|
+
return loadItems();
|
|
258
|
+
};
|
|
259
|
+
var updateItem = function updateItem(newItem) {
|
|
260
|
+
if (loading) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (isPaginated) {
|
|
264
|
+
var currentPages = pages || [];
|
|
265
|
+
updateState({
|
|
266
|
+
pages: currentPages.map(function (pageData) {
|
|
267
|
+
var pageItems = pageData.items || [];
|
|
268
|
+
if (pageItems.findIndex(function (_ref5) {
|
|
269
|
+
var id = _ref5.id;
|
|
270
|
+
return id === newItem.id;
|
|
271
|
+
}) !== -1) {
|
|
272
|
+
return _objectSpread(_objectSpread({}, pageData), {}, {
|
|
273
|
+
items: pageItems.map(function (it) {
|
|
274
|
+
return it.id === newItem.id ? newItem : it;
|
|
275
|
+
})
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return pageData;
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
} else {
|
|
282
|
+
var currentItems = items || [];
|
|
283
|
+
updateState({
|
|
284
|
+
items: currentItems.map(function (it) {
|
|
285
|
+
return it.id === newItem.id ? newItem : it;
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
};
|
|
247
290
|
useEffect(function () {
|
|
248
291
|
var hadState = lastState.current !== null;
|
|
249
292
|
lastState.current = initialState;
|
|
@@ -266,8 +309,8 @@ var useItems = function useItems(_ref) {
|
|
|
266
309
|
}
|
|
267
310
|
};
|
|
268
311
|
}, [getPage, getItems, page]);
|
|
269
|
-
var currentPage = isPaginated && pages !== null ? pages.find(function (
|
|
270
|
-
var pageNumber =
|
|
312
|
+
var currentPage = isPaginated && pages !== null ? pages.find(function (_ref6) {
|
|
313
|
+
var pageNumber = _ref6.page;
|
|
271
314
|
return parseInt(pageNumber, 10) === parseInt(page, 10);
|
|
272
315
|
}) || null : null;
|
|
273
316
|
return {
|
|
@@ -280,7 +323,10 @@ var useItems = function useItems(_ref) {
|
|
|
280
323
|
allLoaded: !isPaginated && loaded || lastPage !== -1 && isPaginated && pages.length === lastPage,
|
|
281
324
|
loading: loading,
|
|
282
325
|
loadNextPage: loadNextPage,
|
|
283
|
-
loadPage: loadPage
|
|
326
|
+
loadPage: loadPage,
|
|
327
|
+
reloadPage: reloadPage,
|
|
328
|
+
reload: reload,
|
|
329
|
+
updateItem: updateItem
|
|
284
330
|
};
|
|
285
331
|
};
|
|
286
332
|
|
package/lib/index.js
CHANGED
|
@@ -263,6 +263,49 @@ var useItems = function useItems(_ref) {
|
|
|
263
263
|
var nextPage = getNextPage();
|
|
264
264
|
return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
|
|
265
265
|
};
|
|
266
|
+
var reloadPage = function reloadPage() {
|
|
267
|
+
if (loading) {
|
|
268
|
+
return Promise.reject();
|
|
269
|
+
}
|
|
270
|
+
return loadItems(page);
|
|
271
|
+
};
|
|
272
|
+
var reload = function reload() {
|
|
273
|
+
if (loading) {
|
|
274
|
+
return Promise.reject();
|
|
275
|
+
}
|
|
276
|
+
return loadItems();
|
|
277
|
+
};
|
|
278
|
+
var updateItem = function updateItem(newItem) {
|
|
279
|
+
if (loading) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (isPaginated) {
|
|
283
|
+
var currentPages = pages || [];
|
|
284
|
+
updateState({
|
|
285
|
+
pages: currentPages.map(function (pageData) {
|
|
286
|
+
var pageItems = pageData.items || [];
|
|
287
|
+
if (pageItems.findIndex(function (_ref5) {
|
|
288
|
+
var id = _ref5.id;
|
|
289
|
+
return id === newItem.id;
|
|
290
|
+
}) !== -1) {
|
|
291
|
+
return _objectSpread__default["default"](_objectSpread__default["default"]({}, pageData), {}, {
|
|
292
|
+
items: pageItems.map(function (it) {
|
|
293
|
+
return it.id === newItem.id ? newItem : it;
|
|
294
|
+
})
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return pageData;
|
|
298
|
+
})
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
var currentItems = items || [];
|
|
302
|
+
updateState({
|
|
303
|
+
items: currentItems.map(function (it) {
|
|
304
|
+
return it.id === newItem.id ? newItem : it;
|
|
305
|
+
})
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
};
|
|
266
309
|
React.useEffect(function () {
|
|
267
310
|
var hadState = lastState.current !== null;
|
|
268
311
|
lastState.current = initialState;
|
|
@@ -285,8 +328,8 @@ var useItems = function useItems(_ref) {
|
|
|
285
328
|
}
|
|
286
329
|
};
|
|
287
330
|
}, [getPage, getItems, page]);
|
|
288
|
-
var currentPage = isPaginated && pages !== null ? pages.find(function (
|
|
289
|
-
var pageNumber =
|
|
331
|
+
var currentPage = isPaginated && pages !== null ? pages.find(function (_ref6) {
|
|
332
|
+
var pageNumber = _ref6.page;
|
|
290
333
|
return parseInt(pageNumber, 10) === parseInt(page, 10);
|
|
291
334
|
}) || null : null;
|
|
292
335
|
return {
|
|
@@ -299,7 +342,10 @@ var useItems = function useItems(_ref) {
|
|
|
299
342
|
allLoaded: !isPaginated && loaded || lastPage !== -1 && isPaginated && pages.length === lastPage,
|
|
300
343
|
loading: loading,
|
|
301
344
|
loadNextPage: loadNextPage,
|
|
302
|
-
loadPage: loadPage
|
|
345
|
+
loadPage: loadPage,
|
|
346
|
+
reloadPage: reloadPage,
|
|
347
|
+
reload: reload,
|
|
348
|
+
updateItem: updateItem
|
|
303
349
|
};
|
|
304
350
|
};
|
|
305
351
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/data",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/runtime": "^7.12.5",
|
|
56
56
|
"@folklore/fetch": "^0.1.15",
|
|
57
|
-
"@panneau/core": "^2.0.
|
|
57
|
+
"@panneau/core": "^2.0.42",
|
|
58
58
|
"prop-types": "^15.7.2",
|
|
59
59
|
"query-string": "^8.1.0",
|
|
60
60
|
"react-router": "^6.2.1"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "970a0645c75fcc4490380f2d17be2f628c40f1bd"
|
|
66
66
|
}
|