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
|
// Set the selected email first to show preview immediately
|
||||||
setSelectedEmail(email);
|
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 {
|
try {
|
||||||
const markReadResponse = await fetch(`/api/mail/mark-read`, {
|
// Fetch the full email content
|
||||||
method: 'POST',
|
const response = await fetch(`/api/courrier/email/${emailId}`);
|
||||||
headers: {
|
if (!response.ok) {
|
||||||
'Content-Type': 'application/json',
|
throw new Error('Failed to fetch full email content');
|
||||||
},
|
}
|
||||||
body: JSON.stringify({
|
|
||||||
emailId,
|
const fullEmail = await response.json();
|
||||||
isRead: true,
|
|
||||||
}),
|
// 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) {
|
// Try to mark as read in the background
|
||||||
// Only update the emails list if the API call was successful
|
try {
|
||||||
setEmails((prevEmails: Email[]) =>
|
const markReadResponse = await fetch(`/api/courrier/mark-read`, {
|
||||||
prevEmails.map((email: Email): Email =>
|
method: 'POST',
|
||||||
email.id === emailId
|
headers: {
|
||||||
? { ...email, read: true }
|
'Content-Type': 'application/json',
|
||||||
: email
|
},
|
||||||
)
|
body: JSON.stringify({
|
||||||
);
|
emailId,
|
||||||
} else {
|
isRead: true,
|
||||||
console.error('Failed to mark email as read:', await markReadResponse.text());
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
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) {
|
} 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') => {
|
const handleReply = (type: 'reply' | 'reply-all' | 'forward') => {
|
||||||
if (!selectedEmail) return;
|
if (!selectedEmail) return;
|
||||||
|
|
||||||
|
// Ensure we have the email content
|
||||||
|
if (!selectedEmail.body) {
|
||||||
|
console.error('No email content available for reply/forward');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const getReplyTo = () => {
|
const getReplyTo = () => {
|
||||||
if (type === 'forward') return '';
|
if (type === 'forward') return '';
|
||||||
return selectedEmail.from;
|
return selectedEmail.from;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user