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]);
|
||||
|
||||
// Fetch a single email's content
|
||||
const fetchEmailContent = useCallback(async (emailId: string) => {
|
||||
const fetchEmailContent = useCallback(async (emailId: string, accountId?: string, folderOverride?: string) => {
|
||||
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) {
|
||||
throw new Error(`Failed to fetch email content: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
@ -286,21 +289,17 @@ export const useCourrier = () => {
|
||||
}, [currentFolder]);
|
||||
|
||||
// Select an email to view
|
||||
const handleEmailSelect = useCallback(async (emailId: string) => {
|
||||
const handleEmailSelect = useCallback(async (emailId: string, accountId?: string, folderOverride?: string) => {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
// 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) {
|
||||
throw new Error('Email not found');
|
||||
}
|
||||
|
||||
// If content is not fetched, get the full content
|
||||
if (!email.contentFetched) {
|
||||
const fullEmail = await fetchEmailContent(emailId);
|
||||
|
||||
const fullEmail = await fetchEmailContent(emailId, accountId, folderOverride);
|
||||
// Merge the full content with the email
|
||||
const updatedEmail = {
|
||||
...email,
|
||||
@ -308,14 +307,12 @@ export const useCourrier = () => {
|
||||
attachments: fullEmail.attachments,
|
||||
contentFetched: true
|
||||
};
|
||||
|
||||
// Update the email in the list
|
||||
setEmails(emails.map(e => e.id === emailId ? updatedEmail : e));
|
||||
setSelectedEmail(updatedEmail);
|
||||
} else {
|
||||
setSelectedEmail(email);
|
||||
}
|
||||
|
||||
// Mark the email as read if it's not already
|
||||
if (!email.flags.seen) {
|
||||
markEmailAsRead(emailId, true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user