panel 2 courier api

This commit is contained in:
alma 2025-04-25 16:57:58 +02:00
parent 7269d4a07d
commit f573d79960

View File

@ -101,8 +101,9 @@ function splitEmailHeadersAndBody(emailBody: string): { headers: string; body: s
}
function EmailContent({ email }: { email: Email }) {
// Add debugging logs
console.log("EmailContent rendering with:", {
// Improved debugging with more details
console.log("EmailContent rendering with EMAIL OBJECT:", email);
console.log("Content details:", {
hasContent: Boolean(email.content),
contentLength: email.content?.length || 0,
hasTextContent: Boolean(email.textContent),
@ -164,8 +165,19 @@ function EmailContent({ email }: { email: Email }) {
);
}
// Last resort
return <div className="text-gray-500">No content available</div>;
// Last resort - show a better error message with debugging info
return (
<div className="text-gray-500">
<p>No content available</p>
<div className="mt-2 p-2 bg-red-50 text-red-700 text-xs rounded">
<p>Content flags:</p>
<p>- Has content: {hasContent ? 'Yes' : 'No'}</p>
<p>- Has text content: {hasTextContent ? 'Yes' : 'No'}</p>
<p>- Has raw content: {hasRawContent ? 'Yes' : 'No'}</p>
<p>- Has body: {hasBody ? 'Yes' : 'No'}</p>
</div>
</div>
);
}
function renderEmailContent(email: Email) {
@ -629,17 +641,27 @@ export default function CourrierPage() {
const fullEmail = await response.json();
console.log("API RESPONSE for email:", JSON.stringify(fullEmail, null, 2));
// Create a safe version of the email with guaranteed fields
const safeEmail = {
// Create a clean, processed version of the email ensuring all necessary fields exist
const processedEmail = {
...fullEmail,
content: fullEmail.content || "",
textContent: fullEmail.textContent || "",
rawContent: fullEmail.rawContent || "",
body: fullEmail.body || ""
id: fullEmail.id || emailId,
content: typeof fullEmail.content === 'string' ? fullEmail.content : '',
textContent: typeof fullEmail.textContent === 'string' ? fullEmail.textContent : '',
rawContent: typeof fullEmail.rawContent === 'string' ? fullEmail.rawContent : '',
body: typeof fullEmail.body === 'string' ? fullEmail.body : '',
from: fullEmail.from || initialEmail?.from || '',
fromName: fullEmail.fromName || initialEmail?.fromName || '',
to: fullEmail.to || initialEmail?.to || '',
subject: fullEmail.subject || initialEmail?.subject || '(No subject)',
date: fullEmail.date || initialEmail?.date || new Date().toISOString(),
read: fullEmail.read !== undefined ? fullEmail.read : true,
folder: fullEmail.folder || currentView
};
console.log("Processed email for UI:", processedEmail);
// Set the selected email with complete information
setSelectedEmail(safeEmail);
setSelectedEmail(processedEmail);
// Update the email in the list to mark it as read
setEmails((prevEmails) =>
@ -1036,9 +1058,16 @@ export default function CourrierPage() {
<div className="flex justify-between items-center mb-2">
<h4 className="text-xs font-medium text-blue-800">Direct Content Preview</h4>
</div>
<div className="text-xs overflow-auto max-h-20">
<strong>Content:</strong> {selectedEmail.content ? selectedEmail.content.substring(0, 200) : 'Empty'}<br/>
<strong>Text Content:</strong> {selectedEmail.textContent ? selectedEmail.textContent.substring(0, 200) : 'Empty'}<br/>
<div className="text-xs overflow-auto max-h-[300px]">
<strong>Content:</strong> {selectedEmail.content
? <div className="mt-1 p-1 bg-white/80 rounded overflow-auto max-h-[100px]">{selectedEmail.content.substring(0, 500)}...</div>
: 'Empty'}<br/>
<strong>Text Content:</strong> {selectedEmail.textContent
? <div className="mt-1 p-1 bg-white/80 rounded overflow-auto max-h-[100px]">{selectedEmail.textContent.substring(0, 500)}...</div>
: 'Empty'}<br/>
<strong>Raw Content:</strong> {selectedEmail.rawContent
? <div className="mt-1 p-1 bg-white/80 rounded overflow-auto max-h-[100px]">{selectedEmail.rawContent.substring(0, 500)}...</div>
: 'Empty'}<br/>
</div>
</div>