mail page rest

This commit is contained in:
alma 2025-04-21 13:51:41 +02:00
parent f708449a4d
commit 35b5a442dd

View File

@ -767,15 +767,32 @@ export default function MailPage() {
// Update handleEmailSelect to set selectedEmail correctly
const handleEmailSelect = async (emailId: number) => {
try {
// Find the email in the existing emails list
// Find the email in the existing emails list for immediate preview
const emailToSelect = emails.find(email => email.id === emailId);
if (!emailToSelect) {
console.error('Email not found in list');
return;
}
// Set the selected email first to show content immediately
// Set the selected email first to show preview immediately
setSelectedEmail(emailToSelect);
// 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 {
@ -804,7 +821,6 @@ export default function MailPage() {
}
} catch (error) {
console.error('Error marking email as read:', error);
// Don't show error to user since this is a background operation
}
} catch (error) {