@rapidmx/web-client 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +192 -88
  2. package/apps/shared/auth/accountUrl.ts +9 -0
  3. package/apps/shared/auth/adminAccess.ts +99 -0
  4. package/apps/shared/components/admin/elevation.ts +61 -0
  5. package/apps/shared/components/admin/layout/AdminShell.tsx +73 -7
  6. package/apps/shared/components/admin/settings/BrandingForm.tsx +2 -1
  7. package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +87 -24
  8. package/apps/shared/components/calendar/layout/CalendarShell.tsx +8 -2
  9. package/apps/shared/components/contacts/ContactsToolbar.tsx +125 -115
  10. package/apps/shared/components/contacts/layout/ContactsShell.tsx +15 -3
  11. package/apps/shared/components/layout/AppShell.tsx +411 -288
  12. package/apps/shared/components/layout/BrandingChrome.tsx +3 -2
  13. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -389
  14. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -126
  15. package/apps/shared/components/layout/UserMenu.tsx +303 -150
  16. package/apps/shared/components/mail/ConversationList.tsx +269 -253
  17. package/apps/shared/components/mail/ConversationThreadPane.tsx +475 -434
  18. package/apps/shared/components/mail/LazyReadingPane.tsx +115 -0
  19. package/apps/shared/components/mail/MailAddress.tsx +88 -0
  20. package/apps/shared/components/mail/MailSelectionBar.tsx +235 -222
  21. package/apps/shared/components/mail/MessageDetailPane.tsx +1458 -1383
  22. package/apps/shared/components/mail/NewMailToasts.tsx +141 -0
  23. package/apps/shared/components/mail/compose/ComposeContext.tsx +279 -160
  24. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -418
  25. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1842 -1700
  26. package/apps/shared/components/mail/compose/ComposeWindowPlaceholder.tsx +111 -0
  27. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -118
  28. package/apps/shared/components/mail/compose/SendFailureAlert.tsx +48 -0
  29. package/apps/shared/components/mail/compose/composePerf.ts +46 -0
  30. package/apps/shared/components/mail/compose/quotedBody.ts +161 -100
  31. package/apps/shared/components/mail/layout/MailShell.tsx +476 -445
  32. package/apps/shared/components/mail/unreadStyle.tsx +75 -0
  33. package/apps/shared/components/settings/layout/SettingsShell.tsx +252 -240
  34. package/apps/shared/components/tasks/layout/TasksShell.tsx +15 -3
  35. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -0
  36. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -0
  37. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -0
  38. package/apps/shared/keyboard/dispatch.ts +124 -0
  39. package/apps/shared/keyboard/format.ts +89 -0
  40. package/apps/shared/keyboard/keymap.ts +114 -0
  41. package/apps/shared/keyboard/match.ts +44 -0
  42. package/apps/shared/keyboard/parse.ts +136 -0
  43. package/apps/shared/keyboard/platform.ts +34 -0
  44. package/apps/shared/keyboard/registry.ts +65 -0
  45. package/apps/shared/keyboard/targets.ts +79 -0
  46. package/apps/shared/keyboard/useShortcut.ts +50 -0
  47. package/apps/shared/keyboard/useShortcutProps.ts +17 -0
  48. package/apps/shared/mail/folderCounts.ts +302 -0
  49. package/apps/shared/mail/listSnapshots.ts +87 -0
  50. package/apps/shared/mail/mergeFirstPage.ts +47 -0
  51. package/apps/shared/mail/messageReadState.ts +85 -0
  52. package/apps/shared/mail/newMailNotifications.ts +183 -0
  53. package/apps/shared/mail/useMailConnection.ts +150 -0
  54. package/apps/shared/mail/useMailLiveUpdates.ts +232 -0
  55. package/apps/shared/mail/useMarkMessageRead.ts +47 -0
  56. package/apps/shared/mail/useNewMailNotifications.ts +163 -0
  57. package/apps/shared/mail/useUnreadTitle.ts +42 -0
  58. package/apps/shared/navigation/AppRouter.tsx +300 -0
  59. package/apps/shared/navigation/appHrefs.ts +23 -0
  60. package/apps/shared/navigation/frameContext.tsx +35 -0
  61. package/apps/shared/navigation/idle.ts +45 -0
  62. package/apps/shared/navigation/routerContext.tsx +83 -0
  63. package/apps/shared/navigation/routes.ts +72 -0
  64. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -98
  65. package/apps/shared/styles/app.css +28 -10
  66. package/apps/www/_routedPage.tsx +24 -0
  67. package/apps/www/_routes.ts +35 -0
  68. package/apps/www/calendar/index.tsx +55 -19
  69. package/apps/www/contacts/[uid].tsx +112 -107
  70. package/apps/www/contacts/index.tsx +584 -567
  71. package/apps/www/index.tsx +2280 -1854
  72. package/apps/www/messages/[uid].tsx +106 -101
  73. package/apps/www/settings/auto-reply/index.tsx +4 -1
  74. package/apps/www/settings/encryption/index.tsx +1252 -1249
  75. package/apps/www/settings/filters/[uid].tsx +4 -1
  76. package/apps/www/settings/filters/index.tsx +102 -99
  77. package/apps/www/settings/filters/new/index.tsx +138 -133
  78. package/apps/www/settings/labels/index.tsx +204 -201
  79. package/apps/www/settings/privacy/index.tsx +4 -1
  80. package/apps/www/settings/read-receipts/index.tsx +4 -1
  81. package/apps/www/settings/sharing/index.tsx +277 -274
  82. package/apps/www/settings/signatures/[uid].tsx +170 -167
  83. package/apps/www/settings/signatures/index.tsx +88 -85
  84. package/apps/www/settings/signatures/new/index.tsx +134 -129
  85. package/apps/www/tasks/index.tsx +18 -2
  86. package/dist/apps/shared/auth/accountUrl.d.ts +2 -0
  87. package/dist/apps/shared/auth/accountUrl.js +8 -0
  88. package/dist/apps/shared/auth/adminAccess.d.ts +30 -0
  89. package/dist/apps/shared/auth/adminAccess.js +89 -0
  90. package/dist/apps/shared/components/admin/elevation.d.ts +24 -0
  91. package/dist/apps/shared/components/admin/elevation.js +56 -0
  92. package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +12 -4
  93. package/dist/apps/shared/components/admin/layout/AdminShell.js +49 -6
  94. package/dist/apps/shared/components/admin/settings/BrandingForm.js +1 -1
  95. package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +31 -13
  96. package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +1 -1
  97. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +8 -4
  98. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
  99. package/dist/apps/shared/components/contacts/ContactsToolbar.js +7 -4
  100. package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +1 -1
  101. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +15 -5
  102. package/dist/apps/shared/components/layout/AppShell.d.ts +29 -4
  103. package/dist/apps/shared/components/layout/AppShell.js +73 -14
  104. package/dist/apps/shared/components/layout/BrandingChrome.d.ts +3 -2
  105. package/dist/apps/shared/components/layout/BrandingChrome.js +3 -2
  106. package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +10 -9
  107. package/dist/apps/shared/components/layout/MailboxProvisioning.d.ts +5 -2
  108. package/dist/apps/shared/components/layout/MailboxProvisioning.js +45 -8
  109. package/dist/apps/shared/components/layout/UserMenu.d.ts +28 -9
  110. package/dist/apps/shared/components/layout/UserMenu.js +87 -14
  111. package/dist/apps/shared/components/mail/ConversationList.js +9 -13
  112. package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +4 -1
  113. package/dist/apps/shared/components/mail/ConversationThreadPane.js +53 -28
  114. package/dist/apps/shared/components/mail/LazyReadingPane.d.ts +9 -0
  115. package/dist/apps/shared/components/mail/LazyReadingPane.js +82 -0
  116. package/dist/apps/shared/components/mail/MailAddress.d.ts +27 -0
  117. package/dist/apps/shared/components/mail/MailAddress.js +39 -0
  118. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +4 -1
  119. package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -3
  120. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +7 -1
  121. package/dist/apps/shared/components/mail/MessageDetailPane.js +87 -36
  122. package/dist/apps/shared/components/mail/NewMailToasts.d.ts +19 -0
  123. package/dist/apps/shared/components/mail/NewMailToasts.js +55 -0
  124. package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +30 -0
  125. package/dist/apps/shared/components/mail/compose/ComposeContext.js +71 -5
  126. package/dist/apps/shared/components/mail/compose/ComposeToolbar.js +4 -3
  127. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +1 -1
  128. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +122 -27
  129. package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.d.ts +19 -0
  130. package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.js +33 -0
  131. package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +9 -1
  132. package/dist/apps/shared/components/mail/compose/RichTextEditor.js +20 -2
  133. package/dist/apps/shared/components/mail/compose/SendFailureAlert.d.ts +14 -0
  134. package/dist/apps/shared/components/mail/compose/SendFailureAlert.js +11 -0
  135. package/dist/apps/shared/components/mail/compose/composePerf.d.ts +16 -0
  136. package/dist/apps/shared/components/mail/compose/composePerf.js +41 -0
  137. package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +13 -0
  138. package/dist/apps/shared/components/mail/compose/quotedBody.js +67 -11
  139. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +19 -4
  140. package/dist/apps/shared/components/mail/layout/MailShell.js +85 -85
  141. package/dist/apps/shared/components/mail/unreadStyle.d.ts +45 -0
  142. package/dist/apps/shared/components/mail/unreadStyle.js +61 -0
  143. package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +1 -1
  144. package/dist/apps/shared/components/settings/layout/SettingsShell.js +15 -5
  145. package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +1 -1
  146. package/dist/apps/shared/components/tasks/layout/TasksShell.js +15 -5
  147. package/dist/apps/shared/keyboard/GlobalShortcuts.d.ts +14 -0
  148. package/dist/apps/shared/keyboard/GlobalShortcuts.js +37 -0
  149. package/dist/apps/shared/keyboard/ShortcutProvider.d.ts +20 -0
  150. package/dist/apps/shared/keyboard/ShortcutProvider.js +52 -0
  151. package/dist/apps/shared/keyboard/ShortcutsDialog.d.ts +14 -0
  152. package/dist/apps/shared/keyboard/ShortcutsDialog.js +42 -0
  153. package/dist/apps/shared/keyboard/dispatch.d.ts +16 -0
  154. package/dist/apps/shared/keyboard/dispatch.js +109 -0
  155. package/dist/apps/shared/keyboard/format.d.ts +12 -0
  156. package/dist/apps/shared/keyboard/format.js +74 -0
  157. package/dist/apps/shared/keyboard/keymap.d.ts +294 -0
  158. package/dist/apps/shared/keyboard/keymap.js +84 -0
  159. package/dist/apps/shared/keyboard/match.d.ts +20 -0
  160. package/dist/apps/shared/keyboard/match.js +31 -0
  161. package/dist/apps/shared/keyboard/parse.d.ts +31 -0
  162. package/dist/apps/shared/keyboard/parse.js +107 -0
  163. package/dist/apps/shared/keyboard/platform.d.ts +15 -0
  164. package/dist/apps/shared/keyboard/platform.js +22 -0
  165. package/dist/apps/shared/keyboard/registry.d.ts +39 -0
  166. package/dist/apps/shared/keyboard/registry.js +33 -0
  167. package/dist/apps/shared/keyboard/targets.d.ts +14 -0
  168. package/dist/apps/shared/keyboard/targets.js +67 -0
  169. package/dist/apps/shared/keyboard/useShortcut.d.ts +19 -0
  170. package/dist/apps/shared/keyboard/useShortcut.js +35 -0
  171. package/dist/apps/shared/keyboard/useShortcutProps.d.ts +10 -0
  172. package/dist/apps/shared/keyboard/useShortcutProps.js +15 -0
  173. package/dist/apps/shared/mail/folderCounts.d.ts +78 -0
  174. package/dist/apps/shared/mail/folderCounts.js +212 -0
  175. package/dist/apps/shared/mail/listSnapshots.d.ts +46 -0
  176. package/dist/apps/shared/mail/listSnapshots.js +43 -0
  177. package/dist/apps/shared/mail/mergeFirstPage.d.ts +23 -0
  178. package/dist/apps/shared/mail/mergeFirstPage.js +30 -0
  179. package/dist/apps/shared/mail/messageReadState.d.ts +32 -0
  180. package/dist/apps/shared/mail/messageReadState.js +63 -0
  181. package/dist/apps/shared/mail/newMailNotifications.d.ts +62 -0
  182. package/dist/apps/shared/mail/newMailNotifications.js +138 -0
  183. package/dist/apps/shared/mail/useMailConnection.d.ts +55 -0
  184. package/dist/apps/shared/mail/useMailConnection.js +96 -0
  185. package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +55 -0
  186. package/dist/apps/shared/mail/useMailLiveUpdates.js +182 -0
  187. package/dist/apps/shared/mail/useMarkMessageRead.d.ts +12 -0
  188. package/dist/apps/shared/mail/useMarkMessageRead.js +44 -0
  189. package/dist/apps/shared/mail/useNewMailNotifications.d.ts +41 -0
  190. package/dist/apps/shared/mail/useNewMailNotifications.js +110 -0
  191. package/dist/apps/shared/mail/useUnreadTitle.d.ts +18 -0
  192. package/dist/apps/shared/mail/useUnreadTitle.js +31 -0
  193. package/dist/apps/shared/navigation/AppRouter.d.ts +52 -0
  194. package/dist/apps/shared/navigation/AppRouter.js +242 -0
  195. package/dist/apps/shared/navigation/appHrefs.d.ts +14 -0
  196. package/dist/apps/shared/navigation/appHrefs.js +20 -0
  197. package/dist/apps/shared/navigation/frameContext.d.ts +19 -0
  198. package/dist/apps/shared/navigation/frameContext.js +24 -0
  199. package/dist/apps/shared/navigation/idle.d.ts +14 -0
  200. package/dist/apps/shared/navigation/idle.js +43 -0
  201. package/dist/apps/shared/navigation/routerContext.d.ts +37 -0
  202. package/dist/apps/shared/navigation/routerContext.js +56 -0
  203. package/dist/apps/shared/navigation/routes.d.ts +32 -0
  204. package/dist/apps/shared/navigation/routes.js +37 -0
  205. package/dist/apps/shared/search/LocalIndexLifecycle.js +17 -3
  206. package/dist/apps/shared/styles/app.css +28 -10
  207. package/dist/apps/www/_routedPage.d.ts +12 -0
  208. package/dist/apps/www/_routedPage.js +19 -0
  209. package/dist/apps/www/_routes.d.ts +11 -0
  210. package/dist/apps/www/_routes.js +29 -0
  211. package/dist/apps/www/calendar/index.d.ts +2 -2
  212. package/dist/apps/www/calendar/index.js +39 -8
  213. package/dist/apps/www/contacts/[uid].d.ts +3 -9
  214. package/dist/apps/www/contacts/[uid].js +6 -2
  215. package/dist/apps/www/contacts/index.d.ts +2 -2
  216. package/dist/apps/www/contacts/index.js +17 -4
  217. package/dist/apps/www/index.d.ts +2 -2
  218. package/dist/apps/www/index.js +361 -34
  219. package/dist/apps/www/messages/[uid].d.ts +3 -7
  220. package/dist/apps/www/messages/[uid].js +7 -4
  221. package/dist/apps/www/settings/auto-reply/index.d.ts +2 -2
  222. package/dist/apps/www/settings/auto-reply/index.js +3 -1
  223. package/dist/apps/www/settings/encryption/index.d.ts +2 -2
  224. package/dist/apps/www/settings/encryption/index.js +3 -1
  225. package/dist/apps/www/settings/filters/[uid].d.ts +2 -2
  226. package/dist/apps/www/settings/filters/[uid].js +3 -1
  227. package/dist/apps/www/settings/filters/index.d.ts +2 -2
  228. package/dist/apps/www/settings/filters/index.js +3 -1
  229. package/dist/apps/www/settings/filters/new/index.d.ts +2 -2
  230. package/dist/apps/www/settings/filters/new/index.js +6 -2
  231. package/dist/apps/www/settings/labels/index.d.ts +2 -2
  232. package/dist/apps/www/settings/labels/index.js +3 -1
  233. package/dist/apps/www/settings/privacy/index.d.ts +2 -2
  234. package/dist/apps/www/settings/privacy/index.js +3 -1
  235. package/dist/apps/www/settings/read-receipts/index.d.ts +2 -2
  236. package/dist/apps/www/settings/read-receipts/index.js +3 -1
  237. package/dist/apps/www/settings/sharing/index.d.ts +2 -2
  238. package/dist/apps/www/settings/sharing/index.js +3 -1
  239. package/dist/apps/www/settings/signatures/[uid].d.ts +2 -2
  240. package/dist/apps/www/settings/signatures/[uid].js +3 -1
  241. package/dist/apps/www/settings/signatures/index.d.ts +2 -2
  242. package/dist/apps/www/settings/signatures/index.js +3 -1
  243. package/dist/apps/www/settings/signatures/new/index.d.ts +2 -2
  244. package/dist/apps/www/settings/signatures/new/index.js +6 -2
  245. package/dist/apps/www/tasks/index.d.ts +2 -2
  246. package/dist/apps/www/tasks/index.js +15 -3
  247. package/package.json +2 -2
@@ -1,253 +1,269 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import React, { useState } from "react";
6
- import { HiChevronDown, HiChevronRight, HiOutlineFlag, HiOutlinePaperClip } from "react-icons/hi2";
7
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
8
- import { Message } from "@rapidmx/react-shared/mail/mailApi.js";
9
- import { ConversationSummary, listConversationMessages } from "@rapidmx/react-shared/mail/conversationsApi.js";
10
-
11
- export interface ConversationListProps {
12
- conversations: ConversationSummary[];
13
- /** The mailbox the conversations were listed from - `listConversationMessages()` is mailbox-scoped. */
14
- mailboxUid: string;
15
- /** The message currently open in the reading pane, so the row standing for it can be marked. */
16
- selectedUid: string | null;
17
- /**
18
- * Opens a conversation in the reading pane, positioned at one of its messages: the one a child row
19
- * stands for, or the conversation's own `latestMessageUid` for a parent row. The conversation goes
20
- * with the uid because the pane shows the whole thread, not just that message.
21
- */
22
- onOpenMessage: (conversation: ConversationSummary, uid: string) => void;
23
- /** Newer copies of messages this list already fetched - the reading pane marks the message it opens as
24
- * read, which this list would otherwise keep showing as unread until the thread is collapsed and
25
- * expanded again. */
26
- messageOverrides?: Record<string, Message>;
27
- /** Turns each parent row into a checkbox row: select mode here ticks whole conversations, since a
28
- * conversation is what this list's rows are. A child row stays a plain "open this message" button - a
29
- * mixed conversation/message selection has no sensible bulk semantics (see `MailListToolbar`). */
30
- selectMode?: boolean;
31
- /** The `conversationId`s currently ticked. */
32
- selectedConversationIds?: Set<string>;
33
- onToggleSelected?: (conversation: ConversationSummary) => void;
34
- /**
35
- * Whether a conversation's own messages read newest first, matching the order sense the rows themselves
36
- * are in ("Newest on top"). `listConversationMessages()` always answers oldest first - the order a
37
- * thread is read in - so this reverses that copy for display rather than asking for it differently.
38
- */
39
- newestFirst?: boolean;
40
- }
41
-
42
- function participantNames(conversation: ConversationSummary): string {
43
- return conversation.participants.map((participant) => participant.displayName || participant.address).join(", ");
44
- }
45
-
46
- /**
47
- * The nested, Outlook-style conversation list: one parent row per conversation - its participants, subject,
48
- * message count, unread count, flag/attachment hints and the latest message's preview - expanding via its
49
- * own chevron into the conversation's individual messages as child rows, fetched on first expand with
50
- * `listConversationMessages()` (one request for the whole thread, across folders, oldest first).
51
- *
52
- * Opening a row opens the whole conversation in `ConversationThreadPane`, positioned at the message the row
53
- * stands for: the latest one for a parent row, that one for a child row.
54
- *
55
- * The chevron is a button of its own beside the row's own button rather than inside it (a button can't
56
- * nest inside a button), so expanding and opening are separately reachable by keyboard and each carries
57
- * its own name.
58
- */
59
- export default function ConversationList({
60
- conversations,
61
- mailboxUid,
62
- selectedUid,
63
- onOpenMessage,
64
- messageOverrides,
65
- selectMode,
66
- selectedConversationIds,
67
- onToggleSelected,
68
- newestFirst,
69
- }: ConversationListProps) {
70
- const [expanded, setExpanded] = useState<Set<string>>(new Set());
71
- const [messagesById, setMessagesById] = useState<Record<string, Message[]>>({});
72
- const [loadingIds, setLoadingIds] = useState<Set<string>>(new Set());
73
- const [errorsById, setErrorsById] = useState<Record<string, string>>({});
74
-
75
- function toggle(conversation: ConversationSummary) {
76
- const id = conversation.conversationId;
77
- setExpanded((prev) => {
78
- const next = new Set(prev);
79
- if (next.has(id)) {
80
- next.delete(id);
81
- } else {
82
- next.add(id);
83
- }
84
- return next;
85
- });
86
- if (expanded.has(id) || messagesById[id] || loadingIds.has(id)) {
87
- return;
88
- }
89
- setLoadingIds((prev) => new Set(prev).add(id));
90
- setErrorsById((prev) => {
91
- const next = { ...prev };
92
- delete next[id];
93
- return next;
94
- });
95
- listConversationMessages(mailboxUid, id)
96
- .then((loaded) => setMessagesById((prev) => ({ ...prev, [id]: loaded })))
97
- .catch((err) =>
98
- setErrorsById((prev) => ({
99
- ...prev,
100
- [id]: err instanceof ApiRequestError ? err.message : "Could not load this conversation's messages.",
101
- }))
102
- )
103
- .finally(() =>
104
- setLoadingIds((prev) => {
105
- const next = new Set(prev);
106
- next.delete(id);
107
- return next;
108
- })
109
- );
110
- }
111
-
112
- if (conversations.length === 0) {
113
- return <p className="p-4 text-sm text-text-muted">No conversations in this folder.</p>;
114
- }
115
-
116
- return (
117
- <ul>
118
- {conversations.map((conversation) => {
119
- const id = conversation.conversationId;
120
- const isExpanded = expanded.has(id);
121
- const unread = conversation.unreadCount > 0;
122
- const loaded = messagesById[id];
123
- // `listConversationMessages()` answers oldest first; the rows read in whichever sense the
124
- // list itself is arranged in. Copied before reversing - the fetched array is cached.
125
- const children = loaded && newestFirst ? [...loaded].reverse() : loaded;
126
- const panelId = `conversation-messages-${id}`;
127
- const ticked = selectedConversationIds?.has(id) ?? false;
128
- return (
129
- <li key={id}>
130
- <div
131
- className={[
132
- "flex items-stretch border-b border-border",
133
- conversation.latestMessageUid === selectedUid || ticked
134
- ? "bg-primary/10"
135
- : "hover:bg-surface-alt",
136
- ].join(" ")}
137
- >
138
- {selectMode && (
139
- <span className="shrink-0 flex items-center pl-3">
140
- <input
141
- type="checkbox"
142
- checked={ticked}
143
- onChange={() => onToggleSelected?.(conversation)}
144
- aria-label={`Select conversation: ${conversation.subject || "(no subject)"}`}
145
- className="w-4 h-4 accent-primary"
146
- />
147
- </span>
148
- )}
149
- <button
150
- type="button"
151
- onClick={() => toggle(conversation)}
152
- aria-expanded={isExpanded}
153
- aria-controls={panelId}
154
- aria-label={`${isExpanded ? "Collapse" : "Expand"} conversation: ${conversation.subject || "(no subject)"}`}
155
- className="shrink-0 px-2 text-text-muted hover:text-text"
156
- >
157
- {isExpanded ? (
158
- <HiChevronDown size={16} aria-hidden="true" />
159
- ) : (
160
- <HiChevronRight size={16} aria-hidden="true" />
161
- )}
162
- </button>
163
- <button
164
- type="button"
165
- onClick={() => onOpenMessage(conversation, conversation.latestMessageUid)}
166
- className={["flex-1 min-w-0 text-left pr-4 py-3", unread ? "font-semibold" : ""].join(
167
- " "
168
- )}
169
- >
170
- <div className="flex items-center justify-between gap-2 text-sm">
171
- <span className="truncate">{participantNames(conversation)}</span>
172
- <span className="text-xs text-text-muted shrink-0">
173
- {new Date(conversation.latestDate).toLocaleDateString()}
174
- </span>
175
- </div>
176
- <div className="text-sm truncate">{conversation.subject || "(no subject)"}</div>
177
- <div className="text-xs text-text-muted truncate font-normal">
178
- {conversation.latestPreview}
179
- </div>
180
- <div className="flex items-center gap-2 mt-1 text-xs text-text-muted font-normal">
181
- {conversation.messageCount > 1 && <span>{conversation.messageCount} messages</span>}
182
- {/* A one-message conversation's unread state is already the row's own
183
- bolding - counting it "1 unread" on every such row is just noise. */}
184
- {unread && conversation.messageCount > 1 && (
185
- <span className="py-0.5 px-2 rounded-pill bg-primary/10 text-primary-dark font-semibold">
186
- {conversation.unreadCount} unread
187
- </span>
188
- )}
189
- {conversation.hasAttachments && (
190
- <HiOutlinePaperClip size={13} aria-label="Has attachments" />
191
- )}
192
- {conversation.flagged && (
193
- <HiOutlineFlag size={13} aria-label="Flagged" className="text-danger" />
194
- )}
195
- </div>
196
- </button>
197
- </div>
198
- <ul id={panelId} hidden={!isExpanded}>
199
- {errorsById[id] && (
200
- <li role="alert" className="pl-8 pr-4 py-2 text-xs text-danger border-b border-border">
201
- {errorsById[id]}
202
- </li>
203
- )}
204
- {loadingIds.has(id) && (
205
- <li className="pl-8 pr-4 py-2 text-xs text-text-muted border-b border-border">
206
- Loading messages&hellip;
207
- </li>
208
- )}
209
- {children?.map((fetched) => {
210
- const message = messageOverrides?.[fetched.uid] ?? fetched;
211
- return (
212
- <li key={message.uid}>
213
- <button
214
- type="button"
215
- onClick={() => onOpenMessage(conversation, message.uid)}
216
- className={[
217
- "w-full text-left pl-8 pr-4 py-2 border-b border-border",
218
- message.uid === selectedUid ? "bg-primary/10" : "hover:bg-surface-alt",
219
- message.flags.read ? "" : "font-semibold",
220
- ].join(" ")}
221
- >
222
- <div className="flex items-center justify-between gap-2 text-sm">
223
- <span className="truncate">
224
- {message.from.displayName || message.from.address}
225
- </span>
226
- <span className="text-xs text-text-muted shrink-0">
227
- {new Date(message.receivedDate).toLocaleDateString()}
228
- </span>
229
- </div>
230
- <div className="flex items-center gap-2 text-xs text-text-muted font-normal">
231
- <span className="truncate">{message.bodyPreview}</span>
232
- {message.hasAttachments && (
233
- <HiOutlinePaperClip size={12} aria-label="Has attachments" />
234
- )}
235
- {message.flags.flagged && (
236
- <HiOutlineFlag
237
- size={12}
238
- aria-label="Flagged"
239
- className="text-danger"
240
- />
241
- )}
242
- </div>
243
- </button>
244
- </li>
245
- );
246
- })}
247
- </ul>
248
- </li>
249
- );
250
- })}
251
- </ul>
252
- );
253
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { useState } from "react";
6
+ import { HiChevronDown, HiChevronRight, HiOutlineFlag, HiOutlinePaperClip } from "react-icons/hi2";
7
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
8
+ import { Message } from "@rapidmx/react-shared/mail/mailApi.js";
9
+ import { formatMailAddress } from "@rapidmx/react-shared/mail/mailAddress.js";
10
+ import MailAddress from "./MailAddress.js";
11
+ import { ConversationSummary, listConversationMessages } from "@rapidmx/react-shared/mail/conversationsApi.js";
12
+ import { ROW_FOCUS_CLASS, UnreadBar, UnreadLabel, dateClass, isUnread, rowClass, senderClass, subjectClass } from "./unreadStyle.js";
13
+
14
+ export interface ConversationListProps {
15
+ conversations: ConversationSummary[];
16
+ /** The mailbox the conversations were listed from - `listConversationMessages()` is mailbox-scoped. */
17
+ mailboxUid: string;
18
+ /** The message currently open in the reading pane, so the row standing for it can be marked. */
19
+ selectedUid: string | null;
20
+ /**
21
+ * Opens a conversation in the reading pane, positioned at one of its messages: the one a child row
22
+ * stands for, or the conversation's own `latestMessageUid` for a parent row. The conversation goes
23
+ * with the uid because the pane shows the whole thread, not just that message.
24
+ */
25
+ onOpenMessage: (conversation: ConversationSummary, uid: string) => void;
26
+ /** Newer copies of messages this list already fetched - the reading pane marks the message it opens as
27
+ * read, which this list would otherwise keep showing as unread until the thread is collapsed and
28
+ * expanded again. */
29
+ messageOverrides?: Record<string, Message>;
30
+ /** Turns each parent row into a checkbox row: select mode here ticks whole conversations, since a
31
+ * conversation is what this list's rows are. A child row stays a plain "open this message" button - a
32
+ * mixed conversation/message selection has no sensible bulk semantics (see `MailListToolbar`). */
33
+ selectMode?: boolean;
34
+ /** The `conversationId`s currently ticked. */
35
+ selectedConversationIds?: Set<string>;
36
+ onToggleSelected?: (conversation: ConversationSummary) => void;
37
+ /**
38
+ * Whether a conversation's own messages read newest first, matching the order sense the rows themselves
39
+ * are in ("Newest on top"). `listConversationMessages()` always answers oldest first - the order a
40
+ * thread is read in - so this reverses that copy for display rather than asking for it differently.
41
+ */
42
+ newestFirst?: boolean;
43
+ }
44
+
45
+ /** Every participant as `Name <address>`, for the tooltip and the accessible text of the "+N" a crowded row folds them into. */
46
+ function participantList(conversation: ConversationSummary): string {
47
+ return conversation.participants.map((participant) => formatMailAddress(participant)).join(", ");
48
+ }
49
+
50
+ /**
51
+ * The nested, Outlook-style conversation list: one parent row per conversation - its participants, subject,
52
+ * message count, unread count, flag/attachment hints and the latest message's preview - expanding via its
53
+ * own chevron into the conversation's individual messages as child rows, fetched on first expand with
54
+ * `listConversationMessages()` (one request for the whole thread, across folders, oldest first).
55
+ *
56
+ * Opening a row opens the whole conversation in `ConversationThreadPane`, positioned at the message the row
57
+ * stands for: the latest one for a parent row, that one for a child row.
58
+ *
59
+ * The chevron is a button of its own beside the row's own button rather than inside it (a button can't
60
+ * nest inside a button), so expanding and opening are separately reachable by keyboard and each carries
61
+ * its own name.
62
+ */
63
+ export default function ConversationList({
64
+ conversations,
65
+ mailboxUid,
66
+ selectedUid,
67
+ onOpenMessage,
68
+ messageOverrides,
69
+ selectMode,
70
+ selectedConversationIds,
71
+ onToggleSelected,
72
+ newestFirst,
73
+ }: ConversationListProps) {
74
+ const [expanded, setExpanded] = useState<Set<string>>(new Set());
75
+ const [messagesById, setMessagesById] = useState<Record<string, Message[]>>({});
76
+ const [loadingIds, setLoadingIds] = useState<Set<string>>(new Set());
77
+ const [errorsById, setErrorsById] = useState<Record<string, string>>({});
78
+
79
+ function toggle(conversation: ConversationSummary) {
80
+ const id = conversation.conversationId;
81
+ setExpanded((prev) => {
82
+ const next = new Set(prev);
83
+ if (next.has(id)) {
84
+ next.delete(id);
85
+ } else {
86
+ next.add(id);
87
+ }
88
+ return next;
89
+ });
90
+ if (expanded.has(id) || messagesById[id] || loadingIds.has(id)) {
91
+ return;
92
+ }
93
+ setLoadingIds((prev) => new Set(prev).add(id));
94
+ setErrorsById((prev) => {
95
+ const next = { ...prev };
96
+ delete next[id];
97
+ return next;
98
+ });
99
+ listConversationMessages(mailboxUid, id)
100
+ .then((loaded) => setMessagesById((prev) => ({ ...prev, [id]: loaded })))
101
+ .catch((err) =>
102
+ setErrorsById((prev) => ({
103
+ ...prev,
104
+ [id]: err instanceof ApiRequestError ? err.message : "Could not load this conversation's messages.",
105
+ }))
106
+ )
107
+ .finally(() =>
108
+ setLoadingIds((prev) => {
109
+ const next = new Set(prev);
110
+ next.delete(id);
111
+ return next;
112
+ })
113
+ );
114
+ }
115
+
116
+ if (conversations.length === 0) {
117
+ return <p className="p-4 text-sm text-text-muted">No conversations in this folder.</p>;
118
+ }
119
+
120
+ return (
121
+ <ul>
122
+ {conversations.map((conversation) => {
123
+ const id = conversation.conversationId;
124
+ const isExpanded = expanded.has(id);
125
+ const unread = conversation.unreadCount > 0;
126
+ const loaded = messagesById[id];
127
+ // `listConversationMessages()` answers oldest first; the rows read in whichever sense the
128
+ // list itself is arranged in. Copied before reversing - the fetched array is cached.
129
+ const children = loaded && newestFirst ? [...loaded].reverse() : loaded;
130
+ const panelId = `conversation-messages-${id}`;
131
+ const ticked = selectedConversationIds?.has(id) ?? false;
132
+ return (
133
+ <li key={id}>
134
+ <div
135
+ data-message-uid={conversation.latestMessageUid}
136
+ data-unread={unread ? "true" : undefined}
137
+ className={rowClass({ unread, selected: conversation.latestMessageUid === selectedUid || ticked }, "flex items-stretch")}
138
+ >
139
+ <UnreadBar unread={unread} />
140
+ {selectMode && (
141
+ <span className="shrink-0 flex items-center pl-3">
142
+ <input
143
+ type="checkbox"
144
+ checked={ticked}
145
+ onChange={() => onToggleSelected?.(conversation)}
146
+ aria-label={`Select conversation: ${conversation.subject || "(no subject)"}`}
147
+ className="w-4 h-4 accent-primary"
148
+ />
149
+ </span>
150
+ )}
151
+ <button
152
+ type="button"
153
+ onClick={() => toggle(conversation)}
154
+ aria-expanded={isExpanded}
155
+ aria-controls={panelId}
156
+ aria-label={`${isExpanded ? "Collapse" : "Expand"} conversation: ${conversation.subject || "(no subject)"}`}
157
+ className={["shrink-0 px-2 text-text-muted hover:text-text", ROW_FOCUS_CLASS].join(" ")}
158
+ >
159
+ {isExpanded ? (
160
+ <HiChevronDown size={16} aria-hidden="true" />
161
+ ) : (
162
+ <HiChevronRight size={16} aria-hidden="true" />
163
+ )}
164
+ </button>
165
+ <button
166
+ type="button"
167
+ data-row-open
168
+ onClick={() => onOpenMessage(conversation, conversation.latestMessageUid)}
169
+ className={["flex-1 min-w-0 text-left pr-4 py-3", ROW_FOCUS_CLASS].join(" ")}
170
+ >
171
+ <UnreadLabel unread={unread} />
172
+ <div className="flex items-center justify-between gap-2 text-sm">
173
+ {/* The first participant in full - name and address - and the rest as a count, with everyone's
174
+ address in its tooltip; the latest sender when the summary lists none. */}
175
+ <MailAddress
176
+ recipient={conversation.participants[0] ?? conversation.latestFrom}
177
+ className={["flex-1", senderClass(unread)].join(" ")}
178
+ />
179
+ {conversation.participants.length > 1 && (
180
+ <span className="text-xs text-text-muted shrink-0 font-normal" title={participantList(conversation)}>
181
+ +{conversation.participants.length - 1}
182
+ <span className="sr-only"> more: {participantList(conversation)}</span>
183
+ </span>
184
+ )}
185
+ <span className={["text-xs shrink-0", dateClass(unread)].join(" ")}>
186
+ {new Date(conversation.latestDate).toLocaleDateString()}
187
+ </span>
188
+ </div>
189
+ <div className={["text-sm truncate", subjectClass(unread)].join(" ")}>{conversation.subject || "(no subject)"}</div>
190
+ <div className="text-xs text-text-muted truncate font-normal">
191
+ {conversation.latestPreview}
192
+ </div>
193
+ <div className="flex items-center gap-2 mt-1 text-xs text-text-muted font-normal">
194
+ {conversation.messageCount > 1 && <span>{conversation.messageCount} messages</span>}
195
+ {/* A one-message conversation's unread state is already the row's own
196
+ bolding - counting it "1 unread" on every such row is just noise. */}
197
+ {unread && conversation.messageCount > 1 && (
198
+ <span className="py-0.5 px-2 rounded-pill bg-primary/15 text-primary-dark font-bold">
199
+ {conversation.unreadCount} unread
200
+ </span>
201
+ )}
202
+ {conversation.hasAttachments && (
203
+ <HiOutlinePaperClip size={13} aria-label="Has attachments" />
204
+ )}
205
+ {conversation.flagged && (
206
+ <HiOutlineFlag size={13} aria-label="Flagged" className="text-danger" />
207
+ )}
208
+ </div>
209
+ </button>
210
+ </div>
211
+ <ul id={panelId} hidden={!isExpanded}>
212
+ {errorsById[id] && (
213
+ <li role="alert" className="pl-8 pr-4 py-2 text-xs text-danger border-b border-border">
214
+ {errorsById[id]}
215
+ </li>
216
+ )}
217
+ {loadingIds.has(id) && (
218
+ <li className="pl-8 pr-4 py-2 text-xs text-text-muted border-b border-border">
219
+ Loading messages&hellip;
220
+ </li>
221
+ )}
222
+ {children?.map((fetched) => {
223
+ const message = messageOverrides?.[fetched.uid] ?? fetched;
224
+ const messageUnread = isUnread(message);
225
+ return (
226
+ <li
227
+ key={message.uid}
228
+ data-message-uid={message.uid}
229
+ data-unread={messageUnread ? "true" : undefined}
230
+ className={rowClass({ unread: messageUnread, selected: message.uid === selectedUid })}
231
+ >
232
+ <UnreadBar unread={messageUnread} />
233
+ <button
234
+ type="button"
235
+ data-row-open
236
+ onClick={() => onOpenMessage(conversation, message.uid)}
237
+ className={["w-full text-left pl-8 pr-4 py-2", ROW_FOCUS_CLASS].join(" ")}
238
+ >
239
+ <UnreadLabel unread={messageUnread} />
240
+ <div className="flex items-center justify-between gap-2 text-sm">
241
+ <MailAddress recipient={message.from} className={senderClass(messageUnread)} />
242
+ <span className={["text-xs shrink-0", dateClass(messageUnread)].join(" ")}>
243
+ {new Date(message.receivedDate).toLocaleDateString()}
244
+ </span>
245
+ </div>
246
+ <div className="flex items-center gap-2 text-xs text-text-muted font-normal">
247
+ <span className="truncate">{message.bodyPreview}</span>
248
+ {message.hasAttachments && (
249
+ <HiOutlinePaperClip size={12} aria-label="Has attachments" />
250
+ )}
251
+ {message.flags.flagged && (
252
+ <HiOutlineFlag
253
+ size={12}
254
+ aria-label="Flagged"
255
+ className="text-danger"
256
+ />
257
+ )}
258
+ </div>
259
+ </button>
260
+ </li>
261
+ );
262
+ })}
263
+ </ul>
264
+ </li>
265
+ );
266
+ })}
267
+ </ul>
268
+ );
269
+ }