courrier preview
This commit is contained in:
parent
2113c27a68
commit
9cde8ac9d0
@ -77,47 +77,16 @@ export function useEmailFetch({ onEmailLoaded, onError }: UseEmailFetchProps = {
|
||||
const data = await response.json();
|
||||
console.log('useEmailFetch: Raw API response:', JSON.stringify(data, null, 2));
|
||||
|
||||
// Transform the data if needed
|
||||
const transformedEmail = {
|
||||
...data,
|
||||
// Create a proper content object that includes all required fields
|
||||
content: data.content || {
|
||||
text: data.text || '',
|
||||
html: data.html || '',
|
||||
isHtml: !!data.html, // Set isHtml based on whether html exists
|
||||
direction: 'ltr' // Default to left-to-right
|
||||
}
|
||||
};
|
||||
// Use the data directly as it already has the standardized format from the server
|
||||
const transformedEmail = data;
|
||||
|
||||
// If data contains content as a string or object without isHtml property,
|
||||
// normalize it to conform to our EmailContent interface
|
||||
if (typeof transformedEmail.content === 'string') {
|
||||
// If content is a string, normalize it to the proper structure
|
||||
const contentStr = transformedEmail.content;
|
||||
transformedEmail.content = {
|
||||
text: contentStr,
|
||||
html: contentStr.startsWith('<') ? contentStr : undefined,
|
||||
isHtml: contentStr.startsWith('<'),
|
||||
direction: 'ltr'
|
||||
};
|
||||
console.log('useEmailFetch: Normalized string content to object');
|
||||
} else if (transformedEmail.content && typeof transformedEmail.content === 'object') {
|
||||
// Ensure the content object has all required fields
|
||||
if (!('isHtml' in transformedEmail.content)) {
|
||||
transformedEmail.content.isHtml = !!transformedEmail.content.html;
|
||||
console.log('useEmailFetch: Added missing isHtml field to content');
|
||||
}
|
||||
if (!('direction' in transformedEmail.content)) {
|
||||
transformedEmail.content.direction = 'ltr';
|
||||
console.log('useEmailFetch: Added missing direction field to content');
|
||||
}
|
||||
if (!('text' in transformedEmail.content) && !transformedEmail.content.text) {
|
||||
transformedEmail.content.text = '';
|
||||
console.log('useEmailFetch: Added missing text field to content');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('useEmailFetch: Transformed email:', JSON.stringify(transformedEmail, null, 2));
|
||||
console.log('useEmailFetch: Email from API ready to use:', JSON.stringify({
|
||||
id: transformedEmail.id,
|
||||
subject: transformedEmail.subject,
|
||||
contentType: typeof transformedEmail.content,
|
||||
hasIsHtml: transformedEmail.content && 'isHtml' in transformedEmail.content,
|
||||
hasDirection: transformedEmail.content && 'direction' in transformedEmail.content
|
||||
}, null, 2));
|
||||
|
||||
setState({ email: transformedEmail, loading: false, error: null });
|
||||
onEmailLoaded?.(transformedEmail);
|
||||
|
||||
@ -757,7 +757,9 @@ export async function getEmailContent(
|
||||
})),
|
||||
content: {
|
||||
text: parsedEmail.text || '',
|
||||
html: rawHtml || ''
|
||||
html: rawHtml || '',
|
||||
isHtml: !!rawHtml,
|
||||
direction: 'ltr' // Default to left-to-right
|
||||
},
|
||||
folder: normalizedFolder,
|
||||
contentFetched: true,
|
||||
|
||||
@ -41,6 +41,8 @@ export interface EmailMessage {
|
||||
content: {
|
||||
text: string;
|
||||
html: string;
|
||||
isHtml: boolean; // Whether the email is HTML or plain text
|
||||
direction: string; // Text direction (ltr or rtl)
|
||||
};
|
||||
preview?: string;
|
||||
date: Date;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user