@peers-app/peers-ui 0.25.2 → 0.25.4
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/README.md +2 -1
- package/dist/components/markdown-editor/mention-node.d.ts +4 -0
- package/dist/components/markdown-editor/mention-node.js +4 -1
- package/dist/components/responsive-section-nav.d.ts +34 -0
- package/dist/components/responsive-section-nav.js +19 -0
- package/dist/components/responsive-section-nav.test.d.ts +1 -0
- package/dist/components/responsive-section-nav.test.js +45 -0
- package/dist/components/router.d.ts +2 -3
- package/dist/components/router.js +6 -9
- package/dist/globals-hash.test.d.ts +1 -0
- package/dist/globals-hash.test.js +16 -0
- package/dist/globals.d.ts +19 -0
- package/dist/globals.js +51 -12
- package/dist/hooks/use-host-contract.d.ts +18 -0
- package/dist/hooks/use-host-contract.js +53 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/peers-services-registration.d.ts +1 -5
- package/dist/peers-services-registration.js +6 -16
- package/dist/root-layout/root-layout-host.js +7 -4
- package/dist/root-layout/root-layout-host.test.js +3 -6
- package/dist/screens/account/account-screen.d.ts +1 -0
- package/dist/screens/account/account-screen.js +29 -53
- package/dist/screens/account/account-screen.test.d.ts +1 -0
- package/dist/screens/account/account-screen.test.js +47 -0
- package/dist/screens/contacts/contact-details.js +2 -23
- package/dist/screens/contacts/contact-list.d.ts +24 -1
- package/dist/screens/contacts/contact-list.js +128 -143
- package/dist/screens/contacts/contact-list.test.d.ts +1 -0
- package/dist/screens/contacts/contact-list.test.js +48 -0
- package/dist/screens/contacts/index.d.ts +0 -2
- package/dist/screens/contacts/index.js +0 -3
- package/dist/screens/device-pairing/device-pairing.js +17 -16
- package/dist/screens/device-pairing/device-pairing.test.js +4 -9
- package/dist/screens/device-pairing/identity-ipc.d.ts +11 -0
- package/dist/screens/device-pairing/identity-ipc.js +20 -0
- package/dist/screens/device-pairing/use-device-pairing-state.d.ts +2 -2
- package/dist/screens/device-pairing/use-device-pairing-state.js +7 -25
- package/dist/screens/devices/devices-list.d.ts +18 -0
- package/dist/screens/devices/devices-list.js +173 -0
- package/dist/screens/devices/devices-list.test.d.ts +1 -0
- package/dist/screens/devices/devices-list.test.js +53 -0
- package/dist/screens/devices/index.d.ts +1 -0
- package/dist/screens/devices/index.js +5 -0
- package/dist/screens/groups/group-details.d.ts +1 -0
- package/dist/screens/groups/group-details.js +4 -63
- package/dist/screens/groups/group-invite-panel.js +2 -2
- package/dist/screens/groups/group-list.d.ts +18 -1
- package/dist/screens/groups/group-list.js +107 -136
- package/dist/screens/groups/group-list.test.d.ts +1 -0
- package/dist/screens/groups/group-list.test.js +38 -0
- package/dist/screens/groups/group-members.d.ts +1 -0
- package/dist/screens/groups/group-members.js +2 -1
- package/dist/screens/groups/index.d.ts +0 -3
- package/dist/screens/groups/index.js +0 -4
- package/dist/screens/identity/identity-routes.d.ts +107 -0
- package/dist/screens/identity/identity-routes.js +245 -0
- package/dist/screens/identity/identity-routes.test.d.ts +1 -0
- package/dist/screens/identity/identity-routes.test.js +51 -0
- package/dist/screens/identity/identity-screen.d.ts +9 -0
- package/dist/screens/identity/identity-screen.js +143 -0
- package/dist/screens/identity/identity-screen.test.d.ts +1 -0
- package/dist/screens/identity/identity-screen.test.js +103 -0
- package/dist/screens/identity/index.d.ts +2 -0
- package/dist/screens/identity/index.js +6 -0
- package/dist/screens/identity/invite-contact-panel.d.ts +4 -0
- package/dist/screens/identity/invite-contact-panel.js +30 -0
- package/dist/screens/identity/profile-invite.d.ts +7 -0
- package/dist/screens/identity/profile-invite.js +62 -0
- package/dist/screens/invites/accept-invite.js +44 -2
- package/dist/screens/invites/accept-invite.test.d.ts +1 -0
- package/dist/screens/invites/accept-invite.test.js +103 -0
- package/dist/screens/invites/activity-view.d.ts +24 -0
- package/dist/screens/invites/activity-view.js +64 -0
- package/dist/screens/invites/activity-view.test.d.ts +1 -0
- package/dist/screens/invites/activity-view.test.js +108 -0
- package/dist/screens/invites/index.d.ts +1 -2
- package/dist/screens/invites/index.js +1 -3
- package/dist/screens/invites/invite-capture.d.ts +0 -2
- package/dist/screens/invites/invite-capture.js +1 -3
- package/dist/screens/invites/invite-classify.test.d.ts +1 -0
- package/dist/screens/invites/invite-classify.test.js +115 -0
- package/dist/screens/invites/invites-ipc.d.ts +1 -1
- package/dist/screens/invites/invites-ipc.js +5 -45
- package/dist/screens/invites/pending-invites-list.d.ts +35 -16
- package/dist/screens/invites/pending-invites-list.js +75 -30
- package/dist/screens/network-viewer/network-viewer-ipc.js +4 -59
- package/dist/screens/search/global-search.d.ts +1 -0
- package/dist/screens/search/global-search.js +2 -1
- package/dist/screens/settings/settings-page.js +25 -58
- package/dist/screens/setup-user.js +5 -5
- package/dist/screens/tools/tool-access-ipc.d.ts +2 -0
- package/dist/screens/tools/tool-access-ipc.js +8 -55
- package/dist/screens/welcome-modal.js +3 -2
- package/dist/system-apps/identity.app.d.ts +3 -0
- package/dist/system-apps/identity.app.js +10 -0
- package/dist/system-apps/index.d.ts +1 -4
- package/dist/system-apps/index.js +5 -17
- package/dist/tabs-layout/network-status-indicator.js +10 -3
- package/dist/tabs-layout/network-status-indicator.test.js +15 -0
- package/dist/tabs-layout/tabs-layout.js +3 -1
- package/dist/tabs-layout/tabs-state.d.ts +79 -1
- package/dist/tabs-layout/tabs-state.js +256 -79
- package/dist/tabs-layout/tabs-state.test.d.ts +1 -0
- package/dist/tabs-layout/tabs-state.test.js +110 -0
- package/package.json +3 -3
- package/src/components/markdown-editor/mention-node.ts +5 -1
- package/src/components/responsive-section-nav.test.tsx +88 -0
- package/src/components/responsive-section-nav.tsx +92 -0
- package/src/components/router.tsx +6 -9
- package/src/globals-hash.test.ts +19 -0
- package/src/globals.tsx +53 -13
- package/src/hooks/use-host-contract.ts +75 -0
- package/src/index.tsx +1 -0
- package/src/peers-services-registration.ts +6 -17
- package/src/root-layout/root-layout-host.test.tsx +4 -7
- package/src/root-layout/root-layout-host.tsx +9 -11
- package/src/screens/account/account-screen.test.tsx +61 -0
- package/src/screens/account/account-screen.tsx +116 -95
- package/src/screens/contacts/contact-details.tsx +4 -26
- package/src/screens/contacts/contact-list.test.tsx +59 -0
- package/src/screens/contacts/contact-list.tsx +246 -260
- package/src/screens/contacts/index.ts +0 -4
- package/src/screens/device-pairing/device-pairing.test.tsx +7 -9
- package/src/screens/device-pairing/device-pairing.tsx +19 -23
- package/src/screens/device-pairing/identity-ipc.ts +25 -0
- package/src/screens/device-pairing/use-device-pairing-state.ts +10 -33
- package/src/screens/devices/devices-list.test.tsx +68 -0
- package/src/screens/devices/devices-list.tsx +361 -0
- package/src/screens/devices/index.ts +1 -0
- package/src/screens/groups/group-details.tsx +8 -142
- package/src/screens/groups/group-invite-panel.tsx +2 -7
- package/src/screens/groups/group-list.test.tsx +44 -0
- package/src/screens/groups/group-list.tsx +227 -288
- package/src/screens/groups/group-members.tsx +3 -2
- package/src/screens/groups/index.ts +0 -5
- package/src/screens/identity/identity-routes.test.ts +70 -0
- package/src/screens/identity/identity-routes.ts +301 -0
- package/src/screens/identity/identity-screen.test.tsx +138 -0
- package/src/screens/identity/identity-screen.tsx +282 -0
- package/src/screens/identity/index.ts +2 -0
- package/src/screens/identity/invite-contact-panel.tsx +45 -0
- package/src/screens/identity/profile-invite.tsx +93 -0
- package/src/screens/invites/accept-invite.test.tsx +115 -0
- package/src/screens/invites/accept-invite.tsx +50 -3
- package/src/screens/invites/activity-view.test.tsx +127 -0
- package/src/screens/invites/activity-view.tsx +162 -0
- package/src/screens/invites/index.ts +1 -4
- package/src/screens/invites/invite-capture.ts +0 -3
- package/src/screens/invites/invite-classify.test.ts +129 -0
- package/src/screens/invites/invites-ipc.ts +6 -55
- package/src/screens/invites/pending-invites-list.tsx +94 -62
- package/src/screens/network-viewer/network-viewer-ipc.ts +8 -82
- package/src/screens/search/global-search.tsx +2 -1
- package/src/screens/settings/settings-page.tsx +53 -126
- package/src/screens/setup-user.tsx +5 -6
- package/src/screens/tools/tool-access-ipc.ts +13 -74
- package/src/screens/welcome-modal.tsx +3 -3
- package/src/system-apps/identity.app.ts +9 -0
- package/src/system-apps/index.ts +3 -12
- package/src/tabs-layout/network-status-indicator.test.tsx +22 -0
- package/src/tabs-layout/network-status-indicator.tsx +31 -0
- package/src/tabs-layout/tabs-layout.tsx +7 -1
- package/src/tabs-layout/tabs-state.test.ts +152 -0
- package/src/tabs-layout/tabs-state.ts +300 -83
- package/dist/screens/invites/invites-screen.d.ts +0 -9
- package/dist/screens/invites/invites-screen.js +0 -36
- package/dist/system-apps/account.app.d.ts +0 -2
- package/dist/system-apps/account.app.js +0 -8
- package/dist/system-apps/contacts.app.d.ts +0 -2
- package/dist/system-apps/contacts.app.js +0 -9
- package/dist/system-apps/groups.app.d.ts +0 -2
- package/dist/system-apps/groups.app.js +0 -9
- package/dist/system-apps/invites.app.d.ts +0 -2
- package/dist/system-apps/invites.app.js +0 -9
- package/src/screens/invites/invites-screen.tsx +0 -78
- package/src/system-apps/account.app.ts +0 -7
- package/src/system-apps/contacts.app.ts +0 -8
- package/src/system-apps/groups.app.ts +0 -8
- package/src/system-apps/invites.app.ts +0 -8
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import type { IInvite } from "@peers-app/peers-sdk";
|
|
2
|
+
import { type ReactNode, useState } from "react";
|
|
3
|
+
import { ResponsiveSectionNav } from "../../components/responsive-section-nav";
|
|
4
|
+
import { isDesktop, mainContentPath } from "../../globals";
|
|
5
|
+
import { useObservable } from "../../hooks";
|
|
6
|
+
import { registerInternalPeersUI } from "../../ui-router/ui-loader";
|
|
7
|
+
import { AccountScreen } from "../account/account-screen";
|
|
8
|
+
import { ContactDetails } from "../contacts/contact-details";
|
|
9
|
+
import { ContactList } from "../contacts/contact-list";
|
|
10
|
+
import { DevicesSection } from "../devices/devices-list";
|
|
11
|
+
import { GroupDetails } from "../groups/group-details";
|
|
12
|
+
import { GroupList } from "../groups/group-list";
|
|
13
|
+
import { AcceptInvite } from "../invites/accept-invite";
|
|
14
|
+
import { ActivityView } from "../invites/activity-view";
|
|
15
|
+
import { classifyInvite, useInviteRows } from "../invites/pending-invites-list";
|
|
16
|
+
import {
|
|
17
|
+
IDENTITY_ACCEPT_PATH,
|
|
18
|
+
IDENTITY_ACCOUNT_PATH,
|
|
19
|
+
IDENTITY_ACTIVITY_PATH,
|
|
20
|
+
IDENTITY_DEVICES_PATH,
|
|
21
|
+
IDENTITY_GROUP_NEW_PATH,
|
|
22
|
+
IDENTITY_GROUPS_PATH,
|
|
23
|
+
IDENTITY_PAIR_PATH,
|
|
24
|
+
IDENTITY_PEOPLE_INVITE_PATH,
|
|
25
|
+
IDENTITY_PEOPLE_PATH,
|
|
26
|
+
type IdentitySectionId,
|
|
27
|
+
parseIdentityLocation,
|
|
28
|
+
} from "./identity-routes";
|
|
29
|
+
|
|
30
|
+
const SECTION_PATHS: Record<IdentitySectionId, string> = {
|
|
31
|
+
activity: IDENTITY_ACTIVITY_PATH,
|
|
32
|
+
people: IDENTITY_PEOPLE_PATH,
|
|
33
|
+
groups: IDENTITY_GROUPS_PATH,
|
|
34
|
+
devices: IDENTITY_DEVICES_PATH,
|
|
35
|
+
account: IDENTITY_ACCOUNT_PATH,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Identity app shell.
|
|
40
|
+
*
|
|
41
|
+
* Activity, People, Groups, Devices, and Account stay one top-level tab. The
|
|
42
|
+
* route selects the section, and detail routes keep that section highlighted.
|
|
43
|
+
*/
|
|
44
|
+
export function IdentityScreen(props: { path?: string }) {
|
|
45
|
+
const [livePath] = useObservable(mainContentPath);
|
|
46
|
+
const location =
|
|
47
|
+
parseIdentityLocation(props.path ?? livePath) ?? parseIdentityLocation(IDENTITY_ACTIVITY_PATH);
|
|
48
|
+
const pending = useInviteRows({ statuses: ["pending"] });
|
|
49
|
+
const rows = pending?.rows;
|
|
50
|
+
if (!location) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<ResponsiveSectionNav
|
|
56
|
+
label="Identity"
|
|
57
|
+
activeSectionId={location.section}
|
|
58
|
+
onSelect={(sectionId) => mainContentPath(SECTION_PATHS[sectionId as IdentitySectionId])}
|
|
59
|
+
toolbar={<IdentityQuickActions />}
|
|
60
|
+
sections={[
|
|
61
|
+
{
|
|
62
|
+
id: "activity",
|
|
63
|
+
label: "Activity",
|
|
64
|
+
iconClassName: "bi-inbox",
|
|
65
|
+
badge: badgeCount(rows, "attention"),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "people",
|
|
69
|
+
label: "People",
|
|
70
|
+
iconClassName: "bi-person-fill-check",
|
|
71
|
+
badge: badgeCount(rows, "contact"),
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "groups",
|
|
75
|
+
label: "Groups",
|
|
76
|
+
iconClassName: "bi-people-fill",
|
|
77
|
+
badge: badgeCount(rows, "group"),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: "devices",
|
|
81
|
+
label: "Devices",
|
|
82
|
+
iconClassName: "bi-laptop",
|
|
83
|
+
badge: badgeCount(rows, "device"),
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "account",
|
|
87
|
+
label: "Account",
|
|
88
|
+
iconClassName: "bi-person-circle",
|
|
89
|
+
},
|
|
90
|
+
]}
|
|
91
|
+
>
|
|
92
|
+
<IdentityBody location={location} />
|
|
93
|
+
</ResponsiveSectionNav>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function IdentityBody(props: { location: NonNullable<ReturnType<typeof parseIdentityLocation>> }) {
|
|
98
|
+
const { location } = props;
|
|
99
|
+
if (location.accepting) {
|
|
100
|
+
return (
|
|
101
|
+
<div className="container-fluid py-3" style={{ maxWidth: 720 }}>
|
|
102
|
+
<a href={`#${IDENTITY_ACTIVITY_PATH}`} className="btn btn-link btn-sm px-0 mb-2">
|
|
103
|
+
Back to Activity
|
|
104
|
+
</a>
|
|
105
|
+
<h4 className="mb-3">
|
|
106
|
+
<i className="bi bi-envelope-paper me-2" />
|
|
107
|
+
Accept an invite
|
|
108
|
+
</h4>
|
|
109
|
+
<div className="card">
|
|
110
|
+
<div className="card-body">
|
|
111
|
+
<AcceptInvite onDone={() => mainContentPath(IDENTITY_ACTIVITY_PATH)} />
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
if (location.section === "people") {
|
|
118
|
+
return location.personId ? (
|
|
119
|
+
<DetailFrame backHref={`#${IDENTITY_PEOPLE_PATH}`} backLabel="Back to people">
|
|
120
|
+
<ContactDetails userId={location.personId} />
|
|
121
|
+
</DetailFrame>
|
|
122
|
+
) : (
|
|
123
|
+
<ContactList action={location.peopleAction} />
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (location.section === "groups") {
|
|
127
|
+
return location.groupId ? (
|
|
128
|
+
<DetailFrame backHref={`#${IDENTITY_GROUPS_PATH}`} backLabel="Back to groups">
|
|
129
|
+
<GroupDetails groupId={location.groupId} />
|
|
130
|
+
</DetailFrame>
|
|
131
|
+
) : (
|
|
132
|
+
<GroupList creating={location.creatingGroup} />
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (location.section === "devices") {
|
|
136
|
+
const mode = location.pairing ? "pair" : location.deviceId ? "detail" : "list";
|
|
137
|
+
return <DevicesSection mode={mode} deviceId={location.deviceId} />;
|
|
138
|
+
}
|
|
139
|
+
if (location.section === "account") {
|
|
140
|
+
return <AccountScreen />;
|
|
141
|
+
}
|
|
142
|
+
return (
|
|
143
|
+
<div className="container-xxl p-3">
|
|
144
|
+
<ActivityView filter={location.activityFilter} />
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function IdentityQuickActions() {
|
|
150
|
+
const [desktop] = useObservable(isDesktop);
|
|
151
|
+
const [showAdd, setShowAdd] = useState(false);
|
|
152
|
+
const addActions = [
|
|
153
|
+
{
|
|
154
|
+
path: IDENTITY_PEOPLE_INVITE_PATH,
|
|
155
|
+
label: "Add person",
|
|
156
|
+
icon: "bi-person-plus",
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
path: IDENTITY_GROUP_NEW_PATH,
|
|
160
|
+
label: "Create group",
|
|
161
|
+
icon: "bi-people",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
path: IDENTITY_PAIR_PATH,
|
|
165
|
+
label: "Add device",
|
|
166
|
+
icon: "bi-laptop",
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
if (desktop) {
|
|
171
|
+
return (
|
|
172
|
+
<div
|
|
173
|
+
className="d-grid align-items-center gap-2 border-bottom p-2"
|
|
174
|
+
style={{ gridTemplateColumns: "minmax(0, 1fr) auto minmax(0, 1fr)" }}
|
|
175
|
+
>
|
|
176
|
+
<div className="overflow-hidden">
|
|
177
|
+
<div className="fw-semibold">Identity</div>
|
|
178
|
+
<small className="text-muted text-truncate d-block">
|
|
179
|
+
People, groups, and your devices
|
|
180
|
+
</small>
|
|
181
|
+
</div>
|
|
182
|
+
<div className="d-flex align-items-center justify-content-center gap-2">
|
|
183
|
+
{addActions.map((action) => (
|
|
184
|
+
<a
|
|
185
|
+
key={action.path}
|
|
186
|
+
href={`#${action.path}`}
|
|
187
|
+
className="btn btn-outline-primary btn-sm"
|
|
188
|
+
>
|
|
189
|
+
<i className={`bi ${action.icon} me-1`} />
|
|
190
|
+
{action.label}
|
|
191
|
+
</a>
|
|
192
|
+
))}
|
|
193
|
+
<a href={`#${IDENTITY_ACCEPT_PATH}`} className="btn btn-primary btn-sm">
|
|
194
|
+
<i className="bi bi-qr-code-scan me-1" />
|
|
195
|
+
Use invite
|
|
196
|
+
</a>
|
|
197
|
+
</div>
|
|
198
|
+
<span aria-hidden="true" />
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div className="position-relative d-flex align-items-center gap-2 border-bottom p-2">
|
|
205
|
+
<div className="me-auto fw-semibold">Identity</div>
|
|
206
|
+
<button
|
|
207
|
+
type="button"
|
|
208
|
+
className="btn btn-outline-primary btn-sm"
|
|
209
|
+
aria-expanded={showAdd}
|
|
210
|
+
onClick={() => setShowAdd((open) => !open)}
|
|
211
|
+
>
|
|
212
|
+
<i className="bi bi-plus-lg me-1" />
|
|
213
|
+
Add
|
|
214
|
+
</button>
|
|
215
|
+
<a href={`#${IDENTITY_ACCEPT_PATH}`} className="btn btn-primary btn-sm">
|
|
216
|
+
<i className="bi bi-qr-code-scan me-1" />
|
|
217
|
+
Invite
|
|
218
|
+
</a>
|
|
219
|
+
{showAdd ? (
|
|
220
|
+
<div
|
|
221
|
+
className="card position-absolute end-0 top-100 mt-1 shadow-sm"
|
|
222
|
+
style={{ zIndex: 20, minWidth: 190 }}
|
|
223
|
+
>
|
|
224
|
+
<div className="list-group list-group-flush">
|
|
225
|
+
{addActions.map((action) => (
|
|
226
|
+
<a
|
|
227
|
+
key={action.path}
|
|
228
|
+
href={`#${action.path}`}
|
|
229
|
+
className="list-group-item list-group-item-action d-flex align-items-center gap-2"
|
|
230
|
+
onClick={() => setShowAdd(false)}
|
|
231
|
+
>
|
|
232
|
+
<i className={`bi ${action.icon}`} />
|
|
233
|
+
{action.label}
|
|
234
|
+
</a>
|
|
235
|
+
))}
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
) : null}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function DetailFrame(props: { backHref: string; backLabel: string; children: ReactNode }) {
|
|
244
|
+
return (
|
|
245
|
+
<div>
|
|
246
|
+
<a href={props.backHref} className="btn btn-link btn-sm px-3 pt-3">
|
|
247
|
+
{props.backLabel}
|
|
248
|
+
</a>
|
|
249
|
+
{props.children}
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function badgeCount(
|
|
255
|
+
rows: IInvite[] | undefined,
|
|
256
|
+
kind: "attention" | "contact" | "group" | "device",
|
|
257
|
+
): number | undefined {
|
|
258
|
+
if (!rows) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
const count = rows.filter((row) =>
|
|
262
|
+
kind === "attention"
|
|
263
|
+
? classifyInvite(row) === "attention"
|
|
264
|
+
: row.type === kind && classifyInvite(row) === "attention",
|
|
265
|
+
).length;
|
|
266
|
+
return count > 0 ? count : undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
registerInternalPeersUI({
|
|
270
|
+
peersUIId: "00identity0screen00000001",
|
|
271
|
+
component: IdentityScreen,
|
|
272
|
+
routes: [
|
|
273
|
+
{
|
|
274
|
+
isMatch: (_props, context) => {
|
|
275
|
+
const path = context.path.split("?")[0];
|
|
276
|
+
return path === "identity" || path.startsWith("identity/");
|
|
277
|
+
},
|
|
278
|
+
uiCategory: "screen",
|
|
279
|
+
priority: 3,
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ICreatedInvite } from "@peers-app/peers-sdk";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { LoadingIndicator } from "../../components/loading-indicator";
|
|
4
|
+
import { InviteShare } from "../invites/invite-share";
|
|
5
|
+
import { inviteTools } from "../invites/invites-ipc";
|
|
6
|
+
|
|
7
|
+
/** Issues a one-off contact invite and shows it as a QR code and link. */
|
|
8
|
+
export function InviteContactPanel({ onClose }: { onClose: () => void }) {
|
|
9
|
+
const [invite, setInvite] = useState<ICreatedInvite | undefined>(undefined);
|
|
10
|
+
const [error, setError] = useState("");
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let cancelled = false;
|
|
14
|
+
void inviteTools()
|
|
15
|
+
.then((tools) => tools.createContactInvite({}))
|
|
16
|
+
.then(({ invite: created }) => {
|
|
17
|
+
if (!cancelled) setInvite(created);
|
|
18
|
+
})
|
|
19
|
+
.catch((err) => {
|
|
20
|
+
if (!cancelled) setError((err as Error).message || "Could not create an invite.");
|
|
21
|
+
});
|
|
22
|
+
return () => {
|
|
23
|
+
cancelled = true;
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="card mb-3">
|
|
29
|
+
<div className="card-body">
|
|
30
|
+
<h6 className="card-title">Invite someone</h6>
|
|
31
|
+
{error ? <div className="alert alert-danger py-2">{error}</div> : null}
|
|
32
|
+
{invite ? (
|
|
33
|
+
<InviteShare
|
|
34
|
+
invite={invite}
|
|
35
|
+
description="Send this link or show the QR. When they accept, you are connected — no need to be online at the same time."
|
|
36
|
+
shareText="Connect with me on Peers:"
|
|
37
|
+
onDone={onClose}
|
|
38
|
+
/>
|
|
39
|
+
) : !error ? (
|
|
40
|
+
<LoadingIndicator />
|
|
41
|
+
) : null}
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ICreatedInvite } from "@peers-app/peers-sdk";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { LoadingIndicator } from "../../components/loading-indicator";
|
|
4
|
+
import { Tooltip } from "../../components/tooltip";
|
|
5
|
+
import { InviteShare } from "../invites/invite-share";
|
|
6
|
+
import { inviteTools } from "../invites/invites-ipc";
|
|
7
|
+
|
|
8
|
+
const PROFILE_QR_INFO = `### Your profile QR
|
|
9
|
+
|
|
10
|
+
Anyone who scans this (or opens the link) can send you a contact request. Requests show up in **Identity → Activity** and nothing happens until you confirm.
|
|
11
|
+
|
|
12
|
+
### Regenerate
|
|
13
|
+
|
|
14
|
+
Regenerating invalidates this QR **and every other invite link you have issued**. Use it if the QR leaked somewhere you did not intend.`;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reusable profile invite.
|
|
18
|
+
*
|
|
19
|
+
* Sharing it asks the other person to request a connection. Regenerating bumps
|
|
20
|
+
* the invite epoch and revokes outstanding links.
|
|
21
|
+
*/
|
|
22
|
+
export function ProfileInviteSection() {
|
|
23
|
+
const [invite, setInvite] = useState<ICreatedInvite | undefined>(undefined);
|
|
24
|
+
const [busy, setBusy] = useState(false);
|
|
25
|
+
const [error, setError] = useState<string | null>(null);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
let cancelled = false;
|
|
29
|
+
void inviteTools()
|
|
30
|
+
.then((tools) => tools.createContactInvite({ profile: true }))
|
|
31
|
+
.then(({ invite: created }) => {
|
|
32
|
+
if (!cancelled) setInvite(created);
|
|
33
|
+
})
|
|
34
|
+
.catch((err) => {
|
|
35
|
+
if (!cancelled) setError((err as Error).message || "Could not load your profile QR.");
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
cancelled = true;
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
const regenerate = async () => {
|
|
43
|
+
if (
|
|
44
|
+
!confirm(
|
|
45
|
+
"Regenerate your profile QR? Every invite link you have issued so far will stop working.",
|
|
46
|
+
)
|
|
47
|
+
) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setBusy(true);
|
|
51
|
+
setError(null);
|
|
52
|
+
try {
|
|
53
|
+
const tools = await inviteTools();
|
|
54
|
+
const { invite: created } = await tools.regenerateProfileInvite();
|
|
55
|
+
setInvite(created);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
setError((err as Error).message || "Could not regenerate.");
|
|
58
|
+
} finally {
|
|
59
|
+
setBusy(false);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div className="card mb-3">
|
|
65
|
+
<div className="card-body">
|
|
66
|
+
<h5 className="card-title d-flex align-items-center gap-2">
|
|
67
|
+
Profile QR
|
|
68
|
+
<Tooltip markdownContent={PROFILE_QR_INFO} />
|
|
69
|
+
</h5>
|
|
70
|
+
{error ? <div className="alert alert-danger py-2">{error}</div> : null}
|
|
71
|
+
{invite ? (
|
|
72
|
+
<InviteShare
|
|
73
|
+
invite={invite}
|
|
74
|
+
description="Let people connect with you by scanning this or opening the link. You confirm each request."
|
|
75
|
+
shareText="Connect with me on Peers:"
|
|
76
|
+
/>
|
|
77
|
+
) : !error ? (
|
|
78
|
+
<LoadingIndicator />
|
|
79
|
+
) : null}
|
|
80
|
+
<div className="text-center mt-3">
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
className="btn btn-outline-danger btn-sm"
|
|
84
|
+
onClick={() => void regenerate()}
|
|
85
|
+
disabled={busy || !invite}
|
|
86
|
+
>
|
|
87
|
+
{busy ? "Regenerating…" : "Regenerate (revokes all invites)"}
|
|
88
|
+
</button>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getUserContext,
|
|
3
|
+
type IAcceptInviteResult,
|
|
4
|
+
type IInvite,
|
|
5
|
+
type IInvitePreview,
|
|
6
|
+
Invites,
|
|
7
|
+
} from "@peers-app/peers-sdk";
|
|
8
|
+
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
9
|
+
import userEvent from "@testing-library/user-event";
|
|
10
|
+
import { AcceptInvite } from "./accept-invite";
|
|
11
|
+
import { inviteTools } from "./invites-ipc";
|
|
12
|
+
|
|
13
|
+
jest.mock("@peers-app/peers-sdk", () => {
|
|
14
|
+
const actual = jest.requireActual<typeof import("@peers-app/peers-sdk")>("@peers-app/peers-sdk");
|
|
15
|
+
return {
|
|
16
|
+
...actual,
|
|
17
|
+
getUserContext: jest.fn(actual.getUserContext),
|
|
18
|
+
Invites: jest.fn(),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
jest.mock("./invites-ipc", () => ({
|
|
23
|
+
inviteTools: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
jest.mock("../../globals", () => ({
|
|
27
|
+
mainContentPath: jest.fn(),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const preview: IInvitePreview = {
|
|
31
|
+
type: "group",
|
|
32
|
+
inviter: {
|
|
33
|
+
userId: "abcdefghijklmnopqrstuvwxy",
|
|
34
|
+
publicKey: "a".repeat(43),
|
|
35
|
+
publicBoxKey: "b".repeat(43),
|
|
36
|
+
displayName: "Ada",
|
|
37
|
+
},
|
|
38
|
+
expiresAt: "2026-10-01T00:00:00.000Z",
|
|
39
|
+
expired: false,
|
|
40
|
+
knownContact: false,
|
|
41
|
+
group: {
|
|
42
|
+
groupId: "zyxwvutsrqponmlkjihgfedcb",
|
|
43
|
+
name: "Neighbors",
|
|
44
|
+
role: 20,
|
|
45
|
+
mode: "open",
|
|
46
|
+
alreadyMember: false,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const pendingResult: IAcceptInviteResult = {
|
|
51
|
+
inviteId: "openjoinrequest0000000001",
|
|
52
|
+
status: "pending",
|
|
53
|
+
deliveryState: "queued",
|
|
54
|
+
groupId: preview.group?.groupId,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
function invite(status: IInvite["status"], deliveryState: IInvite["deliveryState"]): IInvite {
|
|
58
|
+
return {
|
|
59
|
+
inviteId: pendingResult.inviteId,
|
|
60
|
+
direction: "in",
|
|
61
|
+
type: "group",
|
|
62
|
+
status,
|
|
63
|
+
mode: "open",
|
|
64
|
+
counterpart: preview.inviter,
|
|
65
|
+
groupId: preview.group?.groupId,
|
|
66
|
+
groupName: preview.group?.name,
|
|
67
|
+
role: preview.group?.role,
|
|
68
|
+
epoch: 0,
|
|
69
|
+
recipientUserId: preview.inviter.userId,
|
|
70
|
+
deliveryState,
|
|
71
|
+
createdAt: new Date("2026-09-22T00:00:00.000Z"),
|
|
72
|
+
expiresAt: new Date(preview.expiresAt),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe("AcceptInvite", () => {
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
jest.clearAllMocks();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("shows automatic progress and reacts when the delayed approval arrives", async () => {
|
|
82
|
+
let row = invite("pending", "queued");
|
|
83
|
+
let onDataChanged: ((event: { dataObject: IInvite }) => void) | undefined;
|
|
84
|
+
const table = {
|
|
85
|
+
get: jest.fn(async () => row),
|
|
86
|
+
dataChanged: {
|
|
87
|
+
subscribe: jest.fn((listener: typeof onDataChanged) => {
|
|
88
|
+
onDataChanged = listener;
|
|
89
|
+
return { unsubscribe: jest.fn() };
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
(getUserContext as jest.Mock).mockResolvedValue({ userDataContext: {} });
|
|
94
|
+
(Invites as jest.Mock).mockReturnValue(table);
|
|
95
|
+
(inviteTools as jest.Mock).mockResolvedValue({
|
|
96
|
+
previewInvite: jest.fn().mockResolvedValue({ preview }),
|
|
97
|
+
acceptInvite: jest.fn().mockResolvedValue({ result: pendingResult }),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
render(<AcceptInvite initialToken="signed-token" />);
|
|
101
|
+
await userEvent.click(await screen.findByRole("button", { name: "Join" }));
|
|
102
|
+
|
|
103
|
+
expect(await screen.findByText("Finishing your automatic join to Neighbors.")).toBeVisible();
|
|
104
|
+
expect(screen.getByText("Waiting for a route; Peers will retry automatically.")).toBeVisible();
|
|
105
|
+
expect(screen.queryByText(/once it is approved/i)).not.toBeInTheDocument();
|
|
106
|
+
|
|
107
|
+
row = invite("accepted", "sent");
|
|
108
|
+
await act(async () => {
|
|
109
|
+
onDataChanged?.({ dataObject: row });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
await waitFor(() => expect(screen.getByText("You joined Neighbors.")).toBeVisible());
|
|
113
|
+
expect(screen.getByRole("button", { name: "Open group" })).toBeEnabled();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getRoleLabel,
|
|
3
|
+
getUserContext,
|
|
3
4
|
type IAcceptInviteResult,
|
|
4
5
|
type IInvitePreview,
|
|
6
|
+
Invites,
|
|
5
7
|
TrustLevel,
|
|
6
8
|
} from "@peers-app/peers-sdk";
|
|
7
9
|
import { useCallback, useEffect, useState } from "react";
|
|
@@ -59,19 +61,22 @@ function ResultPanel(props: {
|
|
|
59
61
|
}) {
|
|
60
62
|
const { result, preview } = props;
|
|
61
63
|
const accepted = result.status === "accepted";
|
|
64
|
+
const openGroup = preview.type === "group" && preview.group?.mode === "open";
|
|
62
65
|
const message = accepted
|
|
63
66
|
? preview.type === "group"
|
|
64
67
|
? `You joined ${preview.group?.name}.`
|
|
65
68
|
: "Contact added."
|
|
66
69
|
: preview.type === "group"
|
|
67
|
-
?
|
|
70
|
+
? openGroup
|
|
71
|
+
? `Finishing your automatic join to ${preview.group?.name}.`
|
|
72
|
+
: "Join request sent. You will be added once it is approved."
|
|
68
73
|
: "Request sent. They will see it and confirm.";
|
|
69
74
|
return (
|
|
70
75
|
<div className="text-center">
|
|
71
76
|
<output className={`alert d-block ${accepted ? "alert-success" : "alert-info"}`}>
|
|
72
77
|
{message}
|
|
73
78
|
{result.deliveryState === "queued" ? (
|
|
74
|
-
<div className="small mt-1">
|
|
79
|
+
<div className="small mt-1">Waiting for a route; Peers will retry automatically.</div>
|
|
75
80
|
) : null}
|
|
76
81
|
</output>
|
|
77
82
|
<div className="d-flex gap-2 justify-content-center">
|
|
@@ -79,7 +84,7 @@ function ResultPanel(props: {
|
|
|
79
84
|
<button
|
|
80
85
|
type="button"
|
|
81
86
|
className="btn btn-primary"
|
|
82
|
-
onClick={() => mainContentPath(`groups/${result.groupId}`)}
|
|
87
|
+
onClick={() => mainContentPath(`identity/groups/${result.groupId}`)}
|
|
83
88
|
>
|
|
84
89
|
Open group
|
|
85
90
|
</button>
|
|
@@ -136,6 +141,48 @@ export function AcceptInvite(props: AcceptInviteProps) {
|
|
|
136
141
|
return () => sub.dispose();
|
|
137
142
|
}, [props.initialToken, runPreview]);
|
|
138
143
|
|
|
144
|
+
const resultInviteId = result?.inviteId;
|
|
145
|
+
const resultStatus = result?.status;
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!resultInviteId || resultStatus !== "pending") {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
let disposed = false;
|
|
151
|
+
let unsubscribe: (() => void) | undefined;
|
|
152
|
+
void getUserContext().then(async (userContext) => {
|
|
153
|
+
if (disposed) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const table = Invites(userContext.userDataContext);
|
|
157
|
+
const refresh = async () => {
|
|
158
|
+
const row = await table.get(resultInviteId);
|
|
159
|
+
if (!disposed && row) {
|
|
160
|
+
setResult((current) =>
|
|
161
|
+
current?.inviteId === resultInviteId
|
|
162
|
+
? {
|
|
163
|
+
...current,
|
|
164
|
+
status: row.status,
|
|
165
|
+
deliveryState: row.deliveryState,
|
|
166
|
+
groupId: row.groupId ?? current.groupId,
|
|
167
|
+
}
|
|
168
|
+
: current,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const subscription = table.dataChanged.subscribe((event) => {
|
|
173
|
+
if (event.dataObject.inviteId === resultInviteId) {
|
|
174
|
+
void refresh();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
unsubscribe = () => subscription.unsubscribe();
|
|
178
|
+
await refresh();
|
|
179
|
+
});
|
|
180
|
+
return () => {
|
|
181
|
+
disposed = true;
|
|
182
|
+
unsubscribe?.();
|
|
183
|
+
};
|
|
184
|
+
}, [resultInviteId, resultStatus]);
|
|
185
|
+
|
|
139
186
|
const accept = async () => {
|
|
140
187
|
setError("");
|
|
141
188
|
setBusy(true);
|