@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.
Files changed (180) 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 +44 -2
  71. package/dist/screens/invites/accept-invite.test.d.ts +1 -0
  72. package/dist/screens/invites/accept-invite.test.js +103 -0
  73. package/dist/screens/invites/activity-view.d.ts +24 -0
  74. package/dist/screens/invites/activity-view.js +64 -0
  75. package/dist/screens/invites/activity-view.test.d.ts +1 -0
  76. package/dist/screens/invites/activity-view.test.js +108 -0
  77. package/dist/screens/invites/index.d.ts +1 -2
  78. package/dist/screens/invites/index.js +1 -3
  79. package/dist/screens/invites/invite-capture.d.ts +0 -2
  80. package/dist/screens/invites/invite-capture.js +1 -3
  81. package/dist/screens/invites/invite-classify.test.d.ts +1 -0
  82. package/dist/screens/invites/invite-classify.test.js +115 -0
  83. package/dist/screens/invites/invites-ipc.d.ts +1 -1
  84. package/dist/screens/invites/invites-ipc.js +5 -45
  85. package/dist/screens/invites/pending-invites-list.d.ts +35 -16
  86. package/dist/screens/invites/pending-invites-list.js +75 -30
  87. package/dist/screens/network-viewer/network-viewer-ipc.js +4 -59
  88. package/dist/screens/search/global-search.d.ts +1 -0
  89. package/dist/screens/search/global-search.js +2 -1
  90. package/dist/screens/settings/settings-page.js +25 -58
  91. package/dist/screens/setup-user.js +5 -5
  92. package/dist/screens/tools/tool-access-ipc.d.ts +2 -0
  93. package/dist/screens/tools/tool-access-ipc.js +8 -55
  94. package/dist/screens/welcome-modal.js +3 -2
  95. package/dist/system-apps/identity.app.d.ts +3 -0
  96. package/dist/system-apps/identity.app.js +10 -0
  97. package/dist/system-apps/index.d.ts +1 -4
  98. package/dist/system-apps/index.js +5 -17
  99. package/dist/tabs-layout/network-status-indicator.js +10 -3
  100. package/dist/tabs-layout/network-status-indicator.test.js +15 -0
  101. package/dist/tabs-layout/tabs-layout.js +3 -1
  102. package/dist/tabs-layout/tabs-state.d.ts +79 -1
  103. package/dist/tabs-layout/tabs-state.js +256 -79
  104. package/dist/tabs-layout/tabs-state.test.d.ts +1 -0
  105. package/dist/tabs-layout/tabs-state.test.js +110 -0
  106. package/package.json +3 -3
  107. package/src/components/markdown-editor/mention-node.ts +5 -1
  108. package/src/components/responsive-section-nav.test.tsx +88 -0
  109. package/src/components/responsive-section-nav.tsx +92 -0
  110. package/src/components/router.tsx +6 -9
  111. package/src/globals-hash.test.ts +19 -0
  112. package/src/globals.tsx +53 -13
  113. package/src/hooks/use-host-contract.ts +75 -0
  114. package/src/index.tsx +1 -0
  115. package/src/peers-services-registration.ts +6 -17
  116. package/src/root-layout/root-layout-host.test.tsx +4 -7
  117. package/src/root-layout/root-layout-host.tsx +9 -11
  118. package/src/screens/account/account-screen.test.tsx +61 -0
  119. package/src/screens/account/account-screen.tsx +116 -95
  120. package/src/screens/contacts/contact-details.tsx +4 -26
  121. package/src/screens/contacts/contact-list.test.tsx +59 -0
  122. package/src/screens/contacts/contact-list.tsx +246 -260
  123. package/src/screens/contacts/index.ts +0 -4
  124. package/src/screens/device-pairing/device-pairing.test.tsx +7 -9
  125. package/src/screens/device-pairing/device-pairing.tsx +19 -23
  126. package/src/screens/device-pairing/identity-ipc.ts +25 -0
  127. package/src/screens/device-pairing/use-device-pairing-state.ts +10 -33
  128. package/src/screens/devices/devices-list.test.tsx +68 -0
  129. package/src/screens/devices/devices-list.tsx +361 -0
  130. package/src/screens/devices/index.ts +1 -0
  131. package/src/screens/groups/group-details.tsx +8 -142
  132. package/src/screens/groups/group-invite-panel.tsx +2 -7
  133. package/src/screens/groups/group-list.test.tsx +44 -0
  134. package/src/screens/groups/group-list.tsx +227 -288
  135. package/src/screens/groups/group-members.tsx +3 -2
  136. package/src/screens/groups/index.ts +0 -5
  137. package/src/screens/identity/identity-routes.test.ts +70 -0
  138. package/src/screens/identity/identity-routes.ts +301 -0
  139. package/src/screens/identity/identity-screen.test.tsx +138 -0
  140. package/src/screens/identity/identity-screen.tsx +282 -0
  141. package/src/screens/identity/index.ts +2 -0
  142. package/src/screens/identity/invite-contact-panel.tsx +45 -0
  143. package/src/screens/identity/profile-invite.tsx +93 -0
  144. package/src/screens/invites/accept-invite.test.tsx +115 -0
  145. package/src/screens/invites/accept-invite.tsx +50 -3
  146. package/src/screens/invites/activity-view.test.tsx +127 -0
  147. package/src/screens/invites/activity-view.tsx +162 -0
  148. package/src/screens/invites/index.ts +1 -4
  149. package/src/screens/invites/invite-capture.ts +0 -3
  150. package/src/screens/invites/invite-classify.test.ts +129 -0
  151. package/src/screens/invites/invites-ipc.ts +6 -55
  152. package/src/screens/invites/pending-invites-list.tsx +94 -62
  153. package/src/screens/network-viewer/network-viewer-ipc.ts +8 -82
  154. package/src/screens/search/global-search.tsx +2 -1
  155. package/src/screens/settings/settings-page.tsx +53 -126
  156. package/src/screens/setup-user.tsx +5 -6
  157. package/src/screens/tools/tool-access-ipc.ts +13 -74
  158. package/src/screens/welcome-modal.tsx +3 -3
  159. package/src/system-apps/identity.app.ts +9 -0
  160. package/src/system-apps/index.ts +3 -12
  161. package/src/tabs-layout/network-status-indicator.test.tsx +22 -0
  162. package/src/tabs-layout/network-status-indicator.tsx +31 -0
  163. package/src/tabs-layout/tabs-layout.tsx +7 -1
  164. package/src/tabs-layout/tabs-state.test.ts +152 -0
  165. package/src/tabs-layout/tabs-state.ts +300 -83
  166. package/dist/screens/invites/invites-screen.d.ts +0 -9
  167. package/dist/screens/invites/invites-screen.js +0 -36
  168. package/dist/system-apps/account.app.d.ts +0 -2
  169. package/dist/system-apps/account.app.js +0 -8
  170. package/dist/system-apps/contacts.app.d.ts +0 -2
  171. package/dist/system-apps/contacts.app.js +0 -9
  172. package/dist/system-apps/groups.app.d.ts +0 -2
  173. package/dist/system-apps/groups.app.js +0 -9
  174. package/dist/system-apps/invites.app.d.ts +0 -2
  175. package/dist/system-apps/invites.app.js +0 -9
  176. package/src/screens/invites/invites-screen.tsx +0 -78
  177. package/src/system-apps/account.app.ts +0 -7
  178. package/src/system-apps/contacts.app.ts +0 -8
  179. package/src/system-apps/groups.app.ts +0 -8
  180. package/src/system-apps/invites.app.ts +0 -8
@@ -0,0 +1,70 @@
1
+ import {
2
+ canonicalizeRoute,
3
+ IDENTITY_ACCEPT_PATH,
4
+ IDENTITY_ACCOUNT_PATH,
5
+ IDENTITY_ACTIVITY_PATH,
6
+ IDENTITY_DEVICES_PATH,
7
+ IDENTITY_GROUP_NEW_PATH,
8
+ IDENTITY_GROUPS_PATH,
9
+ IDENTITY_PAIR_PATH,
10
+ IDENTITY_PEOPLE_INVITE_PATH,
11
+ IDENTITY_PEOPLE_PATH,
12
+ IDENTITY_PEOPLE_SHARE_PATH,
13
+ identityActivityFilterPath,
14
+ identitySectionFromPath,
15
+ isIdentityPath,
16
+ parseIdentityLocation,
17
+ } from "./identity-routes";
18
+
19
+ const PERSON_ID = "abcdefghijklmnopqrstuvwxy";
20
+ const GROUP_ID = "zyxwvutsrqponmlkjihgfedcb";
21
+ const DEVICE_ID = "0123456789abcdefghijklmno";
22
+
23
+ describe("canonicalizeRoute", () => {
24
+ it.each([
25
+ ["contacts", IDENTITY_PEOPLE_PATH],
26
+ [`contacts/${PERSON_ID}`, `${IDENTITY_PEOPLE_PATH}/${PERSON_ID}`],
27
+ ["groups", IDENTITY_GROUPS_PATH],
28
+ [`groups/${GROUP_ID}`, `${IDENTITY_GROUPS_PATH}/${GROUP_ID}`],
29
+ ["devices", IDENTITY_DEVICES_PATH],
30
+ [`devices/${DEVICE_ID}`, `${IDENTITY_DEVICES_PATH}/${DEVICE_ID}`],
31
+ ["devices?action=pair", IDENTITY_PAIR_PATH],
32
+ ["devices?action=pair&foo=bar", `${IDENTITY_PAIR_PATH}?foo=bar`],
33
+ ["invites", IDENTITY_ACTIVITY_PATH],
34
+ ["invites/accept", IDENTITY_ACCEPT_PATH],
35
+ ["account", IDENTITY_ACCOUNT_PATH],
36
+ ["account?x=1", `${IDENTITY_ACCOUNT_PATH}?x=1`],
37
+ ["identity/account", IDENTITY_ACCOUNT_PATH],
38
+ ["identity/people/invite", IDENTITY_PEOPLE_INVITE_PATH],
39
+ ["identity/people/SHARE", IDENTITY_PEOPLE_SHARE_PATH],
40
+ ["identity/groups/new", IDENTITY_GROUP_NEW_PATH],
41
+ ["identity", IDENTITY_ACTIVITY_PATH],
42
+ [`/#contacts/${PERSON_ID}?x=1`, `${IDENTITY_PEOPLE_PATH}/${PERSON_ID}?x=1`],
43
+ ["tools/abc", "tools/abc"],
44
+ ["", ""],
45
+ ])("rewrites %s to %s", (input, expected) => {
46
+ expect(canonicalizeRoute(input)).toBe(expected);
47
+ });
48
+ });
49
+
50
+ describe("parseIdentityLocation", () => {
51
+ it("parses detail routes and activity filters", () => {
52
+ expect(parseIdentityLocation(`contacts/${PERSON_ID}`)?.personId).toBe(PERSON_ID);
53
+ expect(parseIdentityLocation(`groups/${GROUP_ID}`)?.groupId).toBe(GROUP_ID);
54
+ expect(parseIdentityLocation("devices?action=pair")?.pairing).toBe(true);
55
+ expect(parseIdentityLocation(`devices/${DEVICE_ID}`)?.deviceId).toBe(DEVICE_ID);
56
+ expect(parseIdentityLocation("invites/accept")?.accepting).toBe(true);
57
+ expect(parseIdentityLocation(IDENTITY_PEOPLE_INVITE_PATH)?.peopleAction).toBe("invite");
58
+ expect(parseIdentityLocation(IDENTITY_PEOPLE_SHARE_PATH)?.peopleAction).toBe("share");
59
+ expect(parseIdentityLocation(IDENTITY_GROUP_NEW_PATH)?.creatingGroup).toBe(true);
60
+ expect(
61
+ parseIdentityLocation(identityActivityFilterPath("group", GROUP_ID))?.activityFilter,
62
+ ).toEqual({
63
+ type: "group",
64
+ groupId: GROUP_ID,
65
+ });
66
+ expect(identitySectionFromPath("contacts")).toBe("people");
67
+ expect(identitySectionFromPath("account")).toBe("account");
68
+ expect(isIdentityPath("settings")).toBe(false);
69
+ });
70
+ });
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Canonical Identity routes and legacy aliases.
3
+ *
4
+ * Contacts, Groups, Devices, Account, and the old Invites paths all render
5
+ * inside the Identity app. Navigation rewrites those aliases before a tab is
6
+ * updated.
7
+ */
8
+
9
+ /** Top-level Identity app path. Opening this lands on Activity. */
10
+ export const IDENTITY_APP_PATH = "identity";
11
+
12
+ /** Unified invite inbox. */
13
+ export const IDENTITY_ACTIVITY_PATH = "identity/activity";
14
+
15
+ /** Paste or scan an invite. */
16
+ export const IDENTITY_ACCEPT_PATH = "identity/activity/accept";
17
+
18
+ /** People (contacts) list. */
19
+ export const IDENTITY_PEOPLE_PATH = "identity/people";
20
+
21
+ /** Issue a one-off invitation to connect with a person. */
22
+ export const IDENTITY_PEOPLE_INVITE_PATH = "identity/people/invite";
23
+
24
+ /** Show the reusable profile invitation. */
25
+ export const IDENTITY_PEOPLE_SHARE_PATH = "identity/people/share";
26
+
27
+ /** Groups list. */
28
+ export const IDENTITY_GROUPS_PATH = "identity/groups";
29
+
30
+ /** Create a group. */
31
+ export const IDENTITY_GROUP_NEW_PATH = "identity/groups/new";
32
+
33
+ /** Devices list. */
34
+ export const IDENTITY_DEVICES_PATH = "identity/devices";
35
+
36
+ /** Source-device pairing flow. */
37
+ export const IDENTITY_PAIR_PATH = "identity/devices/pair";
38
+
39
+ /** Peers Services registration. */
40
+ export const IDENTITY_ACCOUNT_PATH = "identity/account";
41
+
42
+ /** Sidebar sections of the Identity app. */
43
+ export type IdentitySectionId = "activity" | "people" | "groups" | "devices" | "account";
44
+
45
+ /** Invite kinds that can filter Activity. */
46
+ export type IdentityInviteType = "contact" | "group" | "device";
47
+
48
+ /** Parsed Identity location, including detail and filter state. */
49
+ export interface IdentityLocation {
50
+ /** Active sidebar section. */
51
+ section: IdentitySectionId;
52
+ /** Canonical path without a query string. */
53
+ pathname: string;
54
+ /** Person id when a contact detail is open. */
55
+ personId?: string;
56
+ /** People action selected by a route. */
57
+ peopleAction?: "invite" | "share";
58
+ /** Group id when a group detail is open. */
59
+ groupId?: string;
60
+ /** True when the group creation panel is open. */
61
+ creatingGroup: boolean;
62
+ /** Device id when a device detail is open. */
63
+ deviceId?: string;
64
+ /** True on the pairing route. */
65
+ pairing: boolean;
66
+ /** True on the paste-or-scan route. */
67
+ accepting: boolean;
68
+ /** Activity list filter from the query string. */
69
+ activityFilter: {
70
+ type?: IdentityInviteType;
71
+ groupId?: string;
72
+ };
73
+ }
74
+
75
+ interface ParsedRoute {
76
+ pathname: string;
77
+ query: URLSearchParams;
78
+ }
79
+
80
+ const IDENTITY_SECTIONS = new Set<IdentitySectionId>([
81
+ "activity",
82
+ "people",
83
+ "groups",
84
+ "devices",
85
+ "account",
86
+ ]);
87
+ const INVITE_TYPES = new Set<IdentityInviteType>(["contact", "group", "device"]);
88
+
89
+ /**
90
+ * Split a hash path into its pathname and query.
91
+ *
92
+ * @param raw - Route with an optional leading `#` or `/` and an optional query.
93
+ */
94
+ export function parseRoute(raw: string | null | undefined): ParsedRoute {
95
+ let trimmed = (raw ?? "").trim();
96
+ if (trimmed.startsWith("/#")) {
97
+ trimmed = trimmed.slice(2);
98
+ } else if (trimmed.startsWith("#")) {
99
+ trimmed = trimmed.slice(1);
100
+ }
101
+ const queryIndex = trimmed.indexOf("?");
102
+ const before = queryIndex >= 0 ? trimmed.slice(0, queryIndex) : trimmed;
103
+ const queryString = queryIndex >= 0 ? trimmed.slice(queryIndex + 1) : "";
104
+ let pathname = before.trim();
105
+ pathname = pathname.replace(/^\/+/, "").replace(/\/+$/, "");
106
+ return { pathname, query: new URLSearchParams(queryString) };
107
+ }
108
+
109
+ /**
110
+ * Rewrite legacy identity aliases to their canonical `identity/*` path.
111
+ *
112
+ * Unrelated routes are returned with only slash cleanup, so other apps keep
113
+ * their existing path casing. `devices?action=pair` becomes the pair route.
114
+ *
115
+ * @param raw - Requested route, possibly a legacy alias.
116
+ * @returns Canonical route, including any query that still applies.
117
+ */
118
+ export function canonicalizeRoute(raw: string | null | undefined): string {
119
+ const { pathname, query } = parseRoute(raw);
120
+ if (!pathname) {
121
+ return "";
122
+ }
123
+ const rewritten = rewritePathname(pathname, query);
124
+ const queryString = query.toString();
125
+ return queryString ? `${rewritten}?${queryString}` : rewritten;
126
+ }
127
+
128
+ /**
129
+ * Whether a route belongs to the Identity app after alias rewrite.
130
+ *
131
+ * @param raw - Route to test.
132
+ */
133
+ export function isIdentityPath(raw: string | null | undefined): boolean {
134
+ const pathname = parseRoute(canonicalizeRoute(raw)).pathname;
135
+ return pathname === IDENTITY_APP_PATH || pathname.startsWith(`${IDENTITY_APP_PATH}/`);
136
+ }
137
+
138
+ /**
139
+ * Sidebar section for an Identity route.
140
+ *
141
+ * @param raw - Identity route or legacy alias.
142
+ * @returns The section, or `undefined` when the route is not Identity.
143
+ */
144
+ export function identitySectionFromPath(
145
+ raw: string | null | undefined,
146
+ ): IdentitySectionId | undefined {
147
+ return parseIdentityLocation(raw)?.section;
148
+ }
149
+
150
+ /**
151
+ * Detail, pairing, accept, and filter state for an Identity route.
152
+ *
153
+ * @param raw - Identity route or legacy alias.
154
+ * @returns Parsed location, or `undefined` when the route is not Identity.
155
+ */
156
+ export function parseIdentityLocation(
157
+ raw: string | null | undefined,
158
+ ): IdentityLocation | undefined {
159
+ const canonical = canonicalizeRoute(raw);
160
+ const { pathname, query } = parseRoute(canonical);
161
+ const parts = pathname.split("/").filter(Boolean);
162
+ if (parts[0] !== IDENTITY_APP_PATH) {
163
+ return undefined;
164
+ }
165
+ const section = IDENTITY_SECTIONS.has(parts[1] as IdentitySectionId)
166
+ ? (parts[1] as IdentitySectionId)
167
+ : "activity";
168
+ const rest = parts.slice(2);
169
+ const pairing = section === "devices" && rest[0] === "pair";
170
+ const accepting = section === "activity" && rest[0] === "accept";
171
+ const peopleAction =
172
+ section === "people" && (rest[0] === "invite" || rest[0] === "share") ? rest[0] : undefined;
173
+ const creatingGroup = section === "groups" && rest[0] === "new";
174
+ const detailId =
175
+ rest[0] &&
176
+ rest[0] !== "pair" &&
177
+ rest[0] !== "accept" &&
178
+ rest[0] !== "invite" &&
179
+ rest[0] !== "share" &&
180
+ rest[0] !== "new"
181
+ ? rest[0]
182
+ : undefined;
183
+ const type = query.get("type");
184
+ return {
185
+ section,
186
+ pathname,
187
+ personId: section === "people" ? detailId : undefined,
188
+ peopleAction,
189
+ groupId: section === "groups" ? detailId : undefined,
190
+ creatingGroup,
191
+ deviceId: section === "devices" && !pairing ? detailId : undefined,
192
+ pairing,
193
+ accepting,
194
+ activityFilter: {
195
+ type:
196
+ type && INVITE_TYPES.has(type as IdentityInviteType)
197
+ ? (type as IdentityInviteType)
198
+ : undefined,
199
+ groupId: query.get("groupId") || undefined,
200
+ },
201
+ };
202
+ }
203
+
204
+ /**
205
+ * Activity route that shows one invite type, optionally one group.
206
+ *
207
+ * @param type - Invite type to show.
208
+ * @param groupId - Group to limit the list to.
209
+ */
210
+ export function identityActivityFilterPath(type: IdentityInviteType, groupId?: string): string {
211
+ const query = new URLSearchParams();
212
+ query.set("type", type);
213
+ if (groupId) {
214
+ query.set("groupId", groupId);
215
+ }
216
+ return `${IDENTITY_ACTIVITY_PATH}?${query.toString()}`;
217
+ }
218
+
219
+ function rewritePathname(pathname: string, query: URLSearchParams): string {
220
+ const parts = pathname.split("/").filter(Boolean);
221
+ const root = parts[0]?.toLowerCase() ?? "";
222
+ let rewritten: string[] | undefined;
223
+ if (root === "identity") {
224
+ rewritten = rewriteIdentity(parts.slice(1));
225
+ } else if (root === "contacts") {
226
+ rewritten = ["identity", "people", ...singleId(parts.slice(1))];
227
+ } else if (root === "groups") {
228
+ rewritten = ["identity", "groups", ...singleId(parts.slice(1))];
229
+ } else if (root === "devices") {
230
+ rewritten = rewriteDevices(parts.slice(1));
231
+ } else if (root === "invites") {
232
+ rewritten =
233
+ parts[1]?.toLowerCase() === "accept"
234
+ ? ["identity", "activity", "accept"]
235
+ : ["identity", "activity"];
236
+ } else if (root === "account") {
237
+ rewritten = ["identity", "account"];
238
+ }
239
+
240
+ if (!rewritten) {
241
+ return pathname;
242
+ }
243
+
244
+ if (rewritten.join("/") === IDENTITY_DEVICES_PATH && query.get("action") === "pair") {
245
+ query.delete("action");
246
+ rewritten = ["identity", "devices", "pair"];
247
+ }
248
+ return rewritten.join("/");
249
+ }
250
+
251
+ function rewriteIdentity(rest: string[]): string[] {
252
+ const section = rest[0]?.toLowerCase();
253
+ if (section === "people") {
254
+ return ["identity", "people", ...rewritePeople(rest.slice(1))];
255
+ }
256
+ if (section === "groups") {
257
+ return ["identity", "groups", ...rewriteGroups(rest.slice(1))];
258
+ }
259
+ if (section === "devices") {
260
+ return rewriteDevices(rest.slice(1));
261
+ }
262
+ if (section === "activity") {
263
+ return rest[1]?.toLowerCase() === "accept"
264
+ ? ["identity", "activity", "accept"]
265
+ : ["identity", "activity"];
266
+ }
267
+ if (section === "account") {
268
+ return ["identity", "account"];
269
+ }
270
+ return ["identity", "activity"];
271
+ }
272
+
273
+ function rewritePeople(rest: string[]): string[] {
274
+ const head = rest[0]?.toLowerCase();
275
+ if (head === "invite" || head === "share") {
276
+ return [head];
277
+ }
278
+ return singleId(rest);
279
+ }
280
+
281
+ function rewriteGroups(rest: string[]): string[] {
282
+ if (rest[0]?.toLowerCase() === "new") {
283
+ return ["new"];
284
+ }
285
+ return singleId(rest);
286
+ }
287
+
288
+ function rewriteDevices(rest: string[]): string[] {
289
+ const head = rest[0]?.toLowerCase();
290
+ if (!head) {
291
+ return ["identity", "devices"];
292
+ }
293
+ if (head === "pair") {
294
+ return ["identity", "devices", "pair"];
295
+ }
296
+ return ["identity", "devices", rest[0]];
297
+ }
298
+
299
+ function singleId(rest: string[]): string[] {
300
+ return rest[0] ? [rest[0]] : [];
301
+ }
@@ -0,0 +1,138 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { isDesktop, mainContentPath } from "../../globals";
4
+ import { IdentityScreen } from "./identity-screen";
5
+
6
+ jest.mock("../../globals", () => {
7
+ const { observable } =
8
+ jest.requireActual<typeof import("@peers-app/peers-sdk")>("@peers-app/peers-sdk");
9
+ return {
10
+ isDesktop: observable(true),
11
+ mainContentPath: observable("identity/activity"),
12
+ };
13
+ });
14
+
15
+ jest.mock("../../ui-router/ui-loader", () => ({
16
+ registerInternalPeersUI: jest.fn(),
17
+ }));
18
+
19
+ jest.mock("../contacts/contact-list", () => ({
20
+ ContactList: () => <div>People view</div>,
21
+ }));
22
+
23
+ jest.mock("../contacts/contact-details", () => ({
24
+ ContactDetails: ({ userId }: { userId: string }) => <div>Person {userId}</div>,
25
+ }));
26
+
27
+ jest.mock("../groups/group-list", () => ({
28
+ GroupList: () => <div>Groups view</div>,
29
+ }));
30
+
31
+ jest.mock("../groups/group-details", () => ({
32
+ GroupDetails: ({ groupId }: { groupId: string }) => <div>Group {groupId}</div>,
33
+ }));
34
+
35
+ jest.mock("../devices/devices-list", () => ({
36
+ DevicesSection: ({ mode }: { mode?: string }) => <div>Devices {mode}</div>,
37
+ }));
38
+
39
+ jest.mock("../invites/accept-invite", () => ({
40
+ AcceptInvite: () => <div>Accept invite view</div>,
41
+ }));
42
+
43
+ jest.mock("../invites/activity-view", () => ({
44
+ ActivityView: () => <div>Activity view</div>,
45
+ }));
46
+
47
+ jest.mock("../account/account-screen", () => ({
48
+ AccountScreen: () => <div>Account view</div>,
49
+ }));
50
+
51
+ jest.mock("../invites/pending-invites-list", () => ({
52
+ useInviteRows: () => ({
53
+ rows: [
54
+ {
55
+ inviteId: "inboundcontact0000000001",
56
+ type: "contact",
57
+ status: "pending",
58
+ direction: "in",
59
+ mode: "contact",
60
+ },
61
+ ],
62
+ hasHistory: false,
63
+ }),
64
+ classifyInvite: (row: { direction: string; type: string; status: string }) =>
65
+ row.status === "pending" && row.direction === "in" && row.type === "contact"
66
+ ? "attention"
67
+ : "waiting",
68
+ }));
69
+
70
+ const PERSON_ID = "abcdefghijklmnopqrstuvwxy";
71
+
72
+ describe("IdentityScreen", () => {
73
+ beforeEach(() => {
74
+ isDesktop(true);
75
+ mainContentPath("identity/activity");
76
+ });
77
+
78
+ it("highlights the parent section for a person route and keeps Activity counted", () => {
79
+ render(<IdentityScreen path={`identity/people/${PERSON_ID}`} />);
80
+
81
+ expect(screen.getByRole("button", { name: /People/ })).toHaveAttribute("aria-current", "page");
82
+ expect(screen.getByText(`Person ${PERSON_ID}`)).toBeInTheDocument();
83
+ expect(screen.getByRole("button", { name: /Activity/ })).toHaveTextContent("1");
84
+ });
85
+
86
+ it("renders the accept flow on the activity section", () => {
87
+ render(<IdentityScreen path="invites/accept" />);
88
+
89
+ expect(screen.getByText("Accept invite view")).toBeInTheDocument();
90
+ expect(screen.getByRole("button", { name: /Activity/ })).toHaveAttribute(
91
+ "aria-current",
92
+ "page",
93
+ );
94
+ });
95
+
96
+ it("renders registration on the account section", () => {
97
+ render(<IdentityScreen path="account" />);
98
+
99
+ expect(screen.getByText("Account view")).toBeInTheDocument();
100
+ expect(screen.getByRole("button", { name: /Account/ })).toHaveAttribute("aria-current", "page");
101
+ });
102
+
103
+ it("selects a section through the canonical route", async () => {
104
+ render(<IdentityScreen path="identity/activity" />);
105
+ await userEvent.click(screen.getByRole("button", { name: /Devices/ }));
106
+ expect(mainContentPath()).toBe("identity/devices");
107
+ });
108
+
109
+ it("keeps all desktop quick actions route-backed", () => {
110
+ render(<IdentityScreen path="identity/activity" />);
111
+
112
+ expect(screen.getByRole("link", { name: /Add person/ })).toHaveAttribute(
113
+ "href",
114
+ "#identity/people/invite",
115
+ );
116
+ expect(screen.getByRole("link", { name: /Create group/ })).toHaveAttribute(
117
+ "href",
118
+ "#identity/groups/new",
119
+ );
120
+ expect(screen.getByRole("link", { name: /Add device/ })).toHaveAttribute(
121
+ "href",
122
+ "#identity/devices/pair",
123
+ );
124
+ expect(screen.getByRole("link", { name: /Use invite/ })).toHaveAttribute(
125
+ "href",
126
+ "#identity/activity/accept",
127
+ );
128
+ });
129
+
130
+ it("collapses add actions on a narrow screen", async () => {
131
+ isDesktop(false);
132
+ render(<IdentityScreen path="identity/activity" />);
133
+
134
+ await userEvent.click(screen.getByRole("button", { name: "Add" }));
135
+ expect(screen.getByRole("link", { name: /Add person/ })).toBeInTheDocument();
136
+ expect(screen.getByRole("link", { name: /Create group/ })).toBeInTheDocument();
137
+ });
138
+ });