Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(email): show saved reply drafts in threads on touch (#8240)

teo473f095b4e31
diff --git a/apps/web/src/features/email-thread/components/draft-reply-preview.test.tsx b/apps/web/src/features/email-thread/components/draft-reply-preview.test.tsx
new file mode 100644
index 0000000000..7d91b218e0
--- /dev/null
+++ b/apps/web/src/features/email-thread/components/draft-reply-preview.test.tsx
@@ -0,0 +1,20 @@
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { afterEach, expect, it, vi } from 'vitest';
+import { DraftReplyPreview } from './draft-reply-preview';
+
+afterEach(cleanup);
+
+it('reopens the draft when tapped and keeps its text out of session replay', () => {
+ const onOpen = vi.fn();
+ render(() => <DraftReplyPreview text="Sounds good" onOpen={onOpen} />);
+
+ const text = screen.getByText('Sounds good');
+ expect(text.classList.contains('ph-no-capture')).toBe(true);
+ fireEvent.click(screen.getByRole('button', { name: /Draft/ }));
+ expect(onOpen).toHaveBeenCalledOnce();
+});
+
+it('says so when the draft has no text yet', () => {
+ render(() => <DraftReplyPreview text="" onOpen={() => {}} />);
+ expect(screen.getByText('No text yet')).toBeTruthy();
+});
diff --git a/apps/web/src/features/email-thread/components/draft-reply-preview.tsx b/apps/web/src/features/email-thread/components/draft-reply-preview.tsx
new file mode 100644
index 0000000000..a63e6fa60d
--- /dev/null
+++ b/apps/web/src/features/email-thread/components/draft-reply-preview.tsx
@@ -0,0 +1,21 @@
+import PencilSimple from '@phosphor/pencil-simple.svg';
+
+/**
+ * A saved reply shown under the message it answers, where touch devices have
+ * no inline composer. Tapping it reopens the draft.
+ */
+export function DraftReplyPreview(props: { text: string; onOpen: () => void }) {
+ return (
+ <button
+ type="button"
+ class="flex w-full min-h-11 items-center gap-2 py-2 text-left text-sm"
+ onClick={() => props.onOpen()}
+ >
+ <span class="shrink-0 font-medium text-warning">Draft</span>
+ <span class="ph-no-capture min-w-0 flex-1 truncate text-ink-muted">
+ {props.text || 'No text yet'}
+ </span>
+ <PencilSimple class="size-4 shrink-0 text-ink-extra-muted" />
+ </button>
+ );
+}
diff --git a/apps/web/src/features/email-thread/core/draft-preview.test.ts b/apps/web/src/features/email-thread/core/draft-preview.test.ts
new file mode 100644
index 0000000000..35c577ba47
--- /dev/null
+++ b/apps/web/src/features/email-thread/core/draft-preview.test.ts
@@ -0,0 +1,29 @@
+import { expect, it } from 'vitest';
+import { draftPreviewText } from './draft-preview';
+
+const html = (value: string) => ({
+ body_html_sanitized: btoa(value),
+ body_text: null,
+ snippet: null,
+});
+
+it('previews what the reply says, not the thread it quotes', () => {
+ expect(
+ draftPreviewText(
+ html(
+ '<div><span>Sounds good,</span></div><div><span>see you then</span></div>' +
+ '<div class="macro_quote gmail_quote">On Oct 11, Jonas wrote: the old message</div>'
+ )
+ )
+ ).toBe('Sounds good, see you then');
+});
+
+it('falls back to plain text for drafts saved without HTML', () => {
+ expect(
+ draftPreviewText({
+ body_html_sanitized: null,
+ body_text: 'Offline\n reply',
+ snippet: null,
+ })
+ ).toBe('Offline reply');
+});
diff --git a/apps/web/src/features/email-thread/core/draft-preview.ts b/apps/web/src/features/email-thread/core/draft-preview.ts
new file mode 100644
index 0000000000..196a56ddda
--- /dev/null
+++ b/apps/web/src/features/email-thread/core/draft-preview.ts
@@ -0,0 +1,27 @@
+import { decodeBase64Utf8 } from '@app/features/email-compose/core/decode-base64';
+import type { EmailMessage } from '@app/features/email-message/core/email-message';
+
+/**
+ * What a draft reply says so far, on one line and without the thread it
+ * quotes. Saved drafts usually carry only HTML; a snippet or plain text is
+ * the fallback.
+ */
+export function draftPreviewText(
+ draft: Pick<EmailMessage, 'body_html_sanitized' | 'body_text' | 'snippet'>
+): string {
+ const encoded = draft.body_html_sanitized;
+ const text = encoded
+ ? htmlText(decodeBase64Utf8(encoded))
+ : (draft.body_text ?? draft.snippet ?? '');
+ return text.replace(/\s+/g, ' ').trim();
+}
+
+function htmlText(html: string) {
+ const { body } = new DOMParser().parseFromString(html, 'text/html');
+ for (const quote of body.querySelectorAll('.macro_quote, .gmail_quote'))
+ quote.remove();
+ // Paragraphs are adjacent elements; keep their words apart.
+ for (const block of body.querySelectorAll('p, div, li, br, h1, h2, h3'))
+ block.after(' ');
+ return body.textContent ?? '';
+}
diff --git a/apps/web/src/features/email-thread/views/message-container.tsx b/apps/web/src/features/email-thread/views/message-container.tsx
index aa7b805443..1e21663596 100644
--- a/apps/web/src/features/email-thread/views/message-container.tsx
+++ b/apps/web/src/features/email-thread/views/message-container.tsx
@@ -3,8 +3,10 @@ import { FloatingInputLoader } from '@core/component/FloatingInputLoader';
import { createMemo, createSignal, Match, Show, Switch } from 'solid-js';
import { isPersonalMessage } from '../../email-message/core/is-personal-message';
import { EmailMessageView } from '../../email-message/views/email-message';
+import { DraftReplyPreview } from '../components/draft-reply-preview';
import { useEmailThreadState } from '../context/email-thread-state-context';
import { useEmailThreadViewContext } from '../context/email-thread-view-context';
+import { draftPreviewText } from '../core/draft-preview';
import { openEmailReplyComposerForMessage } from '../primitives/reply-actions';
import {
revealMessageAfterLayout,
@@ -55,6 +57,10 @@ export function MessageContainer(props: MessageContainerProps) {
context.drafts.initialDraftsSettled()
);
+ // Touch replies live in a drawer, so a saved one would otherwise be invisible.
+ const touchDraft = () =>
+ isTouchDevice() && context.permissions().isOwner ? draftChild() : undefined;
+
const showInlineReplyArea = createMemo(
() =>
context.permissions().isOwner &&
@@ -138,6 +144,20 @@ export function MessageContainer(props: MessageContainerProps) {
: undefined
}
>
+ <Show when={touchDraft()}>
+ {(draft) => (
+ <div class="-mx-4 mt-3 border-t border-edge-muted px-4">
+ <DraftReplyPreview
+ text={draftPreviewText(draft())}
+ onOpen={() => {
+ const messageId = props.message.db_id;
+ if (messageId)
+ context.mobileReplyComposer.openForMessage(messageId);
+ }}
+ />
+ </div>
+ )}
+ </Show>
<Show when={showInlineReplyArea()}>
<div class="relative -mx-4 mb-0 border-t border-edge-frame mt-4">
<Show when={props.isLastMessage && !isTouchDevice()}>
diff --git a/apps/web/src/features/email-thread/views/message-list.tsx b/apps/web/src/features/email-thread/views/message-list.tsx
index aa460412ca..9865a4dff1 100644
--- a/apps/web/src/features/email-thread/views/message-list.tsx
+++ b/apps/web/src/features/email-thread/views/message-list.tsx
@@ -174,11 +174,11 @@ export function MessageList(props: MessageListProps) {
});
// A message with an in-progress draft reply stays expanded so the
- // draft remains visible even after newer messages arrive (matches
- // Gmail/Superhuman). Desktop only: mobile edits drafts in a drawer.
+ // draft (inline on desktop, a preview on touch) remains visible
+ // even after newer messages arrive.
const hasDraft = createMemo(() => {
const messageId = message().db_id;
- if (!messageId || viewContext.thread.isTouch()) return false;
+ if (!messageId) return false;
return !!context.drafts.getDraftForMessage(messageId);
});
diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.md
index d15fc6360c..7a42de8e8d 100644
--- a/docs/agent-guide/email.md
+++ b/docs/agent-guide/email.md
@@ -291,6 +291,8 @@ keeps rounded cards matching the chat composer: soft shadows in light mode,
the same subtle 3D rim in dark mode, and a faint hover tint. Desktop selection
does not add an accent-colored ring; keyboard focus has a neutral outline.
Replies appear inline on desktop and in a composer drawer on touch devices.
+On touch, a saved reply shows as a **Draft** row with its opening words under the
+message it answers (which stays expanded); tapping it reopens the draft.
Desktop draft bodies and app-controlled message text use 15px, matching channels.
HTML messages with preserved sender typography retain their explicit sizes.
Desktop reply actions sit together at the bottom right: discard, attach, schedule,