fix: load mailboxes in Filters when opened directly #485
This commit is contained in:
@@ -160,6 +160,7 @@ export function FilterSettings() {
|
|||||||
const tNotifications = useTranslations("notifications");
|
const tNotifications = useTranslations("notifications");
|
||||||
const { client } = useAuthStore();
|
const { client } = useAuthStore();
|
||||||
const storeMailboxes = useEmailStore((s) => s.mailboxes);
|
const storeMailboxes = useEmailStore((s) => s.mailboxes);
|
||||||
|
const fetchMailboxes = useEmailStore((s) => s.fetchMailboxes);
|
||||||
const expandedFilterView = useSettingsStore((s) => s.expandedFilterView);
|
const expandedFilterView = useSettingsStore((s) => s.expandedFilterView);
|
||||||
const updateSetting = useSettingsStore((s) => s.updateSetting);
|
const updateSetting = useSettingsStore((s) => s.updateSetting);
|
||||||
|
|
||||||
@@ -212,6 +213,22 @@ export function FilterSettings() {
|
|||||||
return () => { cancelled = true; };
|
return () => { cancelled = true; };
|
||||||
}, [client, managedAccountId]);
|
}, [client, managedAccountId]);
|
||||||
|
|
||||||
|
// The "move to" folder list for the primary account comes from the email
|
||||||
|
// store, which is normally populated when the mail view mounts. When the app
|
||||||
|
// is opened or refreshed directly on Settings (the mail view never mounted),
|
||||||
|
// that store is empty, leaving the rule editor's folder dropdown blank. Fetch
|
||||||
|
// mailboxes on demand here so Filters never depends on having visited Inbox
|
||||||
|
// first. fetchMailboxes guards against transient empty results and selecting
|
||||||
|
// an inbox, so it's safe to call independently; a ref keeps it to one attempt
|
||||||
|
// per client.
|
||||||
|
const primaryFetchClientRef = useRef<typeof client | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
if (managedAccountId || !client || storeMailboxes.length > 0) return;
|
||||||
|
if (primaryFetchClientRef.current === client) return;
|
||||||
|
primaryFetchClientRef.current = client;
|
||||||
|
void fetchMailboxes(client);
|
||||||
|
}, [client, managedAccountId, storeMailboxes.length, fetchMailboxes]);
|
||||||
|
|
||||||
const mailboxes = managedAccountId ? scopedMailboxes : storeMailboxes;
|
const mailboxes = managedAccountId ? scopedMailboxes : storeMailboxes;
|
||||||
|
|
||||||
const vacationStoreEnabled = useVacationStore((s) => s.isEnabled);
|
const vacationStoreEnabled = useVacationStore((s) => s.isEnabled);
|
||||||
|
|||||||
Reference in New Issue
Block a user