@xyo-network/react-payload 2.26.31 → 2.26.32
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.
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { XyoApiError } from '@xyo-network/api';
|
|
2
|
+
import { XyoPayload } from '@xyo-network/core';
|
|
3
|
+
export declare const usePayload: (hash?: string) => [XyoPayload | undefined, boolean, XyoApiError | undefined];
|
|
@@ -9,48 +9,33 @@ const react_1 = require("react");
|
|
|
9
9
|
const usePayload = (hash) => {
|
|
10
10
|
const { api } = (0, react_archivist_api_1.useArchivistApi)();
|
|
11
11
|
const { archive } = (0, react_archive_1.useArchive)();
|
|
12
|
-
const [
|
|
13
|
-
const [notFound, setNotFound] = (0, react_1.useState)();
|
|
12
|
+
const [notFound, setNotFound] = (0, react_1.useState)(false);
|
|
14
13
|
const [apiError, setApiError] = (0, react_1.useState)();
|
|
15
14
|
const [payload, setPayload] = (0, react_1.useState)();
|
|
16
|
-
const reset = () => {
|
|
17
|
-
setPayload(undefined);
|
|
18
|
-
setApiError(undefined);
|
|
19
|
-
setNotFound(undefined);
|
|
20
|
-
};
|
|
21
|
-
// allow for hash changes to retrigger the api call
|
|
22
|
-
(0, react_1.useEffect)(() => {
|
|
23
|
-
if (hash !== localHash) {
|
|
24
|
-
setLocalHash(hash);
|
|
25
|
-
reset();
|
|
26
|
-
}
|
|
27
|
-
}, [hash, localHash]);
|
|
28
15
|
(0, react_shared_1.useAsyncEffect)(
|
|
29
16
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
17
|
(mounted) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
if (
|
|
32
|
-
reset();
|
|
18
|
+
if (hash && hash.length > 0) {
|
|
33
19
|
try {
|
|
34
|
-
const result = yield (api === null || api === void 0 ? void 0 : api.archive(archive).payload.hash(
|
|
20
|
+
const result = yield (api === null || api === void 0 ? void 0 : api.archive(archive).payload.hash(hash).get());
|
|
35
21
|
if (mounted()) {
|
|
22
|
+
setApiError(undefined);
|
|
36
23
|
if (result === null || result === void 0 ? void 0 : result.length) {
|
|
37
24
|
setPayload(result[0]);
|
|
38
|
-
setNotFound(false);
|
|
39
25
|
}
|
|
40
|
-
else if (
|
|
26
|
+
else if (result) {
|
|
41
27
|
setNotFound(true);
|
|
42
28
|
setPayload(undefined);
|
|
43
29
|
}
|
|
44
30
|
}
|
|
45
31
|
}
|
|
46
32
|
catch (e) {
|
|
47
|
-
reset();
|
|
48
|
-
setNotFound(false);
|
|
49
33
|
setApiError(e);
|
|
34
|
+
setPayload(undefined);
|
|
50
35
|
console.error(e);
|
|
51
36
|
}
|
|
52
37
|
}
|
|
53
|
-
}), [hash, api, archive
|
|
38
|
+
}), [hash, api, archive]);
|
|
54
39
|
return [payload, notFound, apiError];
|
|
55
40
|
};
|
|
56
41
|
exports.usePayload = usePayload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePayload.js","sourceRoot":"","sources":["../../../src/hooks/usePayload.tsx"],"names":[],"mappings":";;;;AAAA,uDAAqD;AAGrD,8DAAuD;AACvD,0EAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"usePayload.js","sourceRoot":"","sources":["../../../src/hooks/usePayload.tsx"],"names":[],"mappings":";;;;AAAA,uDAAqD;AAGrD,8DAAuD;AACvD,0EAAkE;AAClE,iCAAgC;AAEzB,MAAM,UAAU,GAAG,CAAC,IAAa,EAA8D,EAAE;IACtG,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,qCAAe,GAAE,CAAA;IACjC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,0BAAU,GAAE,CAAA;IAChC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAA;IAC/C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,GAAe,CAAA;IACvD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,GAAc,CAAA;IACpD,IAAA,6BAAc;IACZ,uDAAuD;IACvD,CAAO,OAAO,EAAE,EAAE;QAChB,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,IAAI;gBACF,MAAM,MAAM,GAAG,MAAM,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAA,CAAA;gBACnE,IAAI,OAAO,EAAE,EAAE;oBACb,WAAW,CAAC,SAAS,CAAC,CAAA;oBACtB,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE;wBAClB,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;qBACtB;yBAAM,IAAI,MAAM,EAAE;wBACjB,WAAW,CAAC,IAAI,CAAC,CAAA;wBACjB,UAAU,CAAC,SAAS,CAAC,CAAA;qBACtB;iBACF;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,WAAW,CAAC,CAAgB,CAAC,CAAA;gBAC7B,UAAU,CAAC,SAAS,CAAC,CAAA;gBACrB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;aACjB;SACF;IACH,CAAC,CAAA,EACD,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CACrB,CAAA;IACD,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;AACtC,CAAC,CAAA;AA/BY,QAAA,UAAU,cA+BtB"}
|
package/package.json
CHANGED
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"@xyo-network/api": "^2.22.11",
|
|
22
22
|
"@xyo-network/network": "^2.22.11",
|
|
23
23
|
"@xyo-network/payload": "^2.22.11",
|
|
24
|
-
"@xyo-network/react-archive": "^2.26.
|
|
25
|
-
"@xyo-network/react-archivist": "^2.26.
|
|
26
|
-
"@xyo-network/react-archivist-api": "^2.26.
|
|
27
|
-
"@xyo-network/react-auth-service": "^2.26.
|
|
28
|
-
"@xyo-network/react-network": "^2.26.
|
|
29
|
-
"@xyo-network/react-property": "^2.26.
|
|
30
|
-
"@xyo-network/react-schema": "^2.26.
|
|
31
|
-
"@xyo-network/react-shared": "^2.26.
|
|
24
|
+
"@xyo-network/react-archive": "^2.26.32",
|
|
25
|
+
"@xyo-network/react-archivist": "^2.26.32",
|
|
26
|
+
"@xyo-network/react-archivist-api": "^2.26.32",
|
|
27
|
+
"@xyo-network/react-auth-service": "^2.26.32",
|
|
28
|
+
"@xyo-network/react-network": "^2.26.32",
|
|
29
|
+
"@xyo-network/react-property": "^2.26.32",
|
|
30
|
+
"@xyo-network/react-schema": "^2.26.32",
|
|
31
|
+
"@xyo-network/react-shared": "^2.26.32",
|
|
32
32
|
"@xyo-network/utils": "^2.22.11",
|
|
33
33
|
"luxon": "^3.0.1",
|
|
34
34
|
"react": "^18.2.0",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
},
|
|
96
96
|
"sideEffects": false,
|
|
97
97
|
"types": "dist/esm/index.d.ts",
|
|
98
|
-
"version": "2.26.
|
|
98
|
+
"version": "2.26.32"
|
|
99
99
|
}
|