@xyo-network/os-react-runtime 4.2.0-rc.1 → 4.2.0-rc.11

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.
Files changed (43) hide show
  1. package/dist/browser/DappPathSwitcher.d.ts.map +1 -1
  2. package/dist/browser/hooks/os/useDappContextCreator.d.ts.map +1 -1
  3. package/dist/browser/index.mjs +87 -90
  4. package/dist/browser/index.mjs.map +1 -1
  5. package/dist/browser/modules/Dapp/Container.d.ts +1 -0
  6. package/dist/browser/modules/Dapp/Container.d.ts.map +1 -1
  7. package/dist/browser/modules/Dapp/Page/Row.d.ts +2 -1
  8. package/dist/browser/modules/Dapp/Page/Row.d.ts.map +1 -1
  9. package/dist/browser/modules/Dapp/modules/Window/DappWindow.d.ts +4 -3
  10. package/dist/browser/modules/Dapp/modules/Window/DappWindow.d.ts.map +1 -1
  11. package/dist/browser/modules/Dapp/modules/Window/hooks/index.d.ts +1 -0
  12. package/dist/browser/modules/Dapp/modules/Window/hooks/index.d.ts.map +1 -1
  13. package/dist/browser/modules/Dapp/modules/Window/hooks/lib/deriveDappState.d.ts +3 -3
  14. package/dist/browser/modules/Dapp/modules/Window/hooks/lib/deriveDappState.d.ts.map +1 -1
  15. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/index.d.ts +4 -4
  16. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/index.d.ts.map +1 -1
  17. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappInjectableParamsFromRoute.d.ts +1 -1
  18. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappInjectableParamsFromRoute.d.ts.map +1 -1
  19. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappPathFromRoute.d.ts +2 -0
  20. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappPathFromRoute.d.ts.map +1 -1
  21. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappStateFromRoute.d.ts +2 -2
  22. package/dist/browser/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappStateFromRoute.d.ts.map +1 -1
  23. package/dist/browser/modules/Dapp/modules/Window/hooks/route/index.d.ts +0 -1
  24. package/dist/browser/modules/Dapp/modules/Window/hooks/route/index.d.ts.map +1 -1
  25. package/package.json +9 -9
  26. package/src/DappPathSwitcher.tsx +11 -9
  27. package/src/hooks/os/useDappContextCreator.tsx +20 -15
  28. package/src/hooks/os/useWidgetDapps.tsx +1 -1
  29. package/src/modules/Dapp/Container.tsx +10 -4
  30. package/src/modules/Dapp/Page/Row.tsx +8 -10
  31. package/src/modules/Dapp/modules/Window/DappWindow.tsx +16 -21
  32. package/src/modules/Dapp/modules/Window/hooks/index.ts +1 -0
  33. package/src/modules/Dapp/modules/Window/hooks/lib/deriveDappState.ts +6 -6
  34. package/src/modules/Dapp/modules/Window/hooks/menu/useDappMenu.tsx +1 -1
  35. package/src/modules/Dapp/modules/Window/hooks/route/helpers/RoutingNodes.md +7 -0
  36. package/src/modules/Dapp/modules/Window/hooks/route/helpers/index.ts +4 -4
  37. package/src/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappInjectableParamsFromRoute.tsx +1 -1
  38. package/src/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappPathFromRoute.tsx +2 -0
  39. package/src/modules/Dapp/modules/Window/hooks/route/helpers/useManageDappStateFromRoute.tsx +26 -20
  40. package/src/modules/Dapp/modules/Window/hooks/route/index.ts +0 -1
  41. package/dist/browser/modules/Dapp/modules/Window/hooks/route/useManageDappBasedOffRoute.d.ts +0 -19
  42. package/dist/browser/modules/Dapp/modules/Window/hooks/route/useManageDappBasedOffRoute.d.ts.map +0 -1
  43. package/src/modules/Dapp/modules/Window/hooks/route/useManageDappBasedOffRoute.tsx +0 -33
@@ -2,44 +2,50 @@ import { usePromise } from '@xylabs/react-promise'
2
2
  import type { DappIntent } from '@xyo-network/os-model'
3
3
  import { DappIntentTypes } from '@xyo-network/os-model'
4
4
  import { DappIntentCaller, NameTransforms } from '@xyo-network/os-runtime'
5
- import { useNavigationType, useParams } from 'react-router-dom'
5
+ import { useRef } from 'react'
6
+ import { useParams } from 'react-router-dom'
6
7
 
7
8
  import { useDappIntentCaller, useSendDappIntent } from '../../../../../../../hooks/index.ts'
8
9
 
9
- /** React to changes in `dappName` route param */
10
- export const useManageDappStateFromRoute = (intentPayload?: DappIntent, dappName?: string) => {
10
+ /** Launch or close the dapp based off changes to the `dappName` route param */
11
+ export const useManageDappStateFromRoute = (intentPayload?: DappIntent) => {
11
12
  const params = useParams()
12
13
  const { dappName: dappNameParam } = params
13
14
  const sendIntent = useSendDappIntent()
14
- const navigationType = useNavigationType()
15
15
  const intentCaller = useDappIntentCaller()
16
16
 
17
+ // refs to track the dappName param and the last intent sent
18
+ const dappNameParamRef = useRef<string>()
19
+ const intentRef = useRef<DappIntent>()
20
+
17
21
  // auto-close the dapp if it was launched and the route param goes undefined (i.e. back button clicked)
18
22
  usePromise(async () => {
19
23
  const launched = intentPayload?.intent === DappIntentTypes.Launch
20
- if (launched && dappNameParam === undefined && sendIntent && navigationType === 'POP') {
21
- const closeIntent = DappIntentCaller.buildIntent(DappIntentCaller.OsDappName, DappIntentTypes.Close, dappName)
24
+ const dappNameParamRemoved = !!dappNameParamRef.current && dappNameParam === undefined
25
+ // The last intent was Launch and the dappName param was removed
26
+ if (launched && dappNameParamRemoved && sendIntent) {
27
+ const closeIntent = DappIntentCaller.buildIntent(DappIntentCaller.OsDappName, DappIntentTypes.Close)
22
28
  await sendIntent(closeIntent)
23
29
  }
24
- }, [dappName, dappNameParam, intentPayload, navigationType, sendIntent])
30
+
31
+ // sync back the dappNameParamRef for future checks
32
+ dappNameParamRef.current = dappNameParam
33
+ }, [dappNameParam, intentPayload, sendIntent])
25
34
 
26
35
  // auto-launch the dapp if the route param matches the dapp name
27
36
  usePromise(async () => {
28
- if (dappNameParam && dappName && sendIntent && intentCaller) {
37
+ if (dappNameParam && sendIntent && intentCaller) {
29
38
  const dappNameParamDeSlugged = new NameTransforms(dappNameParam).deSlug()
39
+ // no intents have been sent yet and the dappName param is set so we need to auto launch the dapp
40
+ const autoLaunchNeeded = intentRef.current === undefined && dappNameParam
30
41
 
31
- const notLaunched = intentPayload?.intent !== DappIntentTypes.Launch
32
- const paramMatchesDappName = dappNameParamDeSlugged === dappName
33
-
34
- if (notLaunched && paramMatchesDappName) {
35
- const latestIntent = await intentCaller.latestIntent()
36
- const existing = latestIntent && latestIntent.targetDappId === dappNameParamDeSlugged
37
- if (!existing) {
38
- const launchIntent = DappIntentCaller.buildIntent(DappIntentCaller.OsDappName, DappIntentTypes.Launch, dappNameParamDeSlugged)
39
- await sendIntent(launchIntent)
40
- return
41
- }
42
+ if (autoLaunchNeeded) {
43
+ const launchIntent = DappIntentCaller.buildIntent(DappIntentCaller.OsDappName, DappIntentTypes.Launch, dappNameParamDeSlugged)
44
+ await sendIntent(launchIntent)
45
+ // sync back the intentRef to ensure the auto launch only happens once
46
+ intentRef.current = launchIntent
47
+ return
42
48
  }
43
49
  }
44
- }, [dappNameParam, dappName, sendIntent, intentCaller, intentPayload?.intent])
50
+ }, [dappNameParam, sendIntent, intentCaller, intentPayload?.intent])
45
51
  }
@@ -1,2 +1 @@
1
1
  export * from './helpers/index.ts'
2
- export * from './useManageDappBasedOffRoute.js'
@@ -1,19 +0,0 @@
1
- import type { DappIntent, XyOsContext } from '@xyo-network/os-model';
2
- /**
3
- * Manage the dapp based off the route params and intent type
4
- *
5
- * This hook centralizes the logic for managing the dapp based off the route.
6
- *
7
- * It reacts to changes in the route params and performs the following:
8
- *
9
- * 1. Launch or close the dapp based off changes to the `dappName` route params
10
- * 2. Update the menu archivist based off changes in the the `path` route param
11
- * 3. Update the dapp archivist with injectable params based off changes in the query params
12
- *
13
- * @param intentPayload - The intent type of the dapp
14
- * @param dappName - The name of the dapp
15
- * @param dappNode - The node instance of the dapp
16
- * @param context - The context of the dapp
17
- */
18
- export declare const useManageDappBasedOffRoute: (intentPayload?: DappIntent, dappName?: string, context?: XyOsContext | null) => (Error | undefined)[];
19
- //# sourceMappingURL=useManageDappBasedOffRoute.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useManageDappBasedOffRoute.d.ts","sourceRoot":"","sources":["../../../../../../../../src/modules/Dapp/modules/Window/hooks/route/useManageDappBasedOffRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AASpE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,0BAA0B,mBAAoB,UAAU,aAAa,MAAM,YAAY,WAAW,GAAG,IAAI,0BAOrH,CAAA"}
@@ -1,33 +0,0 @@
1
- import type { DappIntent, XyOsContext } from '@xyo-network/os-model'
2
-
3
- import {
4
- useManageDappInjectableParamsFromRoute,
5
- useManageDappIntentRequest,
6
- useManageDappPathFromRoute,
7
- useManageDappStateFromRoute,
8
- } from './helpers/index.ts'
9
-
10
- /**
11
- * Manage the dapp based off the route params and intent type
12
- *
13
- * This hook centralizes the logic for managing the dapp based off the route.
14
- *
15
- * It reacts to changes in the route params and performs the following:
16
- *
17
- * 1. Launch or close the dapp based off changes to the `dappName` route params
18
- * 2. Update the menu archivist based off changes in the the `path` route param
19
- * 3. Update the dapp archivist with injectable params based off changes in the query params
20
- *
21
- * @param intentPayload - The intent type of the dapp
22
- * @param dappName - The name of the dapp
23
- * @param dappNode - The node instance of the dapp
24
- * @param context - The context of the dapp
25
- */
26
- export const useManageDappBasedOffRoute = (intentPayload?: DappIntent, dappName?: string, context?: XyOsContext | null) => {
27
- const handleIntentError = useManageDappIntentRequest(context, dappName)
28
- useManageDappStateFromRoute(intentPayload, dappName)
29
- useManageDappPathFromRoute(context, dappName)
30
- const injectableErrors = useManageDappInjectableParamsFromRoute(context)
31
-
32
- return [...injectableErrors, handleIntentError]
33
- }