courrier multi account restore compose
This commit is contained in:
parent
1dac8ec1aa
commit
202a0e07d8
@ -269,14 +269,17 @@ export const useCourrier = () => {
|
|||||||
}, [currentFolder, page, perPage, session?.user?.id, loadEmails]);
|
}, [currentFolder, page, perPage, session?.user?.id, loadEmails]);
|
||||||
|
|
||||||
// Fetch a single email's content
|
// Fetch a single email's content
|
||||||
const fetchEmailContent = useCallback(async (emailId: string) => {
|
const fetchEmailContent = useCallback(async (emailId: string, accountId?: string, folderOverride?: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/courrier/${emailId}?folder=${encodeURIComponent(currentFolder)}`);
|
const folderToUse = folderOverride || currentFolder;
|
||||||
|
const query = new URLSearchParams({
|
||||||
|
folder: folderToUse,
|
||||||
|
});
|
||||||
|
if (accountId) query.set('accountId', accountId);
|
||||||
|
const response = await fetch(`/api/courrier/${emailId}?${query.toString()}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to fetch email content: ${response.status}`);
|
throw new Error(`Failed to fetch email content: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -286,21 +289,17 @@ export const useCourrier = () => {
|
|||||||
}, [currentFolder]);
|
}, [currentFolder]);
|
||||||
|
|
||||||
// Select an email to view
|
// Select an email to view
|
||||||
const handleEmailSelect = useCallback(async (emailId: string) => {
|
const handleEmailSelect = useCallback(async (emailId: string, accountId?: string, folderOverride?: string) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Find the email in the current list
|
// Find the email in the current list
|
||||||
const email = emails.find(e => e.id === emailId);
|
const email = emails.find(e => e.id === emailId && (!accountId || e.accountId === accountId) && (!folderOverride || e.folder === folderOverride));
|
||||||
|
|
||||||
if (!email) {
|
if (!email) {
|
||||||
throw new Error('Email not found');
|
throw new Error('Email not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If content is not fetched, get the full content
|
// If content is not fetched, get the full content
|
||||||
if (!email.contentFetched) {
|
if (!email.contentFetched) {
|
||||||
const fullEmail = await fetchEmailContent(emailId);
|
const fullEmail = await fetchEmailContent(emailId, accountId, folderOverride);
|
||||||
|
|
||||||
// Merge the full content with the email
|
// Merge the full content with the email
|
||||||
const updatedEmail = {
|
const updatedEmail = {
|
||||||
...email,
|
...email,
|
||||||
@ -308,14 +307,12 @@ export const useCourrier = () => {
|
|||||||
attachments: fullEmail.attachments,
|
attachments: fullEmail.attachments,
|
||||||
contentFetched: true
|
contentFetched: true
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update the email in the list
|
// Update the email in the list
|
||||||
setEmails(emails.map(e => e.id === emailId ? updatedEmail : e));
|
setEmails(emails.map(e => e.id === emailId ? updatedEmail : e));
|
||||||
setSelectedEmail(updatedEmail);
|
setSelectedEmail(updatedEmail);
|
||||||
} else {
|
} else {
|
||||||
setSelectedEmail(email);
|
setSelectedEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the email as read if it's not already
|
// Mark the email as read if it's not already
|
||||||
if (!email.flags.seen) {
|
if (!email.flags.seen) {
|
||||||
markEmailAsRead(emailId, true);
|
markEmailAsRead(emailId, true);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user