@rapidmx/web-client 0.5.0 → 0.7.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 (224) hide show
  1. package/README.md +88 -0
  2. package/apps/shared/components/admin/layout/AdminShell.tsx +25 -8
  3. package/apps/shared/components/admin/settings/BrandingForm.tsx +398 -385
  4. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -112
  5. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +159 -152
  6. package/apps/shared/components/admin/settings/PluginsManager.tsx +1288 -1235
  7. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +9 -1
  8. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -290
  9. package/apps/shared/components/admin/setup/SetupWizard.tsx +443 -416
  10. package/apps/shared/components/calendar/layout/CalendarShell.tsx +194 -192
  11. package/apps/shared/components/contacts/layout/ContactsShell.tsx +199 -197
  12. package/apps/shared/components/layout/AppShell.tsx +288 -270
  13. package/apps/shared/components/mail/ConversationList.tsx +225 -33
  14. package/apps/shared/components/mail/ConversationThreadPane.tsx +434 -216
  15. package/apps/shared/components/mail/MailListToolbar.tsx +265 -0
  16. package/apps/shared/components/mail/MailSelectionBar.tsx +222 -0
  17. package/apps/shared/components/mail/MenuButton.tsx +384 -0
  18. package/apps/shared/components/mail/MessageDetailPane.tsx +280 -215
  19. package/apps/shared/components/mail/MoveToFolderDialog.tsx +263 -0
  20. package/apps/shared/components/mail/compose/ComposeContext.tsx +29 -2
  21. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1700 -1652
  22. package/apps/shared/components/mail/compose/RecipientInput.tsx +356 -0
  23. package/apps/shared/components/mail/compose/RichTextEditor.tsx +38 -3
  24. package/apps/shared/components/mail/compose/quotedBody.ts +100 -0
  25. package/apps/shared/components/mail/compose/recipients.ts +104 -0
  26. package/apps/shared/components/mail/labelMenu.tsx +278 -0
  27. package/apps/shared/components/mail/layout/MailShell.tsx +31 -4
  28. package/apps/shared/components/mail/listPreferences.ts +228 -0
  29. package/apps/shared/components/settings/layout/SettingsShell.tsx +23 -10
  30. package/apps/shared/components/tasks/layout/TasksShell.tsx +201 -199
  31. package/apps/shared/plugins/pluginNav.ts +73 -0
  32. package/apps/shared/search/localIndexRpcClient.ts +3 -1
  33. package/apps/shared/styles/app.css +28 -5
  34. package/apps/www/index.tsx +1854 -1314
  35. package/apps/www/messages/[uid].tsx +5 -4
  36. package/dist/apps/admin/_404.d.ts +2 -0
  37. package/dist/apps/admin/_500.d.ts +2 -0
  38. package/dist/apps/admin/_layout.d.ts +8 -0
  39. package/dist/apps/admin/audit-log/index.d.ts +11 -0
  40. package/dist/apps/admin/branding/index.d.ts +3 -0
  41. package/dist/apps/admin/data-requests/index.d.ts +3 -0
  42. package/dist/apps/admin/distribution-lists/[uid].d.ts +7 -0
  43. package/dist/apps/admin/distribution-lists/index.d.ts +3 -0
  44. package/dist/apps/admin/distribution-lists/new/index.d.ts +3 -0
  45. package/dist/apps/admin/domains/[uid].d.ts +7 -0
  46. package/dist/apps/admin/domains/index.d.ts +3 -0
  47. package/dist/apps/admin/domains/new/index.d.ts +3 -0
  48. package/dist/apps/admin/encryption-policy/index.d.ts +3 -0
  49. package/dist/apps/admin/escrow-scopes/[uid].d.ts +21 -0
  50. package/dist/apps/admin/escrow-scopes/index.d.ts +3 -0
  51. package/dist/apps/admin/escrow-scopes/new/index.d.ts +3 -0
  52. package/dist/apps/admin/index.d.ts +3 -0
  53. package/dist/apps/admin/ingest-queue/index.d.ts +4 -0
  54. package/dist/apps/admin/mailbox-policy/index.d.ts +3 -0
  55. package/dist/apps/admin/mailboxes/[uid].d.ts +7 -0
  56. package/dist/apps/admin/mailboxes/new/index.d.ts +3 -0
  57. package/dist/apps/admin/plugins/index.d.ts +3 -0
  58. package/dist/apps/admin/quarantine/index.d.ts +6 -0
  59. package/dist/apps/admin/retention-policy/index.d.ts +3 -0
  60. package/dist/apps/admin/setup/index.d.ts +3 -0
  61. package/dist/apps/admin/transport-rules/[uid].d.ts +7 -0
  62. package/dist/apps/admin/transport-rules/_transportRuleConfig.d.ts +21 -0
  63. package/dist/apps/admin/transport-rules/index.d.ts +3 -0
  64. package/dist/apps/admin/transport-rules/new/index.d.ts +3 -0
  65. package/dist/apps/escrow/_layout.d.ts +10 -0
  66. package/dist/apps/escrow/audit-log/index.d.ts +9 -0
  67. package/dist/apps/escrow/index.d.ts +3 -0
  68. package/dist/apps/escrow/matters/[uid].d.ts +7 -0
  69. package/dist/apps/escrow/matters/new/index.d.ts +3 -0
  70. package/dist/apps/shared/components/admin/distributionLists/MemberListCard.d.ts +17 -0
  71. package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.d.ts +32 -0
  72. package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +32 -0
  73. package/dist/apps/shared/components/admin/layout/AdminShell.js +12 -5
  74. package/dist/apps/shared/components/admin/mailboxes/EscrowScopeCard.d.ts +12 -0
  75. package/dist/apps/shared/components/admin/mailboxes/MailboxTable.d.ts +6 -0
  76. package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.d.ts +19 -0
  77. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +12 -0
  78. package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +13 -0
  79. package/dist/apps/shared/components/admin/settings/BrandingForm.js +6 -5
  80. package/dist/apps/shared/components/admin/settings/DomainDnsSetup.d.ts +12 -0
  81. package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.d.ts +15 -0
  82. package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +2 -2
  83. package/dist/apps/shared/components/admin/settings/LoadedSettingsForm.d.ts +9 -0
  84. package/dist/apps/shared/components/admin/settings/MailboxCreateForm.d.ts +19 -0
  85. package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.d.ts +13 -0
  86. package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +2 -2
  87. package/dist/apps/shared/components/admin/settings/PluginsManager.d.ts +11 -0
  88. package/dist/apps/shared/components/admin/settings/PluginsManager.js +33 -14
  89. package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.d.ts +12 -0
  90. package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +2 -2
  91. package/dist/apps/shared/components/admin/setup/EscrowSetupStep.d.ts +14 -0
  92. package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +1 -1
  93. package/dist/apps/shared/components/admin/setup/SetupWizard.d.ts +36 -0
  94. package/dist/apps/shared/components/admin/setup/SetupWizard.js +14 -10
  95. package/dist/apps/shared/components/admin/signOut.d.ts +23 -0
  96. package/dist/apps/shared/components/admin/usePagedList.d.ts +39 -0
  97. package/dist/apps/shared/components/calendar/CalendarListSidebar.d.ts +26 -0
  98. package/dist/apps/shared/components/calendar/EventModal.d.ts +46 -0
  99. package/dist/apps/shared/components/calendar/MonthView.d.ts +15 -0
  100. package/dist/apps/shared/components/calendar/RecurrenceEditor.d.ts +20 -0
  101. package/dist/apps/shared/components/calendar/ResourcePicker.d.ts +19 -0
  102. package/dist/apps/shared/components/calendar/SplitDayView.d.ts +28 -0
  103. package/dist/apps/shared/components/calendar/TimeGridView.d.ts +17 -0
  104. package/dist/apps/shared/components/calendar/allDay.d.ts +51 -0
  105. package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +40 -0
  106. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +2 -2
  107. package/dist/apps/shared/components/contacts/ContactDetailPane.d.ts +23 -0
  108. package/dist/apps/shared/components/contacts/ContactForm.d.ts +20 -0
  109. package/dist/apps/shared/components/contacts/ContactsSidebar.d.ts +40 -0
  110. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +25 -0
  111. package/dist/apps/shared/components/contacts/KeyChangeReview.d.ts +40 -0
  112. package/dist/apps/shared/components/contacts/contactKeys.d.ts +29 -0
  113. package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +21 -0
  114. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +2 -2
  115. package/dist/apps/shared/components/escrow/layout/EscrowShell.d.ts +25 -0
  116. package/dist/apps/shared/components/forms/StringListField.d.ts +22 -0
  117. package/dist/apps/shared/components/layout/AppShell.d.ts +49 -0
  118. package/dist/apps/shared/components/layout/AppShell.js +15 -13
  119. package/dist/apps/shared/components/layout/BrandingChrome.d.ts +18 -0
  120. package/dist/apps/shared/components/layout/KeyEnrollmentGate.d.ts +51 -0
  121. package/dist/apps/shared/components/layout/MailboxProvisioning.d.ts +13 -0
  122. package/dist/apps/shared/components/layout/RecoveryCodeUnlock.d.ts +66 -0
  123. package/dist/apps/shared/components/layout/UnlockPromptProvider.d.ts +45 -0
  124. package/dist/apps/shared/components/layout/UserMenu.d.ts +23 -0
  125. package/dist/apps/shared/components/mail/ConversationList.d.ts +47 -0
  126. package/dist/apps/shared/components/mail/ConversationList.js +84 -10
  127. package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +62 -0
  128. package/dist/apps/shared/components/mail/ConversationThreadPane.js +217 -60
  129. package/dist/apps/shared/components/mail/MailListToolbar.d.ts +55 -0
  130. package/dist/apps/shared/components/mail/MailListToolbar.js +149 -0
  131. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +59 -0
  132. package/dist/apps/shared/components/mail/MailSelectionBar.js +48 -0
  133. package/dist/apps/shared/components/mail/MenuButton.d.ts +71 -0
  134. package/dist/apps/shared/components/mail/MenuButton.js +211 -0
  135. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +101 -0
  136. package/dist/apps/shared/components/mail/MessageDetailPane.js +126 -129
  137. package/dist/apps/shared/components/mail/MoveToFolderDialog.d.ts +57 -0
  138. package/dist/apps/shared/components/mail/MoveToFolderDialog.js +138 -0
  139. package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +73 -0
  140. package/dist/apps/shared/components/mail/compose/ComposeContext.js +3 -1
  141. package/dist/apps/shared/components/mail/compose/ComposeToolbar.d.ts +15 -0
  142. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +37 -0
  143. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +52 -20
  144. package/dist/apps/shared/components/mail/compose/EmojiPicker.d.ts +14 -0
  145. package/dist/apps/shared/components/mail/compose/GifPicker.d.ts +13 -0
  146. package/dist/apps/shared/components/mail/compose/RecipientInput.d.ts +36 -0
  147. package/dist/apps/shared/components/mail/compose/RecipientInput.js +203 -0
  148. package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +43 -0
  149. package/dist/apps/shared/components/mail/compose/RichTextEditor.js +21 -3
  150. package/dist/apps/shared/components/mail/compose/ScheduleSendPicker.d.ts +16 -0
  151. package/dist/apps/shared/components/mail/compose/composeFlushRegistry.d.ts +27 -0
  152. package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +37 -0
  153. package/dist/apps/shared/components/mail/compose/quotedBody.js +85 -0
  154. package/dist/apps/shared/components/mail/compose/recipients.d.ts +24 -0
  155. package/dist/apps/shared/components/mail/compose/recipients.js +87 -0
  156. package/dist/apps/shared/components/mail/labelMenu.d.ts +97 -0
  157. package/dist/apps/shared/components/mail/labelMenu.js +134 -0
  158. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +65 -0
  159. package/dist/apps/shared/components/mail/layout/MailShell.js +17 -5
  160. package/dist/apps/shared/components/mail/listPreferences.d.ts +101 -0
  161. package/dist/apps/shared/components/mail/listPreferences.js +186 -0
  162. package/dist/apps/shared/components/mail/pinnedSigners.d.ts +33 -0
  163. package/dist/apps/shared/components/mail/verificationSeals.d.ts +22 -0
  164. package/dist/apps/shared/components/mail/writableMailboxes.d.ts +15 -0
  165. package/dist/apps/shared/components/rules/RuleBuilder.d.ts +70 -0
  166. package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +41 -0
  167. package/dist/apps/shared/components/settings/layout/SettingsShell.js +19 -10
  168. package/dist/apps/shared/components/tasks/TasksSidebar.d.ts +41 -0
  169. package/dist/apps/shared/components/tasks/TasksToolbar.d.ts +14 -0
  170. package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +24 -0
  171. package/dist/apps/shared/components/tasks/layout/TasksShell.js +2 -2
  172. package/dist/apps/shared/mail/findWellKnownFolderUid.d.ts +5 -0
  173. package/dist/apps/shared/mail/listAllPages.d.ts +17 -0
  174. package/dist/apps/shared/plugins/pluginNav.d.ts +39 -0
  175. package/dist/apps/shared/plugins/pluginNav.js +33 -0
  176. package/dist/apps/shared/search/LocalIndexLifecycle.d.ts +13 -0
  177. package/dist/apps/shared/search/localIndexBlockCipher.d.ts +36 -0
  178. package/dist/apps/shared/search/localIndexBuilder.d.ts +85 -0
  179. package/dist/apps/shared/search/localIndexKey.d.ts +4 -0
  180. package/dist/apps/shared/search/localIndexRpcClient.d.ts +71 -0
  181. package/dist/apps/shared/search/localIndexRpcClient.js +3 -1
  182. package/dist/apps/shared/search/localIndexSchema.d.ts +111 -0
  183. package/dist/apps/shared/search/localIndexSizePreference.d.ts +27 -0
  184. package/dist/apps/shared/search/localIndexStorage.d.ts +28 -0
  185. package/dist/apps/shared/search/localIndexVFS.d.ts +101 -0
  186. package/dist/apps/shared/search/localIndexWorker.d.ts +145 -0
  187. package/dist/apps/shared/search/searchTier2.d.ts +30 -0
  188. package/dist/apps/shared/styles/app.css +28 -5
  189. package/dist/apps/www/_404.d.ts +2 -0
  190. package/dist/apps/www/_500.d.ts +2 -0
  191. package/dist/apps/www/_layout.d.ts +14 -0
  192. package/dist/apps/www/calendar/index.d.ts +3 -0
  193. package/dist/apps/www/contacts/[uid].d.ts +13 -0
  194. package/dist/apps/www/contacts/index.d.ts +3 -0
  195. package/dist/apps/www/index.d.ts +3 -0
  196. package/dist/apps/www/index.js +506 -112
  197. package/dist/apps/www/messages/[uid].d.ts +11 -0
  198. package/dist/apps/www/messages/[uid].js +2 -3
  199. package/dist/apps/www/settings/auto-reply/index.d.ts +4 -0
  200. package/dist/apps/www/settings/encryption/index.d.ts +7 -0
  201. package/dist/apps/www/settings/filters/[uid].d.ts +8 -0
  202. package/dist/apps/www/settings/filters/_mailFilterRuleConfig.d.ts +11 -0
  203. package/dist/apps/www/settings/filters/index.d.ts +4 -0
  204. package/dist/apps/www/settings/filters/new/index.d.ts +4 -0
  205. package/dist/apps/www/settings/labels/index.d.ts +4 -0
  206. package/dist/apps/www/settings/privacy/index.d.ts +4 -0
  207. package/dist/apps/www/settings/read-receipts/index.d.ts +4 -0
  208. package/dist/apps/www/settings/sharing/index.d.ts +4 -0
  209. package/dist/apps/www/settings/signatures/[uid].d.ts +8 -0
  210. package/dist/apps/www/settings/signatures/index.d.ts +4 -0
  211. package/dist/apps/www/settings/signatures/new/index.d.ts +4 -0
  212. package/dist/apps/www/settings/signatures/signatureDefaults.d.ts +10 -0
  213. package/dist/apps/www/tasks/index.d.ts +3 -0
  214. package/package.json +3 -3
  215. package/apps/shared/components/booking/AvailabilityEditor.tsx +0 -118
  216. package/apps/www/settings/booking-types/[uid].tsx +0 -306
  217. package/apps/www/settings/booking-types/index.tsx +0 -98
  218. package/apps/www/settings/booking-types/new/index.tsx +0 -212
  219. package/apps/www/settings/focused-inbox/index.tsx +0 -150
  220. package/dist/apps/shared/components/booking/AvailabilityEditor.js +0 -45
  221. package/dist/apps/www/settings/booking-types/[uid].js +0 -134
  222. package/dist/apps/www/settings/booking-types/index.js +0 -29
  223. package/dist/apps/www/settings/booking-types/new/index.js +0 -86
  224. package/dist/apps/www/settings/focused-inbox/index.js +0 -71
@@ -1,216 +1,434 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import React, { useEffect, useRef, useState } from "react";
6
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
- import { Attachment, Folder, Message, getMessage, listAttachments, setMessageRead } from "@rapidmx/react-shared/mail/mailApi.js";
8
- import { ConversationSummary } from "@rapidmx/react-shared/mail/conversationsApi.js";
9
- import { Label } from "@rapidmx/react-shared/mail/labelsApi.js";
10
- import MessageDetailPane from "./MessageDetailPane.js";
11
- import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
12
-
13
- export interface ConversationThreadPaneProps {
14
- conversation: ConversationSummary | null;
15
- /** The mailbox's full folder list — a conversation can span folders (e.g. an Inbox message and the
16
- * Sent Items copy of its reply), so each message's own recall eligibility is looked up individually
17
- * against its own `folderUid` rather than assuming one folder for the whole thread. */
18
- folders: Folder[];
19
- /** The mailbox's labels, fetched once by the parent (`apps/www/index.tsx`) and passed through to
20
- * every expanded message's own `MessageDetailPane` — see that component's own `labels` prop. */
21
- labels?: Label[];
22
- }
23
-
24
- /**
25
- * The merged, Gmail-style reading pane for "By conversation" mode — every message in the conversation
26
- * fetched and stacked oldest-to-newest, all but the most recent collapsed to a one-line summary
27
- * (sender + subject) until clicked. Reuses `MessageDetailPane` for each *expanded* message's own
28
- * header/attachments/body-iframe rendering rather than re-implementing it; a collapsed row is its own
29
- * lightweight summary, since mounting a full `MessageDetailPane` (and its iframe) for every message in
30
- * a long thread up front would be wasteful.
31
- */
32
- export default function ConversationThreadPane({ conversation, folders, labels }: ConversationThreadPaneProps) {
33
- const [messages, setMessages] = useState<Record<string, Message>>({});
34
- const [attachmentsByUid, setAttachmentsByUid] = useState<Record<string, Attachment[]>>({});
35
- const [expandedUids, setExpandedUids] = useState<Set<string>>(new Set());
36
- const [loading, setLoading] = useState(false);
37
- const [error, setError] = useState<string | null>(null);
38
-
39
- // Bumped on every conversation switch - any in-flight load/attachments/mark-read response carrying an
40
- // older generation belongs to a superseded conversation and is dropped rather than applied.
41
- const generationRef = useRef(0);
42
- // Message uids a mark-read / attachments request has already been issued for in the current
43
- // generation, so re-running the effect below (every `messages`/`expandedUids` change) while one is
44
- // still in flight never fires a duplicate - which for mark-read would also carry a stale `version`.
45
- const markReadRequestedRef = useRef<Set<string>>(new Set());
46
- const attachmentsRequestedRef = useRef<Set<string>>(new Set());
47
-
48
- useEffect(() => {
49
- const generation = ++generationRef.current;
50
- markReadRequestedRef.current = new Set();
51
- attachmentsRequestedRef.current = new Set();
52
- setMessages({});
53
- setAttachmentsByUid({});
54
- setExpandedUids(new Set());
55
- if (!conversation) {
56
- setLoading(false);
57
- return;
58
- }
59
- setLoading(true);
60
- setError(null);
61
- Promise.all(conversation.messageUids.map((uid) => getMessage(uid)))
62
- .then((loaded) => {
63
- if (generation !== generationRef.current) return;
64
- setMessages(Object.fromEntries(loaded.map((m) => [m.uid, m])));
65
- // `messageUids` always has at least one entry — a `ConversationSummary` only ever
66
- // exists because it was grouped from real messages (see
67
- // `BaseMessageRoute.conversations()`).
68
- const latestUid = conversation.messageUids[conversation.messageUids.length - 1];
69
- setExpandedUids(new Set([latestUid]));
70
- })
71
- .catch((err) => {
72
- if (generation !== generationRef.current) return;
73
- setError(err instanceof ApiRequestError ? err.message : "Could not load this conversation.");
74
- })
75
- .finally(() => {
76
- if (generation === generationRef.current) setLoading(false);
77
- });
78
- }, [conversation?.conversationId]);
79
-
80
- // Lazily loads attachments and marks-as-read only for messages the reader has actually expanded —
81
- // mirrors `mailDetailHooks.ts`'s `useMessageAttachments`/`useMarkMessageRead`, reimplemented here
82
- // (rather than called in a loop, which the rules of hooks don't allow) since a thread can expand
83
- // more than one message at once, unlike the single-selected-message case those hooks were built for.
84
- useEffect(() => {
85
- const generation = generationRef.current;
86
- for (const uid of expandedUids) {
87
- const message = messages[uid];
88
- if (!message) continue;
89
- if (message.hasAttachments && !attachmentsRequestedRef.current.has(uid)) {
90
- attachmentsRequestedRef.current.add(uid);
91
- listAttachments(message.folderUid, uid)
92
- .then((loaded) => {
93
- if (generation === generationRef.current) {
94
- setAttachmentsByUid((prev) => ({ ...prev, [uid]: loaded }));
95
- }
96
- })
97
- .catch(() => {
98
- // Best-effort, same as the mark-as-read catch below — `attachmentsByUid[uid] ??
99
- // []` already renders no attachments while this stays unset; forgetting the
100
- // request just lets a later re-expand retry it.
101
- attachmentsRequestedRef.current.delete(uid);
102
- });
103
- }
104
- // `message` is this render's latest copy, so the request carries its current `version`.
105
- if (!message.flags.read && !markReadRequestedRef.current.has(uid)) {
106
- markReadRequestedRef.current.add(uid);
107
- setMessageRead(message, true)
108
- .then((updated) => {
109
- if (generation !== generationRef.current) return;
110
- // Never clobber a newer copy another action (label/classify/...) already patched in.
111
- setMessages((prev) => (prev[uid].version > updated.version ? prev : { ...prev, [uid]: updated }));
112
- })
113
- .catch(() => {
114
- // Best-effort — matches `useMarkMessageRead`'s own doc comment. Forgetting the
115
- // request lets a later effect run (e.g. a re-expand) retry with a fresh copy.
116
- markReadRequestedRef.current.delete(uid);
117
- });
118
- }
119
- }
120
- }, [expandedUids, messages]);
121
-
122
- function toggleExpanded(uid: string) {
123
- setExpandedUids((prev) => {
124
- const next = new Set(prev);
125
- if (next.has(uid)) {
126
- next.delete(uid);
127
- } else {
128
- next.add(uid);
129
- }
130
- return next;
131
- });
132
- }
133
-
134
- if (!conversation) {
135
- return <p className="p-8 text-sm text-text-muted">Select a conversation to read it.</p>;
136
- }
137
- if (loading) {
138
- return <p className="p-8 text-sm text-text-muted">Loading&hellip;</p>;
139
- }
140
- if (error) {
141
- return (
142
- <div className="p-4 flex-1">
143
- <Alert>{error}</Alert>
144
- </div>
145
- );
146
- }
147
-
148
- return (
149
- <div className="flex-1 min-w-0 flex flex-col overflow-y-auto">
150
- <div className="border-b border-border p-4">
151
- <h1 className="text-lg font-bold tracking-tight">{conversation.subject || "(no subject)"}</h1>
152
- <p className="text-sm text-text-muted mt-1">
153
- {conversation.messageCount} message{conversation.messageCount === 1 ? "" : "s"}
154
- </p>
155
- </div>
156
- {conversation.messageUids.map((uid) => {
157
- const message = messages[uid];
158
- if (!message) {
159
- return null;
160
- }
161
- const expanded = expandedUids.has(uid);
162
- if (!expanded) {
163
- return (
164
- <button
165
- key={uid}
166
- type="button"
167
- onClick={() => toggleExpanded(uid)}
168
- className={[
169
- "w-full text-left px-4 py-3 border-b border-border hover:bg-surface-alt",
170
- message.flags.read ? "" : "font-semibold",
171
- ].join(" ")}
172
- >
173
- <div className="flex items-center justify-between gap-2 text-sm">
174
- <span className="truncate">{message.from.displayName || message.from.address}</span>
175
- <span className="text-xs text-text-muted shrink-0">
176
- {new Date(message.receivedDate).toLocaleString()}
177
- </span>
178
- </div>
179
- <div className="text-xs text-text-muted truncate font-normal">{message.bodyPreview}</div>
180
- </button>
181
- );
182
- }
183
- return (
184
- <div key={uid} className="border-b border-border">
185
- <button
186
- type="button"
187
- onClick={() => toggleExpanded(uid)}
188
- className="w-full text-left px-4 pt-2 text-xs text-text-muted hover:text-text"
189
- >
190
- Collapse
191
- </button>
192
- <MessageDetailPane
193
- message={message}
194
- attachments={attachmentsByUid[uid] ?? []}
195
- isSentItems={folders.find((f) => f.uid === message.folderUid)?.type === "sent_items"}
196
- onRecalled={(updated) => setMessages((prev) => ({ ...prev, [uid]: updated }))}
197
- isOutbox={folders.find((f) => f.uid === message.folderUid)?.type === "outbox"}
198
- draftsFolderUid={folders.find((f) => f.type === "drafts")?.uid}
199
- // Unlike `apps/www/index.tsx`'s list-removal behavior, this patches the
200
- // message in place (same as `onRecalled` above) rather than removing it from
201
- // the conversation — `conversation.messageUids` is owned by the parent, not
202
- // this component, so there's no membership list here to remove it from.
203
- onScheduledSendCanceled={(updated) => setMessages((prev) => ({ ...prev, [uid]: updated }))}
204
- isInbox={folders.find((f) => f.uid === message.folderUid)?.type === "inbox"}
205
- onClassified={(updated) => setMessages((prev) => ({ ...prev, [uid]: updated }))}
206
- onReceiptHandled={(updated) => setMessages((prev) => ({ ...prev, [uid]: updated }))}
207
- onArchived={(updated) => setMessages((prev) => ({ ...prev, [uid]: updated }))}
208
- labels={labels}
209
- onLabelsChanged={(updated) => setMessages((prev) => ({ ...prev, [uid]: updated }))}
210
- />
211
- </div>
212
- );
213
- })}
214
- </div>
215
- );
216
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import { Attachment, Folder, Message, listAttachments, setMessageRead } from "@rapidmx/react-shared/mail/mailApi.js";
8
+ import { ConversationSummary, listConversationMessages } from "@rapidmx/react-shared/mail/conversationsApi.js";
9
+ import { Label } from "@rapidmx/react-shared/mail/labelsApi.js";
10
+ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
11
+ import MessageDetailPane from "./MessageDetailPane.js";
12
+
13
+ /** One request's worth of the thread. The server's own default for `listConversationMessages()`. */
14
+ export const THREAD_PAGE_SIZE = 100;
15
+ /**
16
+ * How many of a conversation's messages this pane will load. The server reads at most
17
+ * `CONVERSATION_SCAN_LIMIT` (500) messages when it groups conversations, so a `ConversationSummary` never
18
+ * describes more than this many anyway; the cap is here so a thread that somehow reports more can't turn
19
+ * into an unbounded run of requests. Past it the pane says so and the rest stay readable from the list.
20
+ */
21
+ export const THREAD_MESSAGE_LIMIT = 500;
22
+
23
+ export interface ConversationThreadPaneProps {
24
+ conversation: ConversationSummary | null;
25
+ /** The mailbox the conversation was listed from - `listConversationMessages()` is mailbox-scoped. */
26
+ mailboxUid: string;
27
+ /**
28
+ * The message the reader opened: the thread is scrolled to it, it takes focus, and it is the *oldest*
29
+ * message left expanded (see `expandedFrom()`). `null`, or a uid this thread doesn't hold, falls back
30
+ * to the newest message - which is also what a parent row means by "open the conversation".
31
+ */
32
+ selectedUid: string | null;
33
+ /** The mailbox's full folder list. A conversation spans folders (an Inbox message and the Sent Items
34
+ * copy of its reply), so each message's own folder type is looked up against its own `folderUid`. */
35
+ folders: Folder[];
36
+ /** The mailbox's labels, passed through to every expanded message's own `MessageDetailPane`. */
37
+ labels?: Label[];
38
+ /**
39
+ * A newer copy of one of the thread's messages - read, flagged, labelled, classified, recalled - for
40
+ * the caller's own list to stay in step with what was done in here.
41
+ *
42
+ * `previous` is the copy this pane held before the change, where it has one: the conversation row this
43
+ * thread came from is a *summary* (a message count, an unread count), so a list showing those rows has
44
+ * no way to tell "this message has just been read" from "this already-read message was relabelled"
45
+ * without it - which is what left a row reporting "2 unread" after both had been read.
46
+ */
47
+ onMessagePatched: (updated: Message, previous?: Message) => void;
48
+ /** A message that left the folder being listed (archived, or a scheduled send sent back to Drafts). */
49
+ onMessageRemoved: (updated: Message) => void;
50
+ onLabelCreated?: (label: Label) => void;
51
+ /** A folder created from a message's own Move to prompt, for the folder sidebar to pick up. */
52
+ onFolderCreated?: (folder: Folder) => void;
53
+ }
54
+
55
+ /**
56
+ * Every message from `selectedUid` through to the newest - the run the reader is reading. Anything older
57
+ * stays collapsed to its one-line summary. Selecting the newest message therefore expands just that one.
58
+ *
59
+ * The pane lists newest first (see `loadThread()`), so that run is the opened message together with
60
+ * everything *above* it, and the opened message is the set's **last** entry rather than its first.
61
+ */
62
+ function expandedFrom(messages: Message[], selectedUid: string | null): Set<string> {
63
+ const index = messages.findIndex((message) => message.uid === selectedUid);
64
+ // `messages` is never empty here (the callers below check), so -1 means "not in this thread" and the
65
+ // newest message - the first entry - is the anchor, exactly as a parent row's own click means.
66
+ const anchor = index === -1 ? 0 : index;
67
+ return new Set(messages.slice(0, anchor + 1).map((message) => message.uid));
68
+ }
69
+
70
+ /**
71
+ * The element a message of this thread actually scrolls inside. The pane is not itself the scroll
72
+ * container in the mail shell - `MailShell`'s own `<main>` is - so an adjustment has to be applied where
73
+ * the scrolling really happens, which is whichever ancestor is both scrollable and overflowing.
74
+ */
75
+ function scrollingAncestor(node: HTMLElement): HTMLElement {
76
+ for (let el = node.parentElement; el; el = el.parentElement) {
77
+ const overflowY = getComputedStyle(el).overflowY;
78
+ if ((overflowY === "auto" || overflowY === "scroll") && el.scrollHeight > el.clientHeight) {
79
+ return el;
80
+ }
81
+ }
82
+ // Nothing between the row and the root scrolls, so the page itself does - which in standards mode is
83
+ // `documentElement`, the same element `document.scrollingElement` names there.
84
+ return document.documentElement;
85
+ }
86
+
87
+ /**
88
+ * The thread's messages, **newest first**, in pages of `THREAD_PAGE_SIZE` up to `THREAD_MESSAGE_LIMIT`.
89
+ *
90
+ * `listConversationMessages()` pages oldest first and has no order of its own to ask for, so the pages are
91
+ * collected in that order - which is also the order the `THREAD_MESSAGE_LIMIT` cap has to apply in, since it
92
+ * is the oldest messages that are dropped when a thread is too long to load - and reversed once at the end.
93
+ * The pane reads newest first always, whatever the *list* is sorted by: it is the reading order for mail,
94
+ * and it means the message a conversation row stands for is the entry at the top.
95
+ */
96
+ async function loadThread(mailboxUid: string, conversationId: string): Promise<{ messages: Message[]; truncated: boolean }> {
97
+ const messages: Message[] = [];
98
+ let more = true;
99
+ while (more && messages.length < THREAD_MESSAGE_LIMIT) {
100
+ const page = await listConversationMessages(mailboxUid, conversationId, {
101
+ page: messages.length / THREAD_PAGE_SIZE,
102
+ limit: THREAD_PAGE_SIZE,
103
+ });
104
+ messages.push(...page);
105
+ // A short page is the last one; a full page means asking for another.
106
+ more = page.length === THREAD_PAGE_SIZE;
107
+ }
108
+ messages.reverse();
109
+ return { messages, truncated: more };
110
+ }
111
+
112
+ /**
113
+ * The reading pane for the conversation list: the whole thread, **newest at the top**, opened at the message
114
+ * the reader picked. Every message from that one through to the newest is expanded - which in this order is
115
+ * the opened message and the entries above it - and the older ones, below it, are collapsed to a one-line
116
+ * summary (sender, date, preview) that expands on click or Enter. So opening the newest message shows just
117
+ * the top entry expanded, and opening 5 of 10 expands 10 down to 5.
118
+ *
119
+ * Newest first regardless of how the *list* is sorted: the list's own order arranges rows to pick from,
120
+ * while this is one conversation being read, and the entry a conversation row stands for - its latest
121
+ * message - is the one that should be at the top of the pane every time it is opened.
122
+ *
123
+ * Each *expanded* message is a `MessageDetailPane` of its own rather than a reimplementation of it, so the
124
+ * signature and verification badges, the verification-seal and decryption behaviour, the labels chips and
125
+ * menu, the attachments and Reply/Reply All/Forward/Archive all behave exactly as they do in the
126
+ * single-message pane, and each acts on the message it belongs to. A collapsed message mounts none of
127
+ * that - mounting a body iframe per message up front would be wasteful in a long thread.
128
+ */
129
+ export default function ConversationThreadPane({
130
+ conversation,
131
+ mailboxUid,
132
+ selectedUid,
133
+ folders,
134
+ labels,
135
+ onMessagePatched,
136
+ onMessageRemoved,
137
+ onLabelCreated,
138
+ onFolderCreated,
139
+ }: ConversationThreadPaneProps) {
140
+ const [messages, setMessages] = useState<Message[]>([]);
141
+ const [attachmentsByUid, setAttachmentsByUid] = useState<Record<string, Attachment[]>>({});
142
+ const [expandedUids, setExpandedUids] = useState<Set<string>>(new Set());
143
+ const [truncated, setTruncated] = useState(false);
144
+ const [loading, setLoading] = useState(false);
145
+ const [error, setError] = useState<string | null>(null);
146
+ /** The message to scroll to and focus once it has rendered, or `null` once that has happened. */
147
+ const [pendingFocusUid, setPendingFocusUid] = useState<string | null>(null);
148
+
149
+ // Bumped on every conversation switch - an in-flight load/attachments/mark-read response carrying an
150
+ // older generation belongs to a superseded conversation and is dropped rather than applied.
151
+ const generationRef = useRef(0);
152
+ const markReadRequestedRef = useRef<Set<string>>(new Set());
153
+ const attachmentsRequestedRef = useRef<Set<string>>(new Set());
154
+ /** The `conversationId:selectedUid` the expansion run below has already been applied for, so patching
155
+ * a message (which changes `messages`) doesn't re-expand what the reader has since collapsed. */
156
+ const appliedSelectionRef = useRef<string | null>(null);
157
+ /** Which conversation the messages currently in state belong to. A render with a new conversation and
158
+ * the previous one's messages still in state happens before the load effect has cleared them, and the
159
+ * expansion run below must sit that render out rather than anchor on a message from another thread. */
160
+ const loadedIdRef = useRef<string | null>(null);
161
+ const rowRefs = useRef<Record<string, HTMLLIElement | null>>({});
162
+ const headerRefs = useRef<Record<string, HTMLButtonElement | null>>({});
163
+ /** Where the toggled message's header sat in the viewport before it expanded, so the run below can put
164
+ * it back there - expanding a message above the one being read must not shove that one off-screen. */
165
+ const anchorRef = useRef<{ uid: string; top: number } | null>(null);
166
+
167
+ const conversationId = conversation?.conversationId;
168
+
169
+ useEffect(() => {
170
+ const generation = ++generationRef.current;
171
+ markReadRequestedRef.current = new Set();
172
+ attachmentsRequestedRef.current = new Set();
173
+ appliedSelectionRef.current = null;
174
+ loadedIdRef.current = null;
175
+ setMessages([]);
176
+ setAttachmentsByUid({});
177
+ setExpandedUids(new Set());
178
+ setTruncated(false);
179
+ setError(null);
180
+ // The message the previous conversation was to be scrolled to went with it; leaving it set would
181
+ // point the run below at a row that is no longer rendered.
182
+ setPendingFocusUid(null);
183
+ if (!conversationId) {
184
+ setLoading(false);
185
+ return;
186
+ }
187
+ setLoading(true);
188
+ loadThread(mailboxUid, conversationId)
189
+ .then((loaded) => {
190
+ if (generation !== generationRef.current) return;
191
+ loadedIdRef.current = conversationId;
192
+ setMessages(loaded.messages);
193
+ setTruncated(loaded.truncated);
194
+ })
195
+ .catch((err) => {
196
+ if (generation !== generationRef.current) return;
197
+ setError(err instanceof ApiRequestError ? err.message : "Could not load this conversation.");
198
+ })
199
+ .finally(() => {
200
+ if (generation === generationRef.current) setLoading(false);
201
+ });
202
+ }, [conversationId, mailboxUid]);
203
+
204
+ // Opening the thread, and opening a different message of the same thread, both set the run of expanded
205
+ // messages and ask for that message to be scrolled to. `messages` is a dependency because the thread's
206
+ // messages arrive after the click that selected one of them; the ref guard keeps a later change to
207
+ // `messages` (a patched copy) from re-running it.
208
+ useEffect(() => {
209
+ if (messages.length === 0 || loadedIdRef.current !== conversationId) return;
210
+ const key = `${conversationId}:${selectedUid}`;
211
+ if (appliedSelectionRef.current === key) return;
212
+ appliedSelectionRef.current = key;
213
+ const expanded = expandedFrom(messages, selectedUid);
214
+ setExpandedUids(expanded);
215
+ // The oldest expanded message is the one that was opened - `expandedFrom()`'s own anchor - which in
216
+ // this newest-first order is the *last* of the run, not the first.
217
+ setPendingFocusUid([...expanded][expanded.size - 1]);
218
+ }, [conversationId, selectedUid, messages]);
219
+
220
+ useLayoutEffect(() => {
221
+ if (!pendingFocusUid) return;
222
+ // The row is always rendered by now: this runs after the DOM update that added the message it
223
+ // names, and that message came out of `messages` in the first place.
224
+ //
225
+ // Scrolled inside the thread's own list and nowhere else. `scrollIntoView()` scrolls *every*
226
+ // scrollable ancestor, the window included, which with a run of full-height messages expanded
227
+ // took the app header and the folder rail off the screen - so the adjustment goes on whichever
228
+ // ancestor actually scrolls, exactly as the toggle below already does it. When that is the page
229
+ // itself, nothing inside the pane scrolls and the row is already in view, so it is left alone.
230
+ const row = rowRefs.current[pendingFocusUid]!;
231
+ const scroller = scrollingAncestor(row);
232
+ if (scroller !== document.documentElement) {
233
+ const rect = row.getBoundingClientRect();
234
+ const top = rect.top - scroller.getBoundingClientRect().top;
235
+ // "nearest": the least that brings it into view, and nothing at all when it is already there.
236
+ if (top < 0 || top + rect.height > scroller.clientHeight) {
237
+ scroller.scrollTop += top;
238
+ }
239
+ }
240
+ // `preventScroll` so focusing doesn't scroll it somewhere else again.
241
+ headerRefs.current[pendingFocusUid]!.focus({ preventScroll: true });
242
+ setPendingFocusUid(null);
243
+ }, [pendingFocusUid, expandedUids]);
244
+
245
+ // Keeps the message whose header was just clicked where it was on screen. Expanding one above the
246
+ // message being read otherwise pushes everything below it down by however tall the new body is.
247
+ useLayoutEffect(() => {
248
+ const anchor = anchorRef.current;
249
+ if (!anchor) return;
250
+ anchorRef.current = null;
251
+ // The row is still there: the anchor was taken from a rendered row, and toggling never removes one.
252
+ const row = rowRefs.current[anchor.uid]!;
253
+ scrollingAncestor(row).scrollTop += row.getBoundingClientRect().top - anchor.top;
254
+ }, [expandedUids]);
255
+
256
+ // Attachments and mark-as-read, for expanded messages only - mirrors `mailDetailHooks.ts`'s
257
+ // `useMessageAttachments`/`useMarkMessageRead`, reimplemented here (rather than called in a loop, which
258
+ // the rules of hooks don't allow) because a thread expands several messages at once.
259
+ useEffect(() => {
260
+ const generation = generationRef.current;
261
+ for (const message of messages) {
262
+ const uid = message.uid;
263
+ if (!expandedUids.has(uid)) continue;
264
+ if (message.hasAttachments && !attachmentsRequestedRef.current.has(uid)) {
265
+ attachmentsRequestedRef.current.add(uid);
266
+ listAttachments(message.folderUid, uid)
267
+ .then((loaded) => {
268
+ if (generation === generationRef.current) {
269
+ setAttachmentsByUid((prev) => ({ ...prev, [uid]: loaded }));
270
+ }
271
+ })
272
+ .catch(() => {
273
+ // Best-effort, as in `useMessageAttachments`: no attachments render meanwhile, and
274
+ // forgetting the request lets a later re-expand retry it.
275
+ attachmentsRequestedRef.current.delete(uid);
276
+ });
277
+ }
278
+ if (!message.flags.read && !markReadRequestedRef.current.has(uid)) {
279
+ markReadRequestedRef.current.add(uid);
280
+ // `message` is this render's copy, so the request carries its current `version`.
281
+ setMessageRead(message, true)
282
+ .then((updated) => {
283
+ if (generation !== generationRef.current) return;
284
+ // `message` is the unread copy this pane just replaced - what tells the list's own
285
+ // conversation row that its unread count has gone down by one.
286
+ patchMessage(updated, message);
287
+ })
288
+ .catch(() => {
289
+ // Best-effort, as in `useMarkMessageRead`.
290
+ markReadRequestedRef.current.delete(uid);
291
+ });
292
+ }
293
+ }
294
+ }, [expandedUids, messages]);
295
+
296
+ /** A newer copy of one of the thread's messages, kept here and handed to the list - with the copy it
297
+ * replaces where the caller was given one, so a conversation row can tell what actually changed. */
298
+ function patchMessage(updated: Message, previous?: Message) {
299
+ setMessages((prev) => prev.map((message) => (message.uid === updated.uid ? updated : message)));
300
+ onMessagePatched(updated, previous);
301
+ }
302
+
303
+ /** A message that left the folder being listed - it leaves the thread too, as it left the list. */
304
+ function removeMessage(updated: Message) {
305
+ setMessages((prev) => prev.filter((message) => message.uid !== updated.uid));
306
+ onMessageRemoved(updated);
307
+ }
308
+
309
+ function toggleExpanded(uid: string) {
310
+ // The row this button lives in has rendered, so its ref is set.
311
+ anchorRef.current = { uid, top: rowRefs.current[uid]!.getBoundingClientRect().top };
312
+ setExpandedUids((prev) => {
313
+ const next = new Set(prev);
314
+ if (next.has(uid)) {
315
+ next.delete(uid);
316
+ } else {
317
+ next.add(uid);
318
+ }
319
+ return next;
320
+ });
321
+ }
322
+
323
+ function folderTypeOf(message: Message): string | undefined {
324
+ return folders.find((folder) => folder.uid === message.folderUid)?.type;
325
+ }
326
+
327
+ if (!conversation) {
328
+ return <p className="p-8 text-sm text-text-muted">Select a conversation to read it.</p>;
329
+ }
330
+ if (loading) {
331
+ return <p className="p-8 text-sm text-text-muted">Loading&hellip;</p>;
332
+ }
333
+ if (error) {
334
+ return (
335
+ <div className="p-4 flex-1">
336
+ <Alert>{error}</Alert>
337
+ </div>
338
+ );
339
+ }
340
+
341
+ return (
342
+ // The pane is the window's height, not the thread's: a full-height flex column whose heading is
343
+ // fixed and whose list of messages is the one scrolling, growing child (`min-h-0`, or the list
344
+ // would stretch the column past the pane instead of scrolling inside it). That is what gives an
345
+ // expanded message's own `min-h-full` row - and therefore its body iframe, which can't measure
346
+ // itself - a real height to resolve against at any window size.
347
+ <div className="flex-1 min-w-0 min-h-0 flex flex-col">
348
+ <div className="shrink-0 border-b border-border p-4">
349
+ <h1 className="text-lg font-bold tracking-tight">{conversation.subject || "(no subject)"}</h1>
350
+ <p className="text-sm text-text-muted mt-1">
351
+ {messages.length} message{messages.length === 1 ? "" : "s"}
352
+ </p>
353
+ {truncated && (
354
+ <p className="text-xs text-text-muted mt-1">
355
+ Only the oldest {THREAD_MESSAGE_LIMIT} messages of this conversation are shown here. The rest
356
+ are still in the message list.
357
+ </p>
358
+ )}
359
+ </div>
360
+ <ul className="flex-1 min-h-0 overflow-y-auto">
361
+ {messages.map((message) => {
362
+ const uid = message.uid;
363
+ const expanded = expandedUids.has(uid);
364
+ const bodyId = `thread-message-${uid}`;
365
+ const sender = message.from.displayName || message.from.address;
366
+ return (
367
+ <li
368
+ key={uid}
369
+ ref={(node) => {
370
+ rowRefs.current[uid] = node;
371
+ }}
372
+ // An expanded message is as tall as the list it scrolls in - `min-h-full`
373
+ // against the `<ul>`'s own resolved height - so its `MessageDetailPane` below
374
+ // has a full pane of height to fill and its body reaches the bottom of the
375
+ // window whatever that window's size is. `min-` rather than `h-`: a message
376
+ // whose header alone is taller than the pane still gets the room it needs.
377
+ className={["border-b border-border", expanded ? "flex flex-col min-h-full" : ""].join(" ")}
378
+ >
379
+ <h2 className="shrink-0">
380
+ <button
381
+ type="button"
382
+ ref={(node) => {
383
+ headerRefs.current[uid] = node;
384
+ }}
385
+ onClick={() => toggleExpanded(uid)}
386
+ aria-expanded={expanded}
387
+ aria-controls={bodyId}
388
+ className={[
389
+ "w-full text-left px-4 py-3 hover:bg-surface-alt",
390
+ message.flags.read ? "" : "font-semibold",
391
+ ].join(" ")}
392
+ >
393
+ <span className="flex items-center justify-between gap-2 text-sm">
394
+ <span className="truncate">{sender}</span>
395
+ <span className="text-xs text-text-muted shrink-0">
396
+ {new Date(message.receivedDate).toLocaleString()}
397
+ </span>
398
+ </span>
399
+ {!expanded && (
400
+ <span className="block text-xs text-text-muted truncate font-normal">
401
+ {message.bodyPreview}
402
+ </span>
403
+ )}
404
+ </button>
405
+ </h2>
406
+ <div id={bodyId} hidden={!expanded} className={expanded ? "flex-1 min-h-0 flex" : undefined}>
407
+ {expanded && (
408
+ <MessageDetailPane
409
+ inThread
410
+ message={message}
411
+ attachments={attachmentsByUid[uid] ?? []}
412
+ isSentItems={folderTypeOf(message) === "sent_items"}
413
+ isOutbox={folderTypeOf(message) === "outbox"}
414
+ draftsFolderUid={folders.find((folder) => folder.type === "drafts")?.uid}
415
+ folders={folders}
416
+ onMoved={removeMessage}
417
+ onFolderCreated={onFolderCreated}
418
+ onRecalled={patchMessage}
419
+ onReceiptHandled={patchMessage}
420
+ onScheduledSendCanceled={removeMessage}
421
+ onArchived={removeMessage}
422
+ labels={labels}
423
+ onLabelsChanged={patchMessage}
424
+ onLabelCreated={onLabelCreated}
425
+ />
426
+ )}
427
+ </div>
428
+ </li>
429
+ );
430
+ })}
431
+ </ul>
432
+ </div>
433
+ );
434
+ }