mail page fix design dang

This commit is contained in:
alma 2025-04-21 22:22:20 +02:00
parent 02bfb0cea8
commit da1e18a5ee

View File

@ -686,56 +686,50 @@ export default function CourrierPage() {
// Set the selected email first to show preview immediately // Set the selected email first to show preview immediately
setSelectedEmail(email); setSelectedEmail(email);
// Fetch the full email content
const response = await fetch(`/api/mail/${emailId}`);
if (!response.ok) {
throw new Error('Failed to fetch full email content');
}
const fullEmail = await response.json();
// Update the email in the list and selected email with full content
setEmails(prevEmails => prevEmails.map(email =>
email.id === emailId
? { ...email, body: fullEmail.body }
: email
));
setSelectedEmail(prev => prev ? { ...prev, body: fullEmail.body } : prev);
// Try to mark as read in the background
try { try {
// Fetch the full email content const markReadResponse = await fetch(`/api/mail/mark-read`, {
const response = await fetch(`/api/courrier/email/${emailId}`); method: 'POST',
if (!response.ok) { headers: {
throw new Error('Failed to fetch full email content'); 'Content-Type': 'application/json',
} },
body: JSON.stringify({
const fullEmail = await response.json(); emailId,
isRead: true,
// Update the email in the list and selected email with full content }),
setEmails(prevEmails => prevEmails.map(email => });
email.id === emailId
? { ...email, body: fullEmail.body }
: email
));
setSelectedEmail(prev => prev ? { ...prev, body: fullEmail.body } : prev);
// Try to mark as read in the background if (markReadResponse.ok) {
try { // Only update the emails list if the API call was successful
const markReadResponse = await fetch(`/api/courrier/mark-read`, { setEmails((prevEmails: Email[]) =>
method: 'POST', prevEmails.map((email: Email): Email =>
headers: { email.id === emailId
'Content-Type': 'application/json', ? { ...email, read: true }
}, : email
body: JSON.stringify({ )
emailId, );
isRead: true, } else {
}), console.error('Failed to mark email as read:', await markReadResponse.text());
});
if (markReadResponse.ok) {
// Only update the emails list if the API call was successful
setEmails((prevEmails: Email[]) =>
prevEmails.map((email: Email): Email =>
email.id === emailId
? { ...email, read: true }
: email
)
);
} else {
console.error('Failed to mark email as read:', await markReadResponse.text());
}
} catch (error) {
console.error('Error marking email as read:', error);
} }
} catch (error) { } catch (error) {
console.error('Error fetching full email content:', error); console.error('Error marking email as read:', error);
// If we can't fetch the full content, at least show what we have
setSelectedEmail(email);
} }
}; };
@ -1419,12 +1413,6 @@ export default function CourrierPage() {
const handleReply = (type: 'reply' | 'reply-all' | 'forward') => { const handleReply = (type: 'reply' | 'reply-all' | 'forward') => {
if (!selectedEmail) return; if (!selectedEmail) return;
// Ensure we have the email content
if (!selectedEmail.body) {
console.error('No email content available for reply/forward');
return;
}
const getReplyTo = () => { const getReplyTo = () => {
if (type === 'forward') return ''; if (type === 'forward') return '';
return selectedEmail.from; return selectedEmail.from;