@xyo-network/react-payload 2.26.6 → 2.26.9
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/cjs/components/Details/HashSourceDetails.js +2 -2
- package/dist/cjs/components/Details/HashSourceDetails.js.map +1 -1
- package/dist/cjs/hooks/usePayload.js +8 -3
- package/dist/cjs/hooks/usePayload.js.map +1 -1
- package/dist/esm/components/Details/HashSourceDetails.js +1 -1
- package/dist/esm/components/Details/HashSourceDetails.js.map +1 -1
- package/dist/esm/hooks/usePayload.js +8 -3
- package/dist/esm/hooks/usePayload.js.map +1 -1
- package/package.json +19 -20
- package/src/components/Details/HashSourceDetails.tsx +1 -1
- package/src/hooks/usePayload.stories.tsx +69 -0
- package/src/hooks/usePayload.tsx +10 -3
|
@@ -5,15 +5,15 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const ContentCopy_1 = tslib_1.__importDefault(require("@mui/icons-material/ContentCopy"));
|
|
7
7
|
const material_1 = require("@mui/material");
|
|
8
|
-
const react_common_1 = require("@xylabs/react-common");
|
|
9
8
|
const react_flexbox_1 = require("@xylabs/react-flexbox");
|
|
9
|
+
const react_quick_tip_button_1 = require("@xylabs/react-quick-tip-button");
|
|
10
10
|
const payload_1 = require("@xyo-network/payload");
|
|
11
11
|
const PayloadHashSourceDetails = (_a) => {
|
|
12
12
|
var _b;
|
|
13
13
|
var { noTitle = false, payload } = _a, props = tslib_1.__rest(_a, ["noTitle", "payload"]);
|
|
14
14
|
const theme = (0, material_1.useTheme)();
|
|
15
15
|
const payloadWrapper = payload ? new payload_1.XyoPayloadWrapper(payload) : null;
|
|
16
|
-
return ((0, jsx_runtime_1.jsxs)(react_flexbox_1.FlexCol, Object.assign({ alignItems: "stretch" }, props, { children: [noTitle ? null : ((0, jsx_runtime_1.jsxs)(react_flexbox_1.FlexRow, Object.assign({ margin: 1, justifyContent: "flex-start" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: "Hash Source" }), (0, jsx_runtime_1.jsx)(
|
|
16
|
+
return ((0, jsx_runtime_1.jsxs)(react_flexbox_1.FlexCol, Object.assign({ alignItems: "stretch" }, props, { children: [noTitle ? null : ((0, jsx_runtime_1.jsxs)(react_flexbox_1.FlexRow, Object.assign({ margin: 1, justifyContent: "flex-start" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: "Hash Source" }), (0, jsx_runtime_1.jsx)(react_quick_tip_button_1.QuickTipButton, Object.assign({ title: "Hash Source" }, { children: "The actual string used to generate the hash (SHA256)" }))] }))), (0, jsx_runtime_1.jsxs)(react_flexbox_1.FlexRow, { children: [(0, jsx_runtime_1.jsx)(react_flexbox_1.FlexGrowRow, Object.assign({ background: true, border: 1, borderColor: theme.palette.divider, justifyContent: "start" }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ padding: 2, fontFamily: "monospace", variant: "body1", sx: { overflowWrap: 'break-word', wordBreak: 'break-all' } }, { children: (_b = payloadWrapper === null || payloadWrapper === void 0 ? void 0 : payloadWrapper.stringified) !== null && _b !== void 0 ? _b : '' })) })), (0, jsx_runtime_1.jsx)(material_1.IconButton, { children: (0, jsx_runtime_1.jsx)(ContentCopy_1.default, {}) })] }), noTitle ? ((0, jsx_runtime_1.jsx)(react_flexbox_1.FlexRow, Object.assign({ margin: 1, justifyContent: "flex-start" }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: "The actual string used to generate the hash (SHA256). This can be used to validate the hash manually." })) }))) : null] })));
|
|
17
17
|
};
|
|
18
18
|
exports.PayloadHashSourceDetails = PayloadHashSourceDetails;
|
|
19
19
|
//# sourceMappingURL=HashSourceDetails.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HashSourceDetails.js","sourceRoot":"","sources":["../../../../src/components/Details/HashSourceDetails.tsx"],"names":[],"mappings":";;;;;AAAA,0FA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G,GACR,IACL,EACT,OAAO,CAAC,CAAC,CAAC,CACT,uBAAC,uBAAO,kBAAC,MAAM,EAAE,CAAC,EAAE,cAAc,EAAC,YAAY,gBAC7C,uBAAC,qBAAU,kBAAC,OAAO,EAAC,OAAO,2HAAmH,IACtI,CACX,CAAC,CAAC,CAAC,IAAI,KACA,CACX,CAAA;AACH,CAAC,CAAA;AA7BY,QAAA,wBAAwB,4BA6BpC"}
|
|
@@ -12,14 +12,19 @@ const usePayload = (hash) => {
|
|
|
12
12
|
const [notFound, setNotFound] = (0, react_1.useState)(false);
|
|
13
13
|
const [apiError, setApiError] = (0, react_1.useState)();
|
|
14
14
|
const [payload, setPayload] = (0, react_1.useState)();
|
|
15
|
+
const reset = () => {
|
|
16
|
+
setPayload(undefined);
|
|
17
|
+
setApiError(undefined);
|
|
18
|
+
setNotFound(false);
|
|
19
|
+
};
|
|
15
20
|
(0, react_shared_1.useAsyncEffect)(
|
|
16
21
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
17
22
|
(mounted) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
if (hash && hash.length > 0) {
|
|
23
|
+
if (api && hash && hash.length > 0) {
|
|
19
24
|
try {
|
|
20
25
|
const result = yield (api === null || api === void 0 ? void 0 : api.archive(archive).payload.hash(hash).get());
|
|
21
26
|
if (mounted()) {
|
|
22
|
-
|
|
27
|
+
reset();
|
|
23
28
|
if (result === null || result === void 0 ? void 0 : result.length) {
|
|
24
29
|
setPayload(result[0]);
|
|
25
30
|
}
|
|
@@ -30,8 +35,8 @@ const usePayload = (hash) => {
|
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
catch (e) {
|
|
38
|
+
reset();
|
|
33
39
|
setApiError(e);
|
|
34
|
-
setPayload(undefined);
|
|
35
40
|
console.error(e);
|
|
36
41
|
}
|
|
37
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePayload.js","sourceRoot":"","sources":["../../../src/h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,IAAA,6BAAc;IACZ,uDAAuD;IACvD,CAAO,OAAO,EAAE,EAAE;QAChB,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAClC,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,KAAK,EAAE,CAAA;oBACP,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,KAAK,EAAE,CAAA;gBACP,WAAW,CAAC,CAAgB,CAAC,CAAA;gBAC7B,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;AAtCY,QAAA,UAAU,cAsCtB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
|
3
3
|
import { IconButton, Typography, useTheme } from '@mui/material';
|
|
4
|
-
import { QuickTipButton } from '@xylabs/react-common';
|
|
5
4
|
import { FlexCol, FlexGrowRow, FlexRow } from '@xylabs/react-flexbox';
|
|
5
|
+
import { QuickTipButton } from '@xylabs/react-quick-tip-button';
|
|
6
6
|
import { XyoPayloadWrapper } from '@xyo-network/payload';
|
|
7
7
|
export const PayloadHashSourceDetails = ({ noTitle = false, payload, ...props }) => {
|
|
8
8
|
const theme = useTheme();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HashSourceDetails.js","sourceRoot":"","sources":["../../../../src/components/Details/HashSourceDetails.tsx"],"names":[],"mappings":";AAAA,OAAO,eAAe,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"HashSourceDetails.js","sourceRoot":"","sources":["../../../../src/components/Details/HashSourceDetails.tsx"],"names":[],"mappings":";AAAA,OAAO,eAAe,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAgB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAc,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAOpE,MAAM,CAAC,MAAM,wBAAwB,GAA4C,CAAC,EAAE,OAAO,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IAC1H,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IACxB,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAEtE,OAAO,CACL,MAAC,OAAO,IAAC,UAAU,EAAC,SAAS,KAAK,KAAK,aACpC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAChB,MAAC,OAAO,IAAC,MAAM,EAAE,CAAC,EAAE,cAAc,EAAC,YAAY,aAC7C,KAAC,UAAU,8BAAyB,EACpC,KAAC,cAAc,IAAC,KAAK,EAAC,aAAa,qEAAsE,IACjG,CACX,EACD,MAAC,OAAO,eACN,KAAC,WAAW,IAAC,UAAU,QAAC,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,EAAC,OAAO,YAC3F,KAAC,UAAU,IAAC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAC,WAAW,EAAC,OAAO,EAAC,OAAO,EAAC,EAAE,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,YACtH,cAAc,EAAE,WAAW,IAAI,EAAE,GACvB,GACD,EACd,KAAC,UAAU,cACT,KAAC,eAAe,KAAG,GACR,IACL,EACT,OAAO,CAAC,CAAC,CAAC,CACT,KAAC,OAAO,IAAC,MAAM,EAAE,CAAC,EAAE,cAAc,EAAC,YAAY,YAC7C,KAAC,UAAU,IAAC,OAAO,EAAC,OAAO,sHAAmH,GACtI,CACX,CAAC,CAAC,CAAC,IAAI,IACA,CACX,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -8,14 +8,19 @@ export const usePayload = (hash) => {
|
|
|
8
8
|
const [notFound, setNotFound] = useState(false);
|
|
9
9
|
const [apiError, setApiError] = useState();
|
|
10
10
|
const [payload, setPayload] = useState();
|
|
11
|
+
const reset = () => {
|
|
12
|
+
setPayload(undefined);
|
|
13
|
+
setApiError(undefined);
|
|
14
|
+
setNotFound(false);
|
|
15
|
+
};
|
|
11
16
|
useAsyncEffect(
|
|
12
17
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
13
18
|
async (mounted) => {
|
|
14
|
-
if (hash && hash.length > 0) {
|
|
19
|
+
if (api && hash && hash.length > 0) {
|
|
15
20
|
try {
|
|
16
21
|
const result = await api?.archive(archive).payload.hash(hash).get();
|
|
17
22
|
if (mounted()) {
|
|
18
|
-
|
|
23
|
+
reset();
|
|
19
24
|
if (result?.length) {
|
|
20
25
|
setPayload(result[0]);
|
|
21
26
|
}
|
|
@@ -26,8 +31,8 @@ export const usePayload = (hash) => {
|
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
catch (e) {
|
|
34
|
+
reset();
|
|
29
35
|
setApiError(e);
|
|
30
|
-
setPayload(undefined);
|
|
31
36
|
console.error(e);
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePayload.js","sourceRoot":"","sources":["../../../src/hooks/usePayload.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAa,EAA8D,EAAE;IACtG,MAAM,EAAE,GAAG,EAAE,GAAG,eAAe,EAAE,CAAA;IACjC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,CAAA;IAChC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC/C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,EAAe,CAAA;IACvD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,EAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"usePayload.js","sourceRoot":"","sources":["../../../src/hooks/usePayload.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAA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C,CAAC,CAAA;aACjB;SACF;IACH,CAAC,EACD,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CACrB,CAAA;IACD,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;AACtC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -13,23 +13,22 @@
|
|
|
13
13
|
"@emotion/react": "^11.9.3",
|
|
14
14
|
"@emotion/styled": "^11.9.3",
|
|
15
15
|
"@mui/icons-material": "^5.8.4",
|
|
16
|
-
"@mui/material": "^5.8.
|
|
17
|
-
"@xylabs/react-button": "^2.14.
|
|
18
|
-
"@xylabs/react-
|
|
19
|
-
"@xylabs/react-
|
|
20
|
-
"@xylabs/react-shared": "^2.14.
|
|
21
|
-
"@xyo-network/api": "^2.21.
|
|
22
|
-
"@xyo-network/
|
|
23
|
-
"@xyo-network/
|
|
24
|
-
"@xyo-network/
|
|
25
|
-
"@xyo-network/react-
|
|
26
|
-
"@xyo-network/react-
|
|
27
|
-
"@xyo-network/react-
|
|
28
|
-
"@xyo-network/react-
|
|
29
|
-
"@xyo-network/react-
|
|
30
|
-
"@xyo-network/react-
|
|
31
|
-
"@xyo-network/
|
|
32
|
-
"@xyo-network/utils": "^2.21.13",
|
|
16
|
+
"@mui/material": "^5.8.7",
|
|
17
|
+
"@xylabs/react-button": "^2.14.5",
|
|
18
|
+
"@xylabs/react-flexbox": "^2.14.5",
|
|
19
|
+
"@xylabs/react-quick-tip-button": "^2.14.5",
|
|
20
|
+
"@xylabs/react-shared": "^2.14.5",
|
|
21
|
+
"@xyo-network/api": "^2.21.14",
|
|
22
|
+
"@xyo-network/network": "^2.21.14",
|
|
23
|
+
"@xyo-network/payload": "^2.21.14",
|
|
24
|
+
"@xyo-network/react-archive": "^2.26.9",
|
|
25
|
+
"@xyo-network/react-archivist-api": "^2.26.9",
|
|
26
|
+
"@xyo-network/react-auth-service": "^2.26.9",
|
|
27
|
+
"@xyo-network/react-network": "^2.26.9",
|
|
28
|
+
"@xyo-network/react-property": "^2.26.9",
|
|
29
|
+
"@xyo-network/react-schema": "^2.26.9",
|
|
30
|
+
"@xyo-network/react-shared": "^2.26.9",
|
|
31
|
+
"@xyo-network/utils": "^2.21.14",
|
|
33
32
|
"luxon": "^2.4.0",
|
|
34
33
|
"react": "^18.2.0",
|
|
35
34
|
"react-dom": "^18.2.0",
|
|
@@ -40,8 +39,8 @@
|
|
|
40
39
|
},
|
|
41
40
|
"description": "Common React library for all XYO projects that use React",
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@babel/core": "^7.18.
|
|
44
|
-
"@babel/preset-env": "^7.18.
|
|
42
|
+
"@babel/core": "^7.18.6",
|
|
43
|
+
"@babel/preset-env": "^7.18.6",
|
|
45
44
|
"@storybook/react": "^6.5.9",
|
|
46
45
|
"@types/luxon": "^2.3.2",
|
|
47
46
|
"@xylabs/tsconfig": "^1.0.14"
|
|
@@ -95,6 +94,6 @@
|
|
|
95
94
|
},
|
|
96
95
|
"sideEffects": false,
|
|
97
96
|
"types": "dist/esm/index.d.ts",
|
|
98
|
-
"version": "2.26.
|
|
97
|
+
"version": "2.26.9",
|
|
99
98
|
"packageManager": "yarn@3.1.1"
|
|
100
99
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ContentCopyIcon from '@mui/icons-material/ContentCopy'
|
|
2
2
|
import { IconButton, Typography, useTheme } from '@mui/material'
|
|
3
|
-
import { QuickTipButton } from '@xylabs/react-common'
|
|
4
3
|
import { FlexBoxProps, FlexCol, FlexGrowRow, FlexRow } from '@xylabs/react-flexbox'
|
|
4
|
+
import { QuickTipButton } from '@xylabs/react-quick-tip-button'
|
|
5
5
|
import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'
|
|
6
6
|
|
|
7
7
|
export interface PayloadHashSourceDetailsProps extends FlexBoxProps {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* eslint-disable import/no-internal-modules */
|
|
2
|
+
import { ComponentStory, Meta } from '@storybook/react'
|
|
3
|
+
import { ButtonEx } from '@xylabs/react-button'
|
|
4
|
+
import { FlexCol } from '@xylabs/react-flexbox'
|
|
5
|
+
import { ArchivistApiProvider, useArchivistApi } from '@xyo-network/react-archivist-api'
|
|
6
|
+
import { lazy, Suspense, useState } from 'react'
|
|
7
|
+
|
|
8
|
+
import { usePayload } from './usePayload'
|
|
9
|
+
|
|
10
|
+
const JsonView = lazy(() => import(/* webpackChunkName: "jsonView" */ 'react-json-view'))
|
|
11
|
+
|
|
12
|
+
const apiDomain = 'https://beta.api.archivist.xyo.network'
|
|
13
|
+
const hash = '5605fabad11b10bb5fb86b309ca0970894eda8f22362dda1a489817723bca992'
|
|
14
|
+
|
|
15
|
+
const Wrapper: React.FC<{ hash?: string }> = ({ hash }) => (
|
|
16
|
+
<ArchivistApiProvider apiDomain={apiDomain}>
|
|
17
|
+
<UsePayloadComponent hash={hash} />
|
|
18
|
+
</ArchivistApiProvider>
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const UsePayloadComponent: React.FC<{ hash?: string }> = ({ hash }) => {
|
|
22
|
+
const { api } = useArchivistApi()
|
|
23
|
+
const [trigger, setTrigger] = useState<string>()
|
|
24
|
+
const [payload, notFound] = usePayload(trigger)
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<>
|
|
28
|
+
{api ? (
|
|
29
|
+
<>
|
|
30
|
+
<ButtonEx variant="contained" marginBottom={2} onClick={() => setTrigger(hash)}>
|
|
31
|
+
Fetch Payload
|
|
32
|
+
</ButtonEx>
|
|
33
|
+
<ButtonEx variant="contained" onClick={() => setTrigger('foo')}>
|
|
34
|
+
Fetch Not Found
|
|
35
|
+
</ButtonEx>
|
|
36
|
+
</>
|
|
37
|
+
) : null}
|
|
38
|
+
<FlexCol my={3}>
|
|
39
|
+
<Suspense fallback={<FlexCol busy />}>
|
|
40
|
+
{notFound ? 'Not Found' : null}
|
|
41
|
+
<JsonView src={payload || {}} />
|
|
42
|
+
</Suspense>
|
|
43
|
+
</FlexCol>
|
|
44
|
+
</>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const StorybookEntry: Meta = {
|
|
49
|
+
argTypes: {},
|
|
50
|
+
component: UsePayloadComponent,
|
|
51
|
+
parameters: {
|
|
52
|
+
docs: {
|
|
53
|
+
page: null,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
title: 'payload/usePayload',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const Template: ComponentStory<typeof UsePayloadComponent> = (props) => {
|
|
60
|
+
return <Wrapper {...props} />
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const Default = Template.bind({})
|
|
64
|
+
Default.args = { hash }
|
|
65
|
+
|
|
66
|
+
export { Default }
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line import/no-default-export
|
|
69
|
+
export default StorybookEntry
|
package/src/hooks/usePayload.tsx
CHANGED
|
@@ -11,14 +11,21 @@ export const usePayload = (hash?: string): [XyoPayload | undefined, boolean, Xyo
|
|
|
11
11
|
const [notFound, setNotFound] = useState(false)
|
|
12
12
|
const [apiError, setApiError] = useState<XyoApiError>()
|
|
13
13
|
const [payload, setPayload] = useState<XyoPayload>()
|
|
14
|
+
|
|
15
|
+
const reset = () => {
|
|
16
|
+
setPayload(undefined)
|
|
17
|
+
setApiError(undefined)
|
|
18
|
+
setNotFound(false)
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
useAsyncEffect(
|
|
15
22
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
16
23
|
async (mounted) => {
|
|
17
|
-
if (hash && hash.length > 0) {
|
|
24
|
+
if (api && hash && hash.length > 0) {
|
|
18
25
|
try {
|
|
19
26
|
const result = await api?.archive(archive).payload.hash(hash).get()
|
|
20
27
|
if (mounted()) {
|
|
21
|
-
|
|
28
|
+
reset()
|
|
22
29
|
if (result?.length) {
|
|
23
30
|
setPayload(result[0])
|
|
24
31
|
} else if (result) {
|
|
@@ -27,8 +34,8 @@ export const usePayload = (hash?: string): [XyoPayload | undefined, boolean, Xyo
|
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
} catch (e) {
|
|
37
|
+
reset()
|
|
30
38
|
setApiError(e as XyoApiError)
|
|
31
|
-
setPayload(undefined)
|
|
32
39
|
console.error(e)
|
|
33
40
|
}
|
|
34
41
|
}
|