@dxos/react-client 2.18.3 → 2.19.0
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/.rush/temp/package-deps_build:test.json +23 -25
- package/.rush/temp/shrinkwrap-deps.json +56 -2
- package/README.md +6 -6
- package/dist/src/containers/ClientProvider.d.ts +29 -5
- package/dist/src/containers/ClientProvider.d.ts.map +1 -1
- package/dist/src/containers/ClientProvider.js +45 -4
- package/dist/src/containers/ClientProvider.js.map +1 -1
- package/dist/src/containers/ClientProvider.test.js +0 -2
- package/dist/src/containers/ClientProvider.test.js.map +1 -1
- package/dist/src/containers/index.d.ts +0 -2
- package/dist/src/containers/index.d.ts.map +1 -1
- package/dist/src/containers/index.js +0 -2
- package/dist/src/containers/index.js.map +1 -1
- package/dist/src/hooks/client/context.d.ts +5 -1
- package/dist/src/hooks/client/context.d.ts.map +1 -1
- package/dist/src/hooks/client/context.js.map +1 -1
- package/dist/src/hooks/client/useClient.d.ts +1 -1
- package/dist/src/hooks/client/useClient.d.ts.map +1 -1
- package/dist/src/hooks/client/useClient.js +3 -2
- package/dist/src/hooks/client/useClient.js.map +1 -1
- package/dist/src/hooks/client/useConfig.d.ts +1 -1
- package/dist/src/hooks/client/useConfig.js +3 -3
- package/dist/src/hooks/client/useConfig.js.map +1 -1
- package/dist/src/hooks/client/useProfile.d.ts +2 -2
- package/dist/src/hooks/client/useProfile.d.ts.map +1 -1
- package/dist/src/hooks/client/useProfile.js +1 -1
- package/dist/src/hooks/echo-queries/useContacts.d.ts +1 -1
- package/dist/src/hooks/echo-queries/useContacts.js +2 -2
- package/dist/src/hooks/echo-queries/useContacts.js.map +1 -1
- package/dist/src/hooks/echo-queries/useMembers.d.ts +3 -2
- package/dist/src/hooks/echo-queries/useMembers.d.ts.map +1 -1
- package/dist/src/hooks/echo-queries/useMembers.js.map +1 -1
- package/dist/src/hooks/echo-queries/useParties.d.ts +6 -6
- package/dist/src/hooks/echo-queries/useParties.d.ts.map +1 -1
- package/dist/src/hooks/echo-queries/useParties.js +2 -2
- package/dist/src/hooks/echo-queries/useParties.js.map +1 -1
- package/dist/src/hooks/echo-queries/useRemoteParties.d.ts +3 -4
- package/dist/src/hooks/echo-queries/useRemoteParties.d.ts.map +1 -1
- package/dist/src/hooks/echo-queries/useRemoteParties.js +1 -1
- package/dist/src/hooks/echo-queries/useRemoteParties.js.map +1 -1
- package/dist/src/index.d.ts +1 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/{containers → testing}/ProfileInitializer.d.ts +0 -0
- package/dist/src/testing/ProfileInitializer.d.ts.map +1 -0
- package/dist/src/{containers → testing}/ProfileInitializer.js +4 -2
- package/dist/src/testing/ProfileInitializer.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/{components → testing}/index.js +1 -1
- package/dist/src/testing/index.js.map +1 -0
- package/dist/stories/client.stories.d.ts +1 -0
- package/dist/stories/client.stories.d.ts.map +1 -1
- package/dist/stories/client.stories.js +9 -6
- package/dist/stories/client.stories.js.map +1 -1
- package/dist/stories/halo-invitations.stories.js +3 -3
- package/dist/stories/halo-invitations.stories.js.map +1 -1
- package/dist/stories/helpers/ClientPanel.d.ts +2 -3
- package/dist/stories/helpers/ClientPanel.d.ts.map +1 -1
- package/dist/stories/helpers/ClientPanel.js +1 -5
- package/dist/stories/helpers/ClientPanel.js.map +1 -1
- package/dist/stories/party-invitations.stories.js +3 -3
- package/dist/stories/party-invitations.stories.js.map +1 -1
- package/dist/tests/config.test.js +1 -1
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/esbuild-server.config.js +21 -0
- package/package.json +14 -10
- package/react-client.build.log +6 -6
- package/src/containers/ClientProvider.test.tsx +0 -2
- package/src/containers/ClientProvider.tsx +86 -7
- package/src/containers/index.ts +0 -2
- package/src/hooks/client/context.ts +5 -1
- package/src/hooks/client/useClient.ts +3 -2
- package/src/hooks/client/useConfig.ts +3 -3
- package/src/hooks/client/useProfile.ts +1 -1
- package/src/hooks/echo-queries/useContacts.ts +2 -2
- package/src/hooks/echo-queries/useMembers.tsx +3 -2
- package/src/hooks/echo-queries/useParties.ts +6 -6
- package/src/hooks/echo-queries/useRemoteParties.ts +4 -2
- package/src/index.ts +1 -2
- package/src/{containers → testing}/ProfileInitializer.tsx +4 -2
- package/src/testing/index.ts +5 -0
- package/stories/client.stories.tsx +14 -10
- package/stories/halo-invitations.stories.tsx +6 -6
- package/stories/helpers/ClientPanel.tsx +3 -8
- package/stories/party-invitations.stories.tsx +5 -5
- package/tests/config.test.ts +1 -1
- package/dist/src/components/ErrorBoundary.d.ts +0 -52
- package/dist/src/components/ErrorBoundary.d.ts.map +0 -1
- package/dist/src/components/ErrorBoundary.js +0 -78
- package/dist/src/components/ErrorBoundary.js.map +0 -1
- package/dist/src/components/index.d.ts +0 -2
- package/dist/src/components/index.d.ts.map +0 -1
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/config.d.ts +0 -8
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -11
- package/dist/src/config.js.map +0 -1
- package/dist/src/containers/ClientInitializer.d.ts +0 -30
- package/dist/src/containers/ClientInitializer.d.ts.map +0 -1
- package/dist/src/containers/ClientInitializer.js +0 -82
- package/dist/src/containers/ClientInitializer.js.map +0 -1
- package/dist/src/containers/ProfileInitializer.d.ts.map +0 -1
- package/dist/src/containers/ProfileInitializer.js.map +0 -1
- package/src/components/ErrorBoundary.tsx +0 -96
- package/src/components/index.ts +0 -5
- package/src/config.ts +0 -15
- package/src/containers/ClientInitializer.tsx +0 -121
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
FixMemdownPlugin,
|
|
7
|
+
NodeGlobalsPolyfillPlugin,
|
|
8
|
+
NodeModulesPlugin
|
|
9
|
+
} = require('@dxos/esbuild-plugins');
|
|
10
|
+
|
|
11
|
+
/** @type {import('@dxos/esbuild-server').Config} */
|
|
12
|
+
module.exports = {
|
|
13
|
+
plugins: [
|
|
14
|
+
NodeGlobalsPolyfillPlugin(),
|
|
15
|
+
FixMemdownPlugin(),
|
|
16
|
+
NodeModulesPlugin()
|
|
17
|
+
],
|
|
18
|
+
overrides: {
|
|
19
|
+
sourcemap: 'inline',
|
|
20
|
+
}
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -8,20 +8,23 @@
|
|
|
8
8
|
"main": "dist/src/index.js",
|
|
9
9
|
"types": "dist/src/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
|
+
"book": "esbuild-server book",
|
|
11
12
|
"build": "toolchain build",
|
|
12
13
|
"build:test": "toolchain build:test",
|
|
13
14
|
"lint": "toolchain lint",
|
|
14
15
|
"test": "toolchain test"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@dxos/async": "2.
|
|
18
|
-
"@dxos/client": "2.
|
|
19
|
-
"@dxos/config": "2.
|
|
20
|
-
"@dxos/credentials": "2.
|
|
21
|
-
"@dxos/crypto": "2.
|
|
22
|
-
"@dxos/debug": "2.
|
|
23
|
-
"@dxos/echo-db": "2.
|
|
24
|
-
"@dxos/
|
|
18
|
+
"@dxos/async": "2.19.0",
|
|
19
|
+
"@dxos/client": "2.19.0",
|
|
20
|
+
"@dxos/config": "2.19.0",
|
|
21
|
+
"@dxos/credentials": "2.19.0",
|
|
22
|
+
"@dxos/crypto": "2.19.0",
|
|
23
|
+
"@dxos/debug": "2.19.0",
|
|
24
|
+
"@dxos/echo-db": "2.19.0",
|
|
25
|
+
"@dxos/esbuild-plugins": "2.19.0",
|
|
26
|
+
"@dxos/esbuild-server": "~1.4.0",
|
|
27
|
+
"@dxos/util": "2.19.0",
|
|
25
28
|
"@types/debug": "^4.1.1",
|
|
26
29
|
"assert": "^2.0.0",
|
|
27
30
|
"debug": "^4.1.1",
|
|
@@ -29,10 +32,11 @@
|
|
|
29
32
|
"use-subscription": "^1.4.1"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"@dxos/toolchain-node-library": "2.
|
|
35
|
+
"@dxos/toolchain-node-library": "2.19.0",
|
|
33
36
|
"@mui/material": "^5.0.1",
|
|
34
37
|
"@testing-library/react": "^11.0.4",
|
|
35
38
|
"@testing-library/react-hooks": "5.1.2",
|
|
39
|
+
"@types/debug": "^4.1.1",
|
|
36
40
|
"@types/level-js": "~4.0.1",
|
|
37
41
|
"@types/mocha": "~8.2.2",
|
|
38
42
|
"@types/node": "^14.0.9",
|
package/react-client.build.log
CHANGED
|
@@ -2,10 +2,10 @@ Invoking: toolchain build:test
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
typescript
|
|
5
|
-
OK in
|
|
5
|
+
OK in 6356 ms
|
|
6
6
|
|
|
7
7
|
eslint
|
|
8
|
-
OK in
|
|
8
|
+
OK in 6849 ms
|
|
9
9
|
|
|
10
10
|
mocha
|
|
11
11
|
This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills
|
|
@@ -13,7 +13,7 @@ This browser doesn't support cancelAnimationFrame. Make sure that you load a pol
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
ClientProvider
|
|
16
|
-
✓ Renders with children
|
|
16
|
+
✓ Renders with children (49ms)
|
|
17
17
|
✓ Provides the client
|
|
18
18
|
|
|
19
19
|
Client hook
|
|
@@ -26,8 +26,8 @@ This browser doesn't support cancelAnimationFrame. Make sure that you load a pol
|
|
|
26
26
|
✓ should return custom client config when used properly in a context
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
7 passing (
|
|
29
|
+
7 passing (507ms)
|
|
30
30
|
|
|
31
|
-
OK in
|
|
31
|
+
OK in 9134 ms
|
|
32
32
|
|
|
33
|
-
CHECK COMPLETE in
|
|
33
|
+
CHECK COMPLETE in 22346 ms
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import { screen, render } from '@testing-library/react';
|
|
6
6
|
import expect from 'expect';
|
|
7
|
-
// code import '@testing-library/jest-dom/extend-expect';
|
|
8
7
|
import React from 'react';
|
|
9
8
|
|
|
10
9
|
import { Client } from '@dxos/client';
|
|
@@ -29,7 +28,6 @@ describe('ClientProvider', () => {
|
|
|
29
28
|
client = new Client();
|
|
30
29
|
await client.initialize();
|
|
31
30
|
await client.halo.createProfile({ username: 'test-user' });
|
|
32
|
-
await client.echo.open();
|
|
33
31
|
});
|
|
34
32
|
|
|
35
33
|
after(async () => {
|
|
@@ -2,28 +2,107 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import debug from 'debug';
|
|
6
|
+
import React, { MutableRefObject, ReactNode, useEffect, useState } from 'react';
|
|
6
7
|
|
|
7
|
-
import { Client } from '@dxos/client';
|
|
8
|
+
import { Client, ClientOptions } from '@dxos/client';
|
|
9
|
+
import { Config, ConfigObject } from '@dxos/config';
|
|
10
|
+
import { MaybeFunction, MaybePromise, getAsyncValue } from '@dxos/util';
|
|
8
11
|
|
|
9
12
|
import { ClientContext } from '../hooks';
|
|
10
13
|
|
|
14
|
+
const log = debug('dxos:react-client');
|
|
15
|
+
|
|
16
|
+
export type ClientProvider = MaybeFunction<MaybePromise<Client>>
|
|
17
|
+
|
|
18
|
+
// TODO(burdon): Why defs?
|
|
19
|
+
export type ConfigProvider = MaybeFunction<MaybePromise<Config | ConfigObject>>
|
|
20
|
+
|
|
11
21
|
export interface ClientProviderProps {
|
|
12
|
-
client: Client
|
|
13
22
|
children?: ReactNode
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Forward reference to provide client object to outercontainer since it won't have access to the context.
|
|
26
|
+
*/
|
|
27
|
+
clientRef?: MutableRefObject<Client | undefined>
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Client object or async provider to enable to caller to do custom initialization.
|
|
31
|
+
*/
|
|
32
|
+
client?: ClientProvider
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Config object or async provider.
|
|
36
|
+
*/
|
|
37
|
+
config?: ConfigProvider
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Runtime objects.
|
|
41
|
+
*/
|
|
42
|
+
options?: ClientOptions
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Post initialization hook.
|
|
46
|
+
* @param Client
|
|
47
|
+
*/
|
|
48
|
+
onInitialize?: (client: Client) => Promise<void>
|
|
14
49
|
}
|
|
15
50
|
|
|
16
51
|
/**
|
|
17
52
|
* Root component that provides the DXOS client instance to child components.
|
|
18
|
-
* To be used with `useClient` hook.
|
|
53
|
+
* To be used with the `useClient` hook.
|
|
19
54
|
*/
|
|
20
|
-
export const ClientProvider = ({
|
|
55
|
+
export const ClientProvider = ({
|
|
56
|
+
children,
|
|
57
|
+
clientRef,
|
|
58
|
+
client: clientProvider,
|
|
59
|
+
config: configProvider,
|
|
60
|
+
options,
|
|
61
|
+
onInitialize
|
|
62
|
+
}: ClientProviderProps) => {
|
|
63
|
+
const [client, setClient] = useState<Client | undefined>(clientProvider instanceof Client ? clientProvider : undefined);
|
|
64
|
+
|
|
65
|
+
// Async helpers.
|
|
21
66
|
useEffect(() => {
|
|
22
|
-
(
|
|
67
|
+
if (!client) {
|
|
68
|
+
const done = async (client: Client) => {
|
|
69
|
+
log(`Created client: ${client}`);
|
|
70
|
+
if (clientRef) {
|
|
71
|
+
clientRef.current = client;
|
|
72
|
+
}
|
|
73
|
+
await onInitialize?.(client);
|
|
74
|
+
setClient(client);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// TODO(burdon): Error handling.
|
|
78
|
+
setImmediate(async () => {
|
|
79
|
+
if (clientProvider) {
|
|
80
|
+
// Asynchornously request client.
|
|
81
|
+
const client = await getAsyncValue(clientProvider);
|
|
82
|
+
await done(client);
|
|
83
|
+
} else {
|
|
84
|
+
// Asynchronously construct client (config may be undefined).
|
|
85
|
+
const config = await getAsyncValue(configProvider);
|
|
86
|
+
const client = new Client(config, options);
|
|
87
|
+
await client.initialize();
|
|
88
|
+
await done(client);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
23
92
|
}, []);
|
|
24
93
|
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (client) {
|
|
96
|
+
(window as any).__DXOS__ = client.getDevtoolsContext();
|
|
97
|
+
}
|
|
98
|
+
}, [client]);
|
|
99
|
+
|
|
100
|
+
if (!client) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
25
104
|
return (
|
|
26
|
-
<ClientContext.Provider value={client}>
|
|
105
|
+
<ClientContext.Provider value={{ client }}>
|
|
27
106
|
{children}
|
|
28
107
|
</ClientContext.Provider>
|
|
29
108
|
);
|
package/src/containers/index.ts
CHANGED
|
@@ -6,7 +6,11 @@ import { createContext } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
8
|
|
|
9
|
+
interface ClientContextProps {
|
|
10
|
+
client: Client
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* https://reactjs.org/docs/context.html#reactcreatecontext
|
|
11
15
|
*/
|
|
12
|
-
export const ClientContext = createContext<
|
|
16
|
+
export const ClientContext = createContext<ClientContextProps | undefined>(undefined);
|
|
@@ -10,8 +10,9 @@ import { ClientContext } from './context';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Hook returning instance of DXOS client.
|
|
13
|
-
*
|
|
13
|
+
* Requires ClientContext to be set via ClientProvider.
|
|
14
14
|
*/
|
|
15
15
|
export const useClient = () => {
|
|
16
|
-
|
|
16
|
+
const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
|
|
17
|
+
return client;
|
|
17
18
|
};
|
|
@@ -10,9 +10,9 @@ import { ClientContext } from './context';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Hook returning config object used to initialize the DXOS client instance.
|
|
13
|
-
*
|
|
13
|
+
* Requires ClientConext to be set via ClientProvider.
|
|
14
14
|
*/
|
|
15
15
|
export const useConfig = () => {
|
|
16
|
-
const {
|
|
17
|
-
return config;
|
|
16
|
+
const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
|
|
17
|
+
return client.config;
|
|
18
18
|
};
|
|
@@ -8,7 +8,7 @@ import { useClient } from './useClient';
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Hook returning DXOS user profile object.
|
|
11
|
-
*
|
|
11
|
+
* Requires ClientConext to be set via ClientProvider.
|
|
12
12
|
*/
|
|
13
13
|
export const useProfile = () => {
|
|
14
14
|
const client = useClient();
|
|
@@ -11,14 +11,14 @@ import { useClient } from '../client';
|
|
|
11
11
|
/**
|
|
12
12
|
* Returns all known Contacts across all Parties.
|
|
13
13
|
* Contacts are known members of a common Party.
|
|
14
|
-
*
|
|
14
|
+
* Requires ClientConext to be set via ClientProvider.
|
|
15
15
|
*/
|
|
16
16
|
export const useContacts = () => {
|
|
17
17
|
const client = useClient();
|
|
18
18
|
const [contacts, setContacts] = useState<PartyMember[]>([]);
|
|
19
19
|
|
|
20
20
|
useEffect(() => {
|
|
21
|
-
const result = client.
|
|
21
|
+
const result = client.halo.queryContacts();
|
|
22
22
|
setContacts(result.value);
|
|
23
23
|
|
|
24
24
|
const unsubscribe = result.subscribe(() => {
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { PartyProxy } from '@dxos/client';
|
|
8
|
+
import { PartyMember } from '@dxos/echo-db';
|
|
8
9
|
|
|
9
|
-
export const useMembers = (party:
|
|
10
|
+
export const useMembers = (party: PartyProxy | undefined) => {
|
|
10
11
|
const [members, setMembers] = useState<PartyMember[]>([]);
|
|
11
12
|
|
|
12
13
|
useEffect(() => {
|
|
@@ -4,28 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
|
+
import { PartyProxy } from '@dxos/client';
|
|
7
8
|
import { PublicKey, PublicKeyLike } from '@dxos/crypto';
|
|
8
|
-
import { Party } from '@dxos/echo-db';
|
|
9
9
|
|
|
10
10
|
import { useClient } from '../client';
|
|
11
11
|
import { useResultSet } from '../util';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Get a specific Party.
|
|
15
|
-
*
|
|
15
|
+
* Requires ClientConext to be set via ClientProvider.
|
|
16
16
|
*/
|
|
17
|
-
export const useParty = (partyKey?: PublicKeyLike) => {
|
|
17
|
+
export const useParty = (partyKey?: PublicKeyLike): PartyProxy | undefined => {
|
|
18
18
|
const client = useClient();
|
|
19
19
|
return partyKey ? client.echo.getParty(PublicKey.from(partyKey)) : undefined;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Get all Parties available to current user.
|
|
24
|
-
*
|
|
24
|
+
* Requires ClientConext to be set via ClientProvider.
|
|
25
25
|
*/
|
|
26
26
|
export const useParties = () => {
|
|
27
27
|
const client = useClient();
|
|
28
|
-
const [parties, setParties] = useState<
|
|
28
|
+
const [parties, setParties] = useState<PartyProxy[]>([]);
|
|
29
29
|
|
|
30
30
|
useEffect(() => {
|
|
31
31
|
const result = client.echo.queryParties();
|
|
@@ -48,6 +48,6 @@ export const useParties = () => {
|
|
|
48
48
|
/**
|
|
49
49
|
* Get all known members of a Party.
|
|
50
50
|
*/
|
|
51
|
-
export const usePartyMembers = (party:
|
|
51
|
+
export const usePartyMembers = (party: PartyProxy) => {
|
|
52
52
|
return useResultSet(useMemo(() => party.queryMembers(), [party.key.toHex()]));
|
|
53
53
|
};
|
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect, useState } from 'react';
|
|
6
6
|
|
|
7
|
+
import { Party } from '@dxos/client/src/proto/gen/dxos/client';
|
|
8
|
+
|
|
7
9
|
import { useClient } from '../client';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Get all Parties available to current user.
|
|
11
|
-
*
|
|
13
|
+
* Requires ClientConext to be set via ClientProvider.
|
|
12
14
|
*/
|
|
13
15
|
export const useRemoteParties = () => {
|
|
14
16
|
const client = useClient();
|
|
15
|
-
const [parties, setParties] = useState<
|
|
17
|
+
const [parties, setParties] = useState<Party[]>([]);
|
|
16
18
|
|
|
17
19
|
useEffect(() => {
|
|
18
20
|
const stream = client.services.PartyService.SubscribeParties();
|
package/src/index.ts
CHANGED
|
@@ -10,14 +10,16 @@ import { useClient, useProfile } from '../hooks';
|
|
|
10
10
|
* Automatically creates a random DXOS profile.
|
|
11
11
|
* @deprecated
|
|
12
12
|
*/
|
|
13
|
-
// TODO(burdon): Testing-only
|
|
13
|
+
// TODO(burdon): Testing-only (set as debug option for ClientProvider?)
|
|
14
14
|
export const ProfileInitializer = ({ children }: { children: React.ReactNode }) => {
|
|
15
15
|
const client = useClient();
|
|
16
16
|
const profile = useProfile();
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
if (!profile) {
|
|
20
|
-
|
|
20
|
+
setImmediate(async () => {
|
|
21
|
+
await client.halo.createProfile();
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
}, []);
|
|
23
25
|
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useEffect } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { ClientPanel
|
|
7
|
+
import { ClientProvider, useClient } from '../src';
|
|
8
|
+
import { ClientPanel } from './helpers';
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
|
-
title: 'react-client/
|
|
11
|
+
title: 'react-client/ClientProvider'
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
const TestApp = () => {
|
|
@@ -27,12 +27,16 @@ const TestApp = () => {
|
|
|
27
27
|
|
|
28
28
|
export const Primary = () => {
|
|
29
29
|
return (
|
|
30
|
-
<
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
<ClientProvider>
|
|
31
|
+
<TestApp />
|
|
32
|
+
</ClientProvider>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const Secondary = () => {
|
|
37
|
+
return (
|
|
38
|
+
<ClientProvider config={() => ({})}>
|
|
39
|
+
<TestApp />
|
|
40
|
+
</ClientProvider>
|
|
37
41
|
);
|
|
38
42
|
};
|
|
@@ -12,7 +12,7 @@ import { Awaited } from '@dxos/async';
|
|
|
12
12
|
import { Client, decodeInvitation, PendingInvitation } from '@dxos/client';
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
|
-
|
|
15
|
+
ClientProvider,
|
|
16
16
|
ProfileInitializer,
|
|
17
17
|
useClient,
|
|
18
18
|
useParties,
|
|
@@ -146,7 +146,7 @@ const TestApp = () => {
|
|
|
146
146
|
<ClientPanel client={client} profile={profile} parties={parties} />
|
|
147
147
|
<Divider />
|
|
148
148
|
<HaloInvitationContainer />
|
|
149
|
-
{!client.
|
|
149
|
+
{!client.halo.isInitialized && (
|
|
150
150
|
<>
|
|
151
151
|
<Divider />
|
|
152
152
|
<HaloAuthenticationContainer />
|
|
@@ -164,17 +164,17 @@ export const Primary = () => {
|
|
|
164
164
|
<Container>
|
|
165
165
|
<Box sx={{ display: 'flex', flex: 1, padding: 1, justifyContent: 'space-around' }}>
|
|
166
166
|
{/* Instantiated Client. */}
|
|
167
|
-
<
|
|
167
|
+
<ClientProvider>
|
|
168
168
|
<ProfileInitializer>
|
|
169
169
|
<TestApp />
|
|
170
170
|
</ProfileInitializer>
|
|
171
|
-
</
|
|
171
|
+
</ClientProvider>
|
|
172
172
|
|
|
173
173
|
{/* Joiners. */}
|
|
174
174
|
{[...new Array(peers)].map((_, i) => (
|
|
175
|
-
<
|
|
175
|
+
<ClientProvider key={i}>
|
|
176
176
|
<TestApp />
|
|
177
|
-
</
|
|
177
|
+
</ClientProvider>
|
|
178
178
|
))}
|
|
179
179
|
</Box>
|
|
180
180
|
</Container>
|
|
@@ -6,8 +6,7 @@ import React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { Box } from '@mui/material';
|
|
8
8
|
|
|
9
|
-
import { Client } from '@dxos/client';
|
|
10
|
-
import { Party } from '@dxos/echo-db';
|
|
9
|
+
import { Client, PartyProxy } from '@dxos/client';
|
|
11
10
|
|
|
12
11
|
import { useProfile } from '../../src';
|
|
13
12
|
import { JsonPanel } from './JsonPanel';
|
|
@@ -19,13 +18,9 @@ export const ClientPanel = ({
|
|
|
19
18
|
}: {
|
|
20
19
|
client: Client,
|
|
21
20
|
profile?: Partial<ReturnType<typeof useProfile>>,
|
|
22
|
-
parties?:
|
|
21
|
+
parties?: PartyProxy[]
|
|
23
22
|
}) => {
|
|
24
|
-
const data = (parties.length !== 0)
|
|
25
|
-
? {
|
|
26
|
-
parties: parties.map(({ key }) => key.toHex())
|
|
27
|
-
}
|
|
28
|
-
: undefined;
|
|
23
|
+
const data = (parties.length !== 0) ? { parties: parties.map(({ key }) => key.toHex()) } : undefined;
|
|
29
24
|
|
|
30
25
|
return (
|
|
31
26
|
<Box>
|
|
@@ -13,7 +13,7 @@ import { PublicKey } from '@dxos/crypto';
|
|
|
13
13
|
import { InvitationDescriptorType } from '@dxos/echo-db';
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
-
|
|
16
|
+
ClientProvider,
|
|
17
17
|
ProfileInitializer,
|
|
18
18
|
useClient,
|
|
19
19
|
useContacts,
|
|
@@ -58,8 +58,8 @@ const PartyInvitationContainer = () => {
|
|
|
58
58
|
const handleCreateInvitation = () => {
|
|
59
59
|
setImmediate(async () => {
|
|
60
60
|
const invitation = (contact)
|
|
61
|
-
? await client.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!))
|
|
62
|
-
: await client.createInvitation(partyKey!, secretProvider, {
|
|
61
|
+
? await client.echo.createOfflineInvitation(partyKey!, PublicKey.fromHex(contact!))
|
|
62
|
+
: await client.echo.createInvitation(partyKey!, { secretProvider }, {
|
|
63
63
|
onFinish: () => { // TODO(burdon): Normalize callbacks (error, etc.)
|
|
64
64
|
setInvitationCode(undefined);
|
|
65
65
|
resetPin();
|
|
@@ -192,11 +192,11 @@ export const Primary = () => {
|
|
|
192
192
|
<Container>
|
|
193
193
|
<Box sx={{ display: 'flex', flex: 1, padding: 1, justifyContent: 'space-around' }}>
|
|
194
194
|
{[...new Array(peers)].map((_, i) => (
|
|
195
|
-
<
|
|
195
|
+
<ClientProvider key={i}>
|
|
196
196
|
<ProfileInitializer>
|
|
197
197
|
<TestApp />
|
|
198
198
|
</ProfileInitializer>
|
|
199
|
-
</
|
|
199
|
+
</ClientProvider>
|
|
200
200
|
))}
|
|
201
201
|
</Box>
|
|
202
202
|
</Container>
|
package/tests/config.test.ts
CHANGED
|
@@ -14,7 +14,7 @@ describe('Config hook', () => {
|
|
|
14
14
|
const { result } = renderHook(render);
|
|
15
15
|
// TODO(burdon): Do NOT test functionality by matching literal error messages.
|
|
16
16
|
expect(result.error?.message)
|
|
17
|
-
.toEqual('`useConfig` hook is called outside of ClientContext.
|
|
17
|
+
.toEqual('`useConfig` hook is called outside of ClientContext. Use `ClientProvider`');
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
// TODO(burdon): Add test for context.
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React, { Component, ErrorInfo } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Root-level error boundary.
|
|
4
|
-
* https://reactjs.org/docs/error-boundaries.html
|
|
5
|
-
*
|
|
6
|
-
* NOTE: Must currently be a Component.
|
|
7
|
-
* https://reactjs.org/docs/hooks-faq.html#do-hooks-cover-all-use-cases-for-classes
|
|
8
|
-
*/
|
|
9
|
-
export declare type ErrorCallbackType = (error: Error, errorInfo?: ErrorInfo) => void;
|
|
10
|
-
export interface ErrorComponentProps {
|
|
11
|
-
error: Error | null;
|
|
12
|
-
onRestart?: () => void;
|
|
13
|
-
onReset?: () => void;
|
|
14
|
-
}
|
|
15
|
-
interface ErrorBoundaryProps {
|
|
16
|
-
onError: ErrorCallbackType;
|
|
17
|
-
onRestart?: () => void;
|
|
18
|
-
onReset?: () => void;
|
|
19
|
-
errorComponent?: React.ComponentType<ErrorComponentProps>;
|
|
20
|
-
}
|
|
21
|
-
interface State {
|
|
22
|
-
error: Error | null;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Top-level error boundary.
|
|
26
|
-
* NOTE: Doesn't catch exceptions in event handlers, or asynchronous callbacks.
|
|
27
|
-
* A global error handler should be configured for such errors.
|
|
28
|
-
* https://reactjs.org/docs/error-boundaries.html#how-about-event-handlers
|
|
29
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
|
|
30
|
-
* It DOES catch exceptions in hooks and any components that return malformed React compoennts.
|
|
31
|
-
*/
|
|
32
|
-
export declare class ErrorBoundary extends Component<ErrorBoundaryProps, State> {
|
|
33
|
-
state: {
|
|
34
|
-
error: null;
|
|
35
|
-
};
|
|
36
|
-
static defaultProps: {
|
|
37
|
-
onError: {
|
|
38
|
-
(...data: any[]): void;
|
|
39
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
40
|
-
};
|
|
41
|
-
onRestart: () => void;
|
|
42
|
-
onReset: undefined;
|
|
43
|
-
errorComponent: undefined;
|
|
44
|
-
};
|
|
45
|
-
static getDerivedStateFromError(error: any): {
|
|
46
|
-
error: any;
|
|
47
|
-
};
|
|
48
|
-
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
49
|
-
render(): React.ReactNode;
|
|
50
|
-
}
|
|
51
|
-
export {};
|
|
52
|
-
//# sourceMappingURL=ErrorBoundary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIpD;;;;;;GAMG;AAEH,oBAAY,iBAAiB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,UAAU,kBAAkB;IAC1B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAA;CAC1D;AAED,UAAU,KAAK;IACb,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,KAAK,CAAC;IAC5D,KAAK;;MAEZ;IAEF,MAAM,CAAC,YAAY;;;;;;;;MAOjB;IAEF,MAAM,CAAC,wBAAwB,CAAE,KAAK,EAAE,GAAG;;;IAIlC,iBAAiB,CAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;IAKrD,MAAM;CA4BhB"}
|