mail page fix design dang
This commit is contained in:
parent
d0161fadae
commit
02bfb0cea8
@ -686,50 +686,56 @@ export default function CourrierPage() {
|
||||
// Set the selected email first to show preview immediately
|
||||
setSelectedEmail(email);
|
||||
|
||||
// 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 {
|
||||
const markReadResponse = await fetch(`/api/mail/mark-read`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
emailId,
|
||||
isRead: true,
|
||||
}),
|
||||
});
|
||||
// Fetch the full email content
|
||||
const response = await fetch(`/api/courrier/email/${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);
|
||||
|
||||
if (markReadResponse.ok) {
|
||||
// Only update the emails list if the API call was successful
|
||||
setEmails((prevEmails: Email[]) =>
|
||||
prevEmails.map((email: Email): Email =>
|
||||
email.id === emailId
|
||||
? { ...email, read: true }
|
||||
: email
|
||||
)
|
||||
);
|
||||
} else {
|
||||
console.error('Failed to mark email as read:', await markReadResponse.text());
|
||||
// Try to mark as read in the background
|
||||
try {
|
||||
const markReadResponse = await fetch(`/api/courrier/mark-read`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
emailId,
|
||||
isRead: true,
|
||||
}),
|
||||
});
|
||||
|
||||
if (markReadResponse.ok) {
|
||||
// Only update the emails list if the API call was successful
|
||||
setEmails((prevEmails: Email[]) =>
|
||||
prevEmails.map((email: Email): Email =>
|
||||
email.id === emailId
|
||||
? { ...email, read: true }
|
||||
: email
|
||||
)
|
||||
);
|
||||
} else {
|
||||
console.error('Failed to mark email as read:', await markReadResponse.text());
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error marking email as read:', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error marking email as read:', error);
|
||||
console.error('Error fetching full email content:', error);
|
||||
// If we can't fetch the full content, at least show what we have
|
||||
setSelectedEmail(email);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1413,6 +1419,12 @@ export default function CourrierPage() {
|
||||
const handleReply = (type: 'reply' | 'reply-all' | 'forward') => {
|
||||
if (!selectedEmail) return;
|
||||
|
||||
// Ensure we have the email content
|
||||
if (!selectedEmail.body) {
|
||||
console.error('No email content available for reply/forward');
|
||||
return;
|
||||
}
|
||||
|
||||
const getReplyTo = () => {
|
||||
if (type === 'forward') return '';
|
||||
return selectedEmail.from;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user