fix(pro): show Edit button on draft emails opened in a new tab
This commit is contained in:
committed by
Linus Rath
parent
2704d5dc23
commit
16daf6ea03
@@ -6,6 +6,7 @@ import { EmailViewer } from "@/components/email/email-viewer";
|
|||||||
import { ErrorBoundary, EmailViewerErrorFallback } from "@/components/error";
|
import { ErrorBoundary, EmailViewerErrorFallback } from "@/components/error";
|
||||||
import { useAuthStore } from "@/stores/auth-store";
|
import { useAuthStore } from "@/stores/auth-store";
|
||||||
import { useEmailStore } from "@/stores/email-store";
|
import { useEmailStore } from "@/stores/email-store";
|
||||||
|
import { useIdentityStore } from "@/stores/identity-store";
|
||||||
import { useSettingsStore } from "@/stores/settings-store";
|
import { useSettingsStore } from "@/stores/settings-store";
|
||||||
import { toast } from "@/stores/toast-store";
|
import { toast } from "@/stores/toast-store";
|
||||||
import { useProTabStore, type ProEmailTabData, type ProReplyContext } from "@/stores/pro-tab-store";
|
import { useProTabStore, type ProEmailTabData, type ProReplyContext } from "@/stores/pro-tab-store";
|
||||||
@@ -56,6 +57,7 @@ export function ProEmailTabBody({ tabId, data }: ProEmailTabBodyProps) {
|
|||||||
const setEmailKeywordsLocal = useEmailStore((s) => s.setEmailKeywordsLocal);
|
const setEmailKeywordsLocal = useEmailStore((s) => s.setEmailKeywordsLocal);
|
||||||
const mailboxes = useEmailStore((s) => s.mailboxes);
|
const mailboxes = useEmailStore((s) => s.mailboxes);
|
||||||
const settingsKeywords = useSettingsStore((s) => s.emailKeywords);
|
const settingsKeywords = useSettingsStore((s) => s.emailKeywords);
|
||||||
|
const identities = useIdentityStore((s) => s.identities);
|
||||||
|
|
||||||
const closeTab = useProTabStore((s) => s.closeTab);
|
const closeTab = useProTabStore((s) => s.closeTab);
|
||||||
const openComposeTab = useProTabStore((s) => s.openComposeTab);
|
const openComposeTab = useProTabStore((s) => s.openComposeTab);
|
||||||
@@ -227,6 +229,44 @@ export function ProEmailTabBody({ tabId, data }: ProEmailTabBodyProps) {
|
|||||||
handleReply(body);
|
handleReply(body);
|
||||||
}, [handleReply]);
|
}, [handleReply]);
|
||||||
|
|
||||||
|
const handleEditDraft = useCallback(() => {
|
||||||
|
if (!email) return;
|
||||||
|
|
||||||
|
const bodyText = email.bodyValues
|
||||||
|
? Object.values(email.bodyValues).map((v) => v.value).join('\n')
|
||||||
|
: '';
|
||||||
|
const htmlBody = email.htmlBody?.[0]?.partId && email.bodyValues?.[email.htmlBody[0].partId]
|
||||||
|
? email.bodyValues[email.htmlBody[0].partId].value
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
// Preserve the identity that matches the draft's From address.
|
||||||
|
const draftFromEmail = email.from?.[0]?.email;
|
||||||
|
const matchedIdentity = draftFromEmail
|
||||||
|
? identities.find((id) => id.email === draftFromEmail)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
composerSessionIdRef.current += 1;
|
||||||
|
openComposeTab({
|
||||||
|
sessionId: composerSessionIdRef.current,
|
||||||
|
mode: 'compose',
|
||||||
|
title: email.subject || t('email_composer.new_message'),
|
||||||
|
initialData: {
|
||||||
|
to: email.to?.map((a) => a.email).filter(Boolean).join(', ') || '',
|
||||||
|
cc: email.cc?.map((a) => a.email).filter(Boolean).join(', ') || '',
|
||||||
|
bcc: email.bcc?.map((a) => a.email).filter(Boolean).join(', ') || '',
|
||||||
|
subject: email.subject || '',
|
||||||
|
body: htmlBody || bodyText,
|
||||||
|
showCc: (email.cc?.length || 0) > 0,
|
||||||
|
showBcc: (email.bcc?.length || 0) > 0,
|
||||||
|
selectedIdentityId: matchedIdentity?.id ?? null,
|
||||||
|
subAddressTag: '',
|
||||||
|
mode: 'compose',
|
||||||
|
draftId: email.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
closeTab(tabId);
|
||||||
|
}, [email, identities, openComposeTab, closeTab, tabId, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full flex-col bg-background">
|
<div className="flex h-full w-full flex-col bg-background">
|
||||||
<ErrorBoundary fallback={EmailViewerErrorFallback}>
|
<ErrorBoundary fallback={EmailViewerErrorFallback}>
|
||||||
@@ -243,6 +283,7 @@ export function ProEmailTabBody({ tabId, data }: ProEmailTabBodyProps) {
|
|||||||
onSetColorTag={handleSetColorTag}
|
onSetColorTag={handleSetColorTag}
|
||||||
onDownloadAttachment={handleDownloadAttachment}
|
onDownloadAttachment={handleDownloadAttachment}
|
||||||
onQuickReply={handleQuickReply}
|
onQuickReply={handleQuickReply}
|
||||||
|
onEditDraft={handleEditDraft}
|
||||||
onMoveToMailbox={handleMoveToMailbox}
|
onMoveToMailbox={handleMoveToMailbox}
|
||||||
currentUserEmail={client?.getUsername()}
|
currentUserEmail={client?.getUsername()}
|
||||||
currentUserName={client?.getUsername()?.split('@')[0]}
|
currentUserName={client?.getUsername()?.split('@')[0]}
|
||||||
|
|||||||
Reference in New Issue
Block a user