Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
style(email): Improved draft saving experience (#1917)
Evan Hutnik7e4b21969674
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsxindex abb5c2582f..735812383d 100644--- a/js/app/packages/block-email/component/BaseInput.tsx+++ b/js/app/packages/block-email/component/BaseInput.tsx@@ -578,11 +578,11 @@ export function BaseInput(props: {);return null;}- // Fail if no body text and no attachments- // You can have a draft with attachments and no body text+ // Fail if no body text, no attachments, and no subjectif (prepared.bodyText.trim() === '' &&- form().attachments.list().length === 0+ form().attachments.list().length === 0 &&+ !form().subject()?.trim()) {return null;}@@ -702,6 +702,13 @@ export function BaseInput(props: {}, DRAFT_DEBOUNCE_MS);}+ const withDraftSave =+ <T,>(setter: (v: T) => void) =>+ (v: T) => {+ setter(v);+ scheduleDraftSave();+ };+// We are consuming the first change, because it is the initial valuelet firstChangeConsumed = false;const handleChange = (value: string) => {@@ -1128,12 +1135,6 @@ export function BaseInput(props: {};const isDraftSaving = () => saveDraftMutation.isPending;-- // Used to keep displaying draft status for some time- const debouncedIsDraftSaving = stickyGate(isDraftSaving, 2000);-- // Used to keep displaying spinner for a short time before switching- // to saved stateconst laggedIsDraftSaving = stickyGate(isDraftSaving, 250);return (@@ -1222,7 +1223,9 @@ export function BaseInput(props: {inputRef={setToRef}options={ctx.recipientOptions}selectedOptions={form().recipients().to}- setSelectedOptions={(v) => form().setRecipients('to', v)}+ setSelectedOptions={withDraftSave((v) =>+ form().setRecipients('to', v)+ )}triggerMode="input"hideBorder/>@@ -1235,7 +1238,9 @@ export function BaseInput(props: {inputRef={setCcRef}options={ctx.recipientOptions}selectedOptions={form().recipients().cc}- setSelectedOptions={(v) => form().setRecipients('cc', v)}+ setSelectedOptions={withDraftSave((v) =>+ form().setRecipients('cc', v)+ )}triggerMode="input"hideBorder/>@@ -1249,7 +1254,9 @@ export function BaseInput(props: {inputRef={setBccRef}options={ctx.recipientOptions}selectedOptions={form().recipients().bcc}- setSelectedOptions={(v) => form().setRecipients('bcc', v)}+ setSelectedOptions={withDraftSave((v) =>+ form().setRecipients('bcc', v)+ )}triggerMode="input"hideBorder/>@@ -1286,17 +1293,6 @@ export function BaseInput(props: {</div></div></Show>- <Show when={debouncedIsDraftSaving()}>- <div class="absolute right-4 top-4 flex gap-1 items-center text-xs text-ink-muted">- <Show- when={laggedIsDraftSaving()}- fallback={<span>Draft saved</span>}- >- <Spinner class="size-4 animate-spin" />- <span>Saving draft</span>- </Show>- </div>- </Show></div><divclass={`${props.isEditingExisting || props.newMessage ? 'flex' : 'hidden'} flex-row items-center`}@@ -1519,7 +1515,7 @@ export function BaseInput(props: {onSendTimeChange={handleSendTimeChange}/></Show>- <Show when={savedDraftId()}>+ <Show when={savedDraftId() && !laggedIsDraftSaving()}><Buttononclick={deleteDraftAndReset}tooltip="Delete draft"@@ -1528,6 +1524,11 @@ export function BaseInput(props: {<Trash class="h-5" /></Button></Show>+ <Show when={laggedIsDraftSaving()}>+ <div class="aspect-square p-1 flex items-center justify-center">+ <Spinner class="size-5 animate-spin text-ink-muted" />+ </div>+ </Show></div><Buttondiff --git a/js/app/packages/block-email/component/Compose.tsx b/js/app/packages/block-email/component/Compose.tsxindex 09d0c7c9fe..dc454b4535 100644--- a/js/app/packages/block-email/component/Compose.tsx+++ b/js/app/packages/block-email/component/Compose.tsx@@ -227,11 +227,11 @@ export function EmailCompose(props: EmailComposeProps) {);return null;}- // Fail if no body text and no attachments- // You can have a draft with attachments and no body text+ // Fail if no body text, no attachments, and no subjectif (prepared.bodyText.trim() === '' &&- form.attachments.list().length === 0+ form.attachments.list().length === 0 &&+ !form.subject()?.trim()) {return null;}@@ -310,6 +310,13 @@ export function EmailCompose(props: EmailComposeProps) {void executeSaveDraft();}, DRAFT_DEBOUNCE_MS);+ const withDraftSave =+ <T,>(setter: (v: T) => void) =>+ (v: T) => {+ setter(v);+ scheduleDraftSave();+ };+const onAddAttachments = (attachments: DraftFormAttachment[]) => {for (const attachment of attachments) {form.attachments.add(attachment);@@ -748,11 +755,6 @@ export function EmailCompose(props: EmailComposeProps) {const isDraftSaving = () => saveDraftMutation.isPending;- // Used to keep displaying draft status for some time- const debouncedIsDraftSaving = stickyGate(isDraftSaving, 2000);-- // Used to keep displaying spinner for a short time before switching- // to saved stateconst laggedIsDraftSaving = stickyGate(isDraftSaving, 250);return (@@ -853,17 +855,6 @@ export function EmailCompose(props: EmailComposeProps) {</Show></Suspense><div class="flex gap-2 ml-auto">- <Show when={debouncedIsDraftSaving()}>- <div class="flex gap-1 items-center text-ink-muted">- <Show- when={laggedIsDraftSaving()}- fallback={<span>Draft saved</span>}- >- <CircleSpinner class="size-4 animate-spin" />- <span>Saving draft</span>- </Show>- </div>- </Show><Show when={!isCcVisible()}><buttontype="button"@@ -893,9 +884,9 @@ export function EmailCompose(props: EmailComposeProps) {inputRef={registerRef('directRecipientsSelector')}options={getRecipientOptions}selectedOptions={form.recipients().to}- setSelectedOptions={(next) =>+ setSelectedOptions={withDraftSave((next) =>form.setRecipients('to', next)- }+ )}placeholder="Macro users or email addresses"focusOnMount={!hasLinkError()}hideBorder@@ -917,9 +908,9 @@ export function EmailCompose(props: EmailComposeProps) {inputRef={registerRef('ccRecipientsSelector')}options={getRecipientOptions}selectedOptions={form.recipients().cc}- setSelectedOptions={(next) =>+ setSelectedOptions={withDraftSave((next) =>form.setRecipients('cc', next)- }+ )}placeholder="Macro users or email addresses"hideBordernoBrackets@@ -934,9 +925,9 @@ export function EmailCompose(props: EmailComposeProps) {inputRef={registerRef('bccRecipientsSelector')}options={getRecipientOptions}selectedOptions={form.recipients().bcc}- setSelectedOptions={(next) =>+ setSelectedOptions={withDraftSave((next) =>form.setRecipients('bcc', next)- }+ )}placeholder="Macro users or email addresses"hideBordernoBrackets@@ -993,6 +984,7 @@ export function EmailCompose(props: EmailComposeProps) {onSendTimeChange={handleSendTimeChange}onSubmit={() => void onSubmit()}isSubmitting={sendMutation.isPending}+ isDraftSaving={laggedIsDraftSaving()}hasDraft={currentDraftID() != null}onDraftDeletePress={deleteDraftAndReset}disabled={hasLinkError() || sendMutation.isPending}diff --git a/js/app/packages/block-email/component/ComposeEmailInput.tsx b/js/app/packages/block-email/component/ComposeEmailInput.tsxindex 59b408a2fa..018e5b8f55 100644--- a/js/app/packages/block-email/component/ComposeEmailInput.tsx+++ b/js/app/packages/block-email/component/ComposeEmailInput.tsx@@ -63,6 +63,7 @@ type ComposeEmailInputProps = {isSubmitting?: boolean;hasDraft?: boolean;onDraftDeletePress?: VoidFunction;+ isDraftSaving?: boolean;attachments?: DraftFormAttachment[];initialHtml?: string;onAddAttachments?: (attachments: DraftFormAttachment[]) => void;@@ -396,7 +397,7 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {onSendTimeChange={props.onSendTimeChange}/></Show>- <Show when={props.hasDraft}>+ <Show when={props.hasDraft && !props.isDraftSaving}><Buttononclick={props.onDraftDeletePress}tooltip="Delete draft"@@ -405,6 +406,11 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {<Trash /></Button></Show>+ <Show when={props.isDraftSaving}>+ <div class="aspect-square p-1 flex items-center justify-center">+ <Spinner class="size-5 animate-spin text-ink-muted" />+ </div>+ </Show></div><Button