compose mime
This commit is contained in:
parent
a629e23a70
commit
fa85613f31
@ -103,20 +103,30 @@ function splitEmailHeadersAndBody(emailBody: string): { headers: string; body: s
|
|||||||
function EmailContent({ email }: { email: Email }) {
|
function EmailContent({ email }: { email: Email }) {
|
||||||
const [content, setContent] = useState<React.ReactNode>(null);
|
const [content, setContent] = useState<React.ReactNode>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
|
|
||||||
async function loadContent() {
|
async function loadContent() {
|
||||||
|
if (!email) return;
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
if (!email.body) {
|
if (!email.body) {
|
||||||
if (mounted) setContent(null);
|
if (mounted) {
|
||||||
|
setContent(null);
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formattedEmail = email.body.trim();
|
const formattedEmail = email.body.trim();
|
||||||
if (!formattedEmail) {
|
if (!formattedEmail) {
|
||||||
if (mounted) setContent(null);
|
if (mounted) {
|
||||||
|
setContent(null);
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,12 +150,14 @@ function EmailContent({ email }: { email: Email }) {
|
|||||||
setContent(null);
|
setContent(null);
|
||||||
}
|
}
|
||||||
setError(null);
|
setError(null);
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error rendering email content:', err);
|
console.error('Error rendering email content:', err);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setError('Error rendering email content. Please try again.');
|
setError('Error rendering email content. Please try again.');
|
||||||
setContent(null);
|
setContent(null);
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +167,15 @@ function EmailContent({ email }: { email: Email }) {
|
|||||||
return () => {
|
return () => {
|
||||||
mounted = false;
|
mounted = false;
|
||||||
};
|
};
|
||||||
}, [email.body]);
|
}, [email?.body]);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center py-8">
|
||||||
|
<div className="animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-blue-500"></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <div className="text-red-500">{error}</div>;
|
return <div className="text-red-500">{error}</div>;
|
||||||
@ -589,8 +609,10 @@ export default function CourrierPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Set the selected email first to show preview immediately
|
// Set the selected email first to show preview immediately
|
||||||
setSelectedEmail(email);
|
setSelectedEmail(email);
|
||||||
|
setContentLoading(true);
|
||||||
|
|
||||||
// Fetch the full email content
|
// Fetch the full email content
|
||||||
const response = await fetch(`/api/mail/${emailId}`);
|
const response = await fetch(`/api/mail/${emailId}`);
|
||||||
@ -603,11 +625,12 @@ export default function CourrierPage() {
|
|||||||
// Update the email in the list and selected email with full content
|
// Update the email in the list and selected email with full content
|
||||||
setEmails(prevEmails => prevEmails.map(email =>
|
setEmails(prevEmails => prevEmails.map(email =>
|
||||||
email.id === emailId
|
email.id === emailId
|
||||||
? { ...email, body: fullEmail.body }
|
? { ...email, body: fullEmail.body || email.body }
|
||||||
: email
|
: email
|
||||||
));
|
));
|
||||||
|
|
||||||
setSelectedEmail(prev => prev ? { ...prev, body: fullEmail.body } : prev);
|
setSelectedEmail(prev => prev ? { ...prev, body: fullEmail.body || prev.body } : prev);
|
||||||
|
setContentLoading(false);
|
||||||
|
|
||||||
// Try to mark as read in the background
|
// Try to mark as read in the background
|
||||||
try {
|
try {
|
||||||
@ -637,6 +660,10 @@ export default function CourrierPage() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error marking email as read:', error);
|
console.error('Error marking email as read:', error);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching email content:', error);
|
||||||
|
setContentLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add these improved handlers
|
// Add these improved handlers
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user