Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions js/app/packages/block-email/component/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,7 @@ export function BaseInput(props: {
!hasDraftContent(
prepared.bodyText,
form().subject(),
form().attachments.list().length,
form().recipients().to.length +
form().recipients().cc.length +
form().recipients().bcc.length
form().attachments.list().length
)
) {
return null;
Expand All @@ -720,6 +717,7 @@ export function BaseInput(props: {
if (draftId) {
await deleteDraftMutation.mutateAsync({
draftId,
threadId: ctx.thread()?.db_id,
linkId: headerLinkId(),
});
refetchThreadMessages();
Expand Down Expand Up @@ -1092,6 +1090,7 @@ export function BaseInput(props: {
if (draftId) {
await deleteDraftMutation.mutateAsync({
draftId,
threadId: ctx.thread()?.db_id,
linkId: headerLinkId(),
});
refetchThreadMessages();
Expand Down
2 changes: 2 additions & 0 deletions js/app/packages/block-email/component/compose/Compose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export function EmailCompose(props: EmailComposeProps) {
if (draftID) {
await deleteDraftMutation.mutateAsync({
draftId: draftID,
threadId: currentThreadID(),
linkId: headerLinkId(),
});
}
Expand Down Expand Up @@ -602,6 +603,7 @@ export function EmailCompose(props: EmailComposeProps) {
if (draftId) {
await deleteDraftMutation.mutateAsync({
draftId,
threadId: currentThreadID(),
linkId: headerLinkId(),
});
}
Expand Down
4 changes: 3 additions & 1 deletion js/app/packages/block-email/util/prepareEmailBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ export function prepareEmailBody(

/**
* Returns true if the draft has meaningful user content worth saving.
* Auto-filled reply/forward subjects alone don't count.
* Auto-filled reply/forward subjects alone don't count. Pass recipientCount
* only when recipients are user-entered (compose) and should keep the draft
* alive — reply recipients are auto-derived, so the reply path omits it.
*/
export function hasDraftContent(
bodyText: string,
Expand Down
12 changes: 10 additions & 2 deletions js/app/packages/queries/email/draft.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toast } from '@core/component/Toast/Toast';
import { throwOnErr } from '@core/util/result';
import { invalidateSoupEntity, refetchSoupEntity } from '@queries/soup/cache';
import { refetchSoupEntity } from '@queries/soup/cache';
import { emailClient } from '@service-email/client';
import type {
ApiDraftInput,
Expand Down Expand Up @@ -64,6 +64,8 @@ export function useSaveDraftMutation(

type DeleteDraftParams = {
draftId: string;
/** Thread the draft belonged to, refetched so it leaves the drafts tab. */
threadId?: string;
/** Target inbox for a non-primary inbox; sent as the X-Email-Link-Id header. */
linkId?: string;
};
Expand Down Expand Up @@ -91,7 +93,13 @@ export function useDeleteDraftMutation(
queryClient.invalidateQueries({
queryKey: emailKeys.previews._def,
});
invalidateSoupEntity(vars.draftId);
// Refetch the thread (not the deleted draft) so it drops from the
// drafts tab without a manual refresh. No-op for compose drafts,
// whose thread is deleted along with the draft, so the refetch
// finds nothing to update.
if (vars.threadId) {
refetchSoupEntity(vars.threadId, 'emailThread');
}
},
},
callbacks
Expand Down
Loading