@peers-app/peers-ui 0.25.1 → 0.25.3

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 (177) hide show
  1. package/README.md +2 -1
  2. package/dist/components/markdown-editor/mention-node.d.ts +4 -0
  3. package/dist/components/markdown-editor/mention-node.js +4 -1
  4. package/dist/components/responsive-section-nav.d.ts +34 -0
  5. package/dist/components/responsive-section-nav.js +19 -0
  6. package/dist/components/responsive-section-nav.test.d.ts +1 -0
  7. package/dist/components/responsive-section-nav.test.js +45 -0
  8. package/dist/components/router.d.ts +2 -3
  9. package/dist/components/router.js +6 -9
  10. package/dist/globals-hash.test.d.ts +1 -0
  11. package/dist/globals-hash.test.js +16 -0
  12. package/dist/globals.d.ts +19 -0
  13. package/dist/globals.js +51 -12
  14. package/dist/hooks/use-host-contract.d.ts +18 -0
  15. package/dist/hooks/use-host-contract.js +53 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/peers-services-registration.d.ts +1 -5
  19. package/dist/peers-services-registration.js +6 -16
  20. package/dist/root-layout/root-layout-host.js +7 -4
  21. package/dist/root-layout/root-layout-host.test.js +3 -6
  22. package/dist/screens/account/account-screen.d.ts +1 -0
  23. package/dist/screens/account/account-screen.js +29 -53
  24. package/dist/screens/account/account-screen.test.d.ts +1 -0
  25. package/dist/screens/account/account-screen.test.js +47 -0
  26. package/dist/screens/contacts/contact-details.js +2 -23
  27. package/dist/screens/contacts/contact-list.d.ts +24 -1
  28. package/dist/screens/contacts/contact-list.js +128 -143
  29. package/dist/screens/contacts/contact-list.test.d.ts +1 -0
  30. package/dist/screens/contacts/contact-list.test.js +48 -0
  31. package/dist/screens/contacts/index.d.ts +0 -2
  32. package/dist/screens/contacts/index.js +0 -3
  33. package/dist/screens/device-pairing/device-pairing.js +17 -16
  34. package/dist/screens/device-pairing/device-pairing.test.js +4 -9
  35. package/dist/screens/device-pairing/identity-ipc.d.ts +11 -0
  36. package/dist/screens/device-pairing/identity-ipc.js +20 -0
  37. package/dist/screens/device-pairing/use-device-pairing-state.d.ts +2 -2
  38. package/dist/screens/device-pairing/use-device-pairing-state.js +7 -25
  39. package/dist/screens/devices/devices-list.d.ts +18 -0
  40. package/dist/screens/devices/devices-list.js +173 -0
  41. package/dist/screens/devices/devices-list.test.d.ts +1 -0
  42. package/dist/screens/devices/devices-list.test.js +53 -0
  43. package/dist/screens/devices/index.d.ts +1 -0
  44. package/dist/screens/devices/index.js +5 -0
  45. package/dist/screens/groups/group-details.d.ts +1 -0
  46. package/dist/screens/groups/group-details.js +4 -63
  47. package/dist/screens/groups/group-invite-panel.js +2 -2
  48. package/dist/screens/groups/group-list.d.ts +18 -1
  49. package/dist/screens/groups/group-list.js +107 -136
  50. package/dist/screens/groups/group-list.test.d.ts +1 -0
  51. package/dist/screens/groups/group-list.test.js +38 -0
  52. package/dist/screens/groups/group-members.d.ts +1 -0
  53. package/dist/screens/groups/group-members.js +2 -1
  54. package/dist/screens/groups/index.d.ts +0 -3
  55. package/dist/screens/groups/index.js +0 -4
  56. package/dist/screens/identity/identity-routes.d.ts +107 -0
  57. package/dist/screens/identity/identity-routes.js +245 -0
  58. package/dist/screens/identity/identity-routes.test.d.ts +1 -0
  59. package/dist/screens/identity/identity-routes.test.js +51 -0
  60. package/dist/screens/identity/identity-screen.d.ts +9 -0
  61. package/dist/screens/identity/identity-screen.js +143 -0
  62. package/dist/screens/identity/identity-screen.test.d.ts +1 -0
  63. package/dist/screens/identity/identity-screen.test.js +103 -0
  64. package/dist/screens/identity/index.d.ts +2 -0
  65. package/dist/screens/identity/index.js +6 -0
  66. package/dist/screens/identity/invite-contact-panel.d.ts +4 -0
  67. package/dist/screens/identity/invite-contact-panel.js +30 -0
  68. package/dist/screens/identity/profile-invite.d.ts +7 -0
  69. package/dist/screens/identity/profile-invite.js +62 -0
  70. package/dist/screens/invites/accept-invite.js +1 -1
  71. package/dist/screens/invites/activity-view.d.ts +24 -0
  72. package/dist/screens/invites/activity-view.js +64 -0
  73. package/dist/screens/invites/activity-view.test.d.ts +1 -0
  74. package/dist/screens/invites/activity-view.test.js +108 -0
  75. package/dist/screens/invites/index.d.ts +1 -2
  76. package/dist/screens/invites/index.js +1 -3
  77. package/dist/screens/invites/invite-capture.d.ts +0 -2
  78. package/dist/screens/invites/invite-capture.js +1 -3
  79. package/dist/screens/invites/invite-classify.test.d.ts +1 -0
  80. package/dist/screens/invites/invite-classify.test.js +98 -0
  81. package/dist/screens/invites/invites-ipc.d.ts +1 -1
  82. package/dist/screens/invites/invites-ipc.js +5 -45
  83. package/dist/screens/invites/pending-invites-list.d.ts +35 -16
  84. package/dist/screens/invites/pending-invites-list.js +69 -30
  85. package/dist/screens/network-viewer/network-viewer-ipc.js +4 -59
  86. package/dist/screens/search/global-search.d.ts +1 -0
  87. package/dist/screens/search/global-search.js +2 -1
  88. package/dist/screens/settings/settings-page.js +25 -58
  89. package/dist/screens/setup-user.js +5 -5
  90. package/dist/screens/tools/tool-access-ipc.d.ts +2 -0
  91. package/dist/screens/tools/tool-access-ipc.js +8 -55
  92. package/dist/screens/welcome-modal.js +3 -2
  93. package/dist/system-apps/identity.app.d.ts +3 -0
  94. package/dist/system-apps/identity.app.js +10 -0
  95. package/dist/system-apps/index.d.ts +1 -4
  96. package/dist/system-apps/index.js +5 -17
  97. package/dist/tabs-layout/network-status-indicator.js +10 -3
  98. package/dist/tabs-layout/network-status-indicator.test.js +15 -0
  99. package/dist/tabs-layout/tabs-layout.js +3 -1
  100. package/dist/tabs-layout/tabs-state.d.ts +79 -1
  101. package/dist/tabs-layout/tabs-state.js +256 -79
  102. package/dist/tabs-layout/tabs-state.test.d.ts +1 -0
  103. package/dist/tabs-layout/tabs-state.test.js +110 -0
  104. package/package.json +3 -3
  105. package/src/components/markdown-editor/mention-node.ts +5 -1
  106. package/src/components/responsive-section-nav.test.tsx +88 -0
  107. package/src/components/responsive-section-nav.tsx +92 -0
  108. package/src/components/router.tsx +6 -9
  109. package/src/globals-hash.test.ts +19 -0
  110. package/src/globals.tsx +53 -13
  111. package/src/hooks/use-host-contract.ts +75 -0
  112. package/src/index.tsx +1 -0
  113. package/src/peers-services-registration.ts +6 -17
  114. package/src/root-layout/root-layout-host.test.tsx +4 -7
  115. package/src/root-layout/root-layout-host.tsx +9 -11
  116. package/src/screens/account/account-screen.test.tsx +61 -0
  117. package/src/screens/account/account-screen.tsx +116 -95
  118. package/src/screens/contacts/contact-details.tsx +4 -26
  119. package/src/screens/contacts/contact-list.test.tsx +59 -0
  120. package/src/screens/contacts/contact-list.tsx +246 -260
  121. package/src/screens/contacts/index.ts +0 -4
  122. package/src/screens/device-pairing/device-pairing.test.tsx +7 -9
  123. package/src/screens/device-pairing/device-pairing.tsx +19 -23
  124. package/src/screens/device-pairing/identity-ipc.ts +25 -0
  125. package/src/screens/device-pairing/use-device-pairing-state.ts +10 -33
  126. package/src/screens/devices/devices-list.test.tsx +68 -0
  127. package/src/screens/devices/devices-list.tsx +361 -0
  128. package/src/screens/devices/index.ts +1 -0
  129. package/src/screens/groups/group-details.tsx +8 -142
  130. package/src/screens/groups/group-invite-panel.tsx +2 -7
  131. package/src/screens/groups/group-list.test.tsx +44 -0
  132. package/src/screens/groups/group-list.tsx +227 -288
  133. package/src/screens/groups/group-members.tsx +3 -2
  134. package/src/screens/groups/index.ts +0 -5
  135. package/src/screens/identity/identity-routes.test.ts +70 -0
  136. package/src/screens/identity/identity-routes.ts +301 -0
  137. package/src/screens/identity/identity-screen.test.tsx +138 -0
  138. package/src/screens/identity/identity-screen.tsx +282 -0
  139. package/src/screens/identity/index.ts +2 -0
  140. package/src/screens/identity/invite-contact-panel.tsx +45 -0
  141. package/src/screens/identity/profile-invite.tsx +93 -0
  142. package/src/screens/invites/accept-invite.tsx +1 -1
  143. package/src/screens/invites/activity-view.test.tsx +127 -0
  144. package/src/screens/invites/activity-view.tsx +162 -0
  145. package/src/screens/invites/index.ts +1 -4
  146. package/src/screens/invites/invite-capture.ts +0 -3
  147. package/src/screens/invites/invite-classify.test.ts +110 -0
  148. package/src/screens/invites/invites-ipc.ts +6 -55
  149. package/src/screens/invites/pending-invites-list.tsx +85 -61
  150. package/src/screens/network-viewer/network-viewer-ipc.ts +8 -82
  151. package/src/screens/search/global-search.tsx +2 -1
  152. package/src/screens/settings/settings-page.tsx +53 -126
  153. package/src/screens/setup-user.tsx +5 -6
  154. package/src/screens/tools/tool-access-ipc.ts +13 -74
  155. package/src/screens/welcome-modal.tsx +3 -3
  156. package/src/system-apps/identity.app.ts +9 -0
  157. package/src/system-apps/index.ts +3 -12
  158. package/src/tabs-layout/network-status-indicator.test.tsx +22 -0
  159. package/src/tabs-layout/network-status-indicator.tsx +31 -0
  160. package/src/tabs-layout/tabs-layout.tsx +7 -1
  161. package/src/tabs-layout/tabs-state.test.ts +152 -0
  162. package/src/tabs-layout/tabs-state.ts +300 -83
  163. package/dist/screens/invites/invites-screen.d.ts +0 -9
  164. package/dist/screens/invites/invites-screen.js +0 -36
  165. package/dist/system-apps/account.app.d.ts +0 -2
  166. package/dist/system-apps/account.app.js +0 -8
  167. package/dist/system-apps/contacts.app.d.ts +0 -2
  168. package/dist/system-apps/contacts.app.js +0 -9
  169. package/dist/system-apps/groups.app.d.ts +0 -2
  170. package/dist/system-apps/groups.app.js +0 -9
  171. package/dist/system-apps/invites.app.d.ts +0 -2
  172. package/dist/system-apps/invites.app.js +0 -9
  173. package/src/screens/invites/invites-screen.tsx +0 -78
  174. package/src/system-apps/account.app.ts +0 -7
  175. package/src/system-apps/contacts.app.ts +0 -8
  176. package/src/system-apps/groups.app.ts +0 -8
  177. 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,2 @@
1
+ export { identityApp } from "../../system-apps/identity.app";
2
+ import "./identity-screen";
@@ -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
+ }
@@ -79,7 +79,7 @@ function ResultPanel(props: {
79
79
  <button
80
80
  type="button"
81
81
  className="btn btn-primary"
82
- onClick={() => mainContentPath(`groups/${result.groupId}`)}
82
+ onClick={() => mainContentPath(`identity/groups/${result.groupId}`)}
83
83
  >
84
84
  Open group
85
85
  </button>
@@ -0,0 +1,127 @@
1
+ import type { IInvite } from "@peers-app/peers-sdk";
2
+ import { render, screen, waitFor } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { ActivityView } from "./activity-view";
5
+ import { inviteTools } from "./invites-ipc";
6
+ import { useInviteRows } from "./pending-invites-list";
7
+
8
+ jest.mock("./pending-invites-list", () => {
9
+ const actual =
10
+ jest.requireActual<typeof import("./pending-invites-list")>("./pending-invites-list");
11
+ return {
12
+ ...actual,
13
+ useInviteRows: jest.fn(),
14
+ };
15
+ });
16
+
17
+ jest.mock("./invites-ipc", () => ({
18
+ inviteTools: jest.fn(),
19
+ }));
20
+
21
+ function invite(
22
+ partial: Partial<IInvite> & Pick<IInvite, "inviteId" | "direction" | "type" | "mode">,
23
+ ): IInvite {
24
+ return {
25
+ status: "pending",
26
+ epoch: 1,
27
+ createdAt: new Date("2026-01-01T00:00:00Z"),
28
+ expiresAt: new Date("2026-02-01T00:00:00Z"),
29
+ counterpart: { userId: "abcdefghijklmnopqrstuvwxy", displayName: "Ada" },
30
+ ...partial,
31
+ } as IInvite;
32
+ }
33
+
34
+ const attention = invite({
35
+ inviteId: "inboundcontact0000000001",
36
+ direction: "in",
37
+ type: "contact",
38
+ mode: "contact",
39
+ });
40
+ const waiting = invite({
41
+ inviteId: "outboundcontact0000000001",
42
+ direction: "out",
43
+ type: "contact",
44
+ mode: "contact",
45
+ });
46
+ const joinRequest = invite({
47
+ inviteId: "groupjoinrequest000000001",
48
+ direction: "in",
49
+ type: "group",
50
+ mode: "approve",
51
+ groupId: "zyxwvutsrqponmlkjihgfedcb",
52
+ groupName: "Neighbors",
53
+ });
54
+ const history = invite({
55
+ inviteId: "oldcontact000000000000001",
56
+ direction: "in",
57
+ type: "contact",
58
+ mode: "contact",
59
+ status: "accepted",
60
+ });
61
+
62
+ const mockedRows = useInviteRows as jest.MockedFunction<typeof useInviteRows>;
63
+ const acceptInvite = jest.fn();
64
+ const approveJoinRequest = jest.fn();
65
+
66
+ describe("ActivityView", () => {
67
+ beforeEach(() => {
68
+ acceptInvite.mockReset();
69
+ approveJoinRequest.mockReset();
70
+ (inviteTools as jest.Mock).mockResolvedValue({
71
+ acceptInvite,
72
+ declineInvite: jest.fn(),
73
+ approveJoinRequest,
74
+ denyJoinRequest: jest.fn(),
75
+ revokeInvite: jest.fn(),
76
+ });
77
+ mockedRows.mockImplementation((filter) => ({
78
+ rows: filter.statuses?.includes("accepted") ? [history] : [attention, joinRequest, waiting],
79
+ hasHistory: true,
80
+ }));
81
+ });
82
+
83
+ it("offers approval for a received group join request", async () => {
84
+ render(<ActivityView />);
85
+
86
+ expect(screen.getByText("Ada wants to join Neighbors")).toBeInTheDocument();
87
+ await userEvent.click(screen.getByRole("button", { name: "Approve" }));
88
+ await waitFor(() =>
89
+ expect(approveJoinRequest).toHaveBeenCalledWith({ inviteId: joinRequest.inviteId }),
90
+ );
91
+ });
92
+
93
+ it("splits pending invites and accepts a request from the inbox", async () => {
94
+ render(<ActivityView />);
95
+
96
+ expect(screen.getByRole("heading", { name: "Needs your attention" })).toBeInTheDocument();
97
+ expect(screen.getByRole("heading", { name: "Waiting on others" })).toBeInTheDocument();
98
+ expect(screen.getByText("Ada wants to connect")).toBeInTheDocument();
99
+
100
+ await userEvent.click(screen.getByRole("button", { name: "Accept" }));
101
+ await waitFor(() =>
102
+ expect(acceptInvite).toHaveBeenCalledWith({ inviteId: attention.inviteId }),
103
+ );
104
+ });
105
+
106
+ it("switches to history and shows an empty pending inbox", async () => {
107
+ const view = render(<ActivityView />);
108
+ await userEvent.click(screen.getByRole("button", { name: "History" }));
109
+ expect(screen.getByRole("heading", { name: "History" })).toBeInTheDocument();
110
+ expect(screen.getByText(/accepted/i)).toBeInTheDocument();
111
+ expect(screen.queryByRole("heading", { name: "Needs your attention" })).not.toBeInTheDocument();
112
+
113
+ mockedRows.mockReturnValue({ rows: [], hasHistory: false });
114
+ view.rerender(<ActivityView />);
115
+ await userEvent.click(screen.getByRole("button", { name: "Pending" }));
116
+ expect(screen.getByText("No invites need attention.")).toBeInTheDocument();
117
+ });
118
+
119
+ it("shows the active filter", () => {
120
+ render(<ActivityView filter={{ type: "group", groupId: "zyxwvutsrqponmlkjihgfedcb" }} />);
121
+ expect(screen.getByText("Showing invites for this group.")).toBeInTheDocument();
122
+ expect(screen.getByRole("link", { name: "Show all" })).toHaveAttribute(
123
+ "href",
124
+ "#identity/activity",
125
+ );
126
+ });
127
+ });