From 35b5a442dd65a35f9cc37dda0a50038695b9e023 Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 21 Apr 2025 13:51:41 +0200 Subject: [PATCH] mail page rest --- app/courrier/page.tsx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 76041647..655c359f 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -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) {