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();
|
const data = await response.json();
|
||||||
console.log('useEmailFetch: Raw API response:', JSON.stringify(data, null, 2));
|
console.log('useEmailFetch: Raw API response:', JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
// Transform the data if needed
|
// Use the data directly as it already has the standardized format from the server
|
||||||
const transformedEmail = {
|
const transformedEmail = data;
|
||||||
...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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// If data contains content as a string or object without isHtml property,
|
console.log('useEmailFetch: Email from API ready to use:', JSON.stringify({
|
||||||
// normalize it to conform to our EmailContent interface
|
id: transformedEmail.id,
|
||||||
if (typeof transformedEmail.content === 'string') {
|
subject: transformedEmail.subject,
|
||||||
// If content is a string, normalize it to the proper structure
|
contentType: typeof transformedEmail.content,
|
||||||
const contentStr = transformedEmail.content;
|
hasIsHtml: transformedEmail.content && 'isHtml' in transformedEmail.content,
|
||||||
transformedEmail.content = {
|
hasDirection: transformedEmail.content && 'direction' in transformedEmail.content
|
||||||
text: contentStr,
|
}, null, 2));
|
||||||
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));
|
|
||||||
|
|
||||||
setState({ email: transformedEmail, loading: false, error: null });
|
setState({ email: transformedEmail, loading: false, error: null });
|
||||||
onEmailLoaded?.(transformedEmail);
|
onEmailLoaded?.(transformedEmail);
|
||||||
|
|||||||
@ -757,7 +757,9 @@ export async function getEmailContent(
|
|||||||
})),
|
})),
|
||||||
content: {
|
content: {
|
||||||
text: parsedEmail.text || '',
|
text: parsedEmail.text || '',
|
||||||
html: rawHtml || ''
|
html: rawHtml || '',
|
||||||
|
isHtml: !!rawHtml,
|
||||||
|
direction: 'ltr' // Default to left-to-right
|
||||||
},
|
},
|
||||||
folder: normalizedFolder,
|
folder: normalizedFolder,
|
||||||
contentFetched: true,
|
contentFetched: true,
|
||||||
|
|||||||
@ -41,6 +41,8 @@ export interface EmailMessage {
|
|||||||
content: {
|
content: {
|
||||||
text: string;
|
text: string;
|
||||||
html: string;
|
html: string;
|
||||||
|
isHtml: boolean; // Whether the email is HTML or plain text
|
||||||
|
direction: string; // Text direction (ltr or rtl)
|
||||||
};
|
};
|
||||||
preview?: string;
|
preview?: string;
|
||||||
date: Date;
|
date: Date;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user