fix: load trusted senders address book on settings page so count isn't 0
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useSettingsStore } from '@/stores/settings-store';
|
import { useSettingsStore } from '@/stores/settings-store';
|
||||||
import { SettingsSection, SettingItem, Select, ToggleSwitch } from './settings-section';
|
import { SettingsSection, SettingItem, Select, ToggleSwitch } from './settings-section';
|
||||||
@@ -8,6 +8,7 @@ import { TrustedSendersModal } from '@/components/trusted-senders-modal';
|
|||||||
import { ChevronRight } from 'lucide-react';
|
import { ChevronRight } from 'lucide-react';
|
||||||
import { usePolicyStore } from '@/stores/policy-store';
|
import { usePolicyStore } from '@/stores/policy-store';
|
||||||
import { useContactStore } from '@/stores/contact-store';
|
import { useContactStore } from '@/stores/contact-store';
|
||||||
|
import { useAuthStore } from '@/stores/auth-store';
|
||||||
|
|
||||||
export function ContentSendersSettings() {
|
export function ContentSendersSettings() {
|
||||||
const t = useTranslations('settings.email_behavior');
|
const t = useTranslations('settings.email_behavior');
|
||||||
@@ -21,7 +22,15 @@ export function ContentSendersSettings() {
|
|||||||
trustedSendersAddressBook,
|
trustedSendersAddressBook,
|
||||||
updateSetting,
|
updateSetting,
|
||||||
} = useSettingsStore();
|
} = useSettingsStore();
|
||||||
const { trustedSenderEmails } = useContactStore();
|
const { trustedSenderEmails, trustedSendersLoaded, loadTrustedSendersBook } = useContactStore();
|
||||||
|
const client = useAuthStore((state) => state.client);
|
||||||
|
|
||||||
|
// Load the address book so the count reflects the synced senders, not 0.
|
||||||
|
useEffect(() => {
|
||||||
|
if (trustedSendersAddressBook && client && !trustedSendersLoaded) {
|
||||||
|
loadTrustedSendersBook(client);
|
||||||
|
}
|
||||||
|
}, [trustedSendersAddressBook, client, trustedSendersLoaded, loadTrustedSendersBook]);
|
||||||
|
|
||||||
const getTrustedSendersCount = () => {
|
const getTrustedSendersCount = () => {
|
||||||
const count = trustedSendersAddressBook ? trustedSenderEmails.length : trustedSenders.length;
|
const count = trustedSendersAddressBook ? trustedSenderEmails.length : trustedSenders.length;
|
||||||
|
|||||||
Reference in New Issue
Block a user