fix: list the folders in the import dialog when it opens from Settings

This commit is contained in:
Linus Rath
2026-11-01 05:42:00 +01:00
parent dd1e0e0b13
commit 58f66c4fdc
2 changed files with 22 additions and 0 deletions
@@ -71,6 +71,17 @@ describe('MailImportDialog', () => {
expect(startImport).toHaveBeenCalledWith(expect.objectContaining({ accountId: 'acc1', targetMailboxId: null, keepFolders: true }));
});
it('loads the folders when opened from Settings before the mail view did, then picks the Inbox', async () => {
const fetchMailboxes = vi.fn(async () => {});
const loaded = useEmailStore.getState().mailboxes;
useEmailStore.setState({ mailboxes: [], fetchMailboxes } as never);
render(<MailTransferHost />);
act(() => openMailImport());
expect(fetchMailboxes).toHaveBeenCalled();
act(() => useEmailStore.setState({ mailboxes: loaded } as never));
await waitFor(() => expect((screen.getByTestId('mail-import-target') as HTMLSelectElement).value).toBe('inbox'));
});
it('cannot start without files', () => {
render(<MailTransferHost />);
act(() => openMailImport());
@@ -72,6 +72,17 @@ export function MailImportDialog({ request }: { request: ImportRequest }) {
const targetId = target === TOP ? null : targetMailbox ? targetMailbox.originalId || targetMailbox.id : null;
const effectiveKeep = anyFolders && keepFolders;
// Opened from Settings, the mail view may not have loaded the folders yet.
useEffect(() => {
if (client && mailboxes.length === 0) void useEmailStore.getState().fetchMailboxes(client).catch(() => {});
}, [client, mailboxes.length]);
// Keep the choice valid when the folders arrive or the files change.
useEffect(() => {
const valid = target === TOP ? anyFolders : targets.some((x) => x.mailbox.id === target);
if (!valid && target !== initialTarget) setTarget(initialTarget);
}, [targets, target, anyFolders, initialTarget]);
// An earlier import of the same file into the same place that stopped part way.
useEffect(() => {
let current = true;