mail page rest
This commit is contained in:
parent
f708449a4d
commit
35b5a442dd
@ -767,16 +767,33 @@ export default function MailPage() {
|
|||||||
// Update handleEmailSelect to set selectedEmail correctly
|
// Update handleEmailSelect to set selectedEmail correctly
|
||||||
const handleEmailSelect = async (emailId: number) => {
|
const handleEmailSelect = async (emailId: number) => {
|
||||||
try {
|
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);
|
const emailToSelect = emails.find(email => email.id === emailId);
|
||||||
if (!emailToSelect) {
|
if (!emailToSelect) {
|
||||||
console.error('Email not found in list');
|
console.error('Email not found in list');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the selected email first to show content immediately
|
// Set the selected email first to show preview immediately
|
||||||
setSelectedEmail(emailToSelect);
|
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 to mark as read in the background
|
||||||
try {
|
try {
|
||||||
const markReadResponse = await fetch(`/api/mail/mark-read`, {
|
const markReadResponse = await fetch(`/api/mail/mark-read`, {
|
||||||
@ -804,7 +821,6 @@ export default function MailPage() {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error marking email as read:', 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) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user