mail page rest

This commit is contained in:
alma 2025-04-21 13:39:45 +02:00
parent 6e7c9013a5
commit cd06672074

View File

@ -767,6 +767,13 @@ export default function MailPage() {
// Update handleEmailSelect to set selectedEmail correctly
const handleEmailSelect = async (emailId: number) => {
try {
// Find the email in the existing emails list
const emailToSelect = emails.find(email => email.id === emailId);
if (!emailToSelect) {
console.error('Email not found in list');
return;
}
// Mark email as read
const markReadResponse = await fetch(`/api/mail/mark-read`, {
method: 'POST',
@ -783,25 +790,17 @@ export default function MailPage() {
console.error('Failed to mark email as read');
}
// Fetch full email content
const response = await fetch(`/api/mail/${emailId}?folder=${currentView}`);
if (!response.ok) {
throw new Error('Failed to fetch email content');
}
const fullEmail = await response.json();
// Update the email in the list with full content
// Update the email in the list to mark it as read
setEmails(prevEmails =>
prevEmails.map(email =>
email.id === emailId
? { ...email, ...fullEmail, read: true }
? { ...email, read: true }
: email
)
);
// Update selected email
setSelectedEmail(fullEmail);
// Set the selected email from the existing list
setSelectedEmail(emailToSelect);
} catch (error) {
console.error('Error selecting email:', error);