@xyo-network/react-payload 2.26.7 → 2.26.8
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.
|
@@ -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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AE,OAAO,EAAE,EAAE;QAChB,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAClC,IAAI;gBACF,MAAM,MAAM,GAAG,MAAM,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;gBACnE,IAAI,OAAO,EAAE,EAAE;oBACb,KAAK,EAAE,CAAA;oBACP,IAAI,MAAM,EAAE,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,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
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"@xyo-network/core": "^2.21.13",
|
|
23
23
|
"@xyo-network/network": "^2.21.13",
|
|
24
24
|
"@xyo-network/payload": "^2.21.13",
|
|
25
|
-
"@xyo-network/react-archive": "^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.
|
|
25
|
+
"@xyo-network/react-archive": "^2.26.8",
|
|
26
|
+
"@xyo-network/react-archivist-api": "^2.26.8",
|
|
27
|
+
"@xyo-network/react-auth-service": "^2.26.8",
|
|
28
|
+
"@xyo-network/react-network": "^2.26.8",
|
|
29
|
+
"@xyo-network/react-property": "^2.26.8",
|
|
30
|
+
"@xyo-network/react-schema": "^2.26.8",
|
|
31
|
+
"@xyo-network/react-shared": "^2.26.8",
|
|
32
32
|
"@xyo-network/utils": "^2.21.13",
|
|
33
33
|
"luxon": "^2.4.0",
|
|
34
34
|
"react": "^18.2.0",
|
|
@@ -95,6 +95,6 @@
|
|
|
95
95
|
},
|
|
96
96
|
"sideEffects": false,
|
|
97
97
|
"types": "dist/esm/index.d.ts",
|
|
98
|
-
"version": "2.26.
|
|
98
|
+
"version": "2.26.8",
|
|
99
99
|
"packageManager": "yarn@3.1.1"
|
|
100
100
|
}
|
|
@@ -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
|
}
|