mail page rest

This commit is contained in:
alma 2025-04-21 13:43:30 +02:00
parent cd06672074
commit ada8eb6185

View File

@ -774,7 +774,11 @@ export default function MailPage() {
return; return;
} }
// Mark email as read // Set the selected email first to show content immediately
setSelectedEmail(emailToSelect);
// Try to mark as read in the background
try {
const markReadResponse = await fetch(`/api/mail/mark-read`, { const markReadResponse = await fetch(`/api/mail/mark-read`, {
method: 'POST', method: 'POST',
headers: { headers: {
@ -786,21 +790,22 @@ export default function MailPage() {
}), }),
}); });
if (!markReadResponse.ok) { if (markReadResponse.ok) {
console.error('Failed to mark email as read'); // Only update the emails list if the API call was successful
} setEmails((prevEmails: Email[]) =>
prevEmails.map((email: Email): Email =>
// Update the email in the list to mark it as read
setEmails(prevEmails =>
prevEmails.map(email =>
email.id === emailId email.id === emailId
? { ...email, read: true } ? { ...email, read: true }
: email : email
) )
); );
} else {
// Set the selected email from the existing list console.error('Failed to mark email as read:', await markReadResponse.text());
setSelectedEmail(emailToSelect); }
} catch (error) {
console.error('Error marking email as read:', error);
// Don't show error to user since this is a background operation
}
} catch (error) { } catch (error) {
console.error('Error selecting email:', error); console.error('Error selecting email:', error);