"use client"; import { useEffect, useState } from 'react'; import { useTranslations } from 'next-intl'; import { useSettingsStore } from '@/stores/settings-store'; import { SettingsSection, SettingItem, Select, ToggleSwitch } from './settings-section'; import { DownloadsSettings } from './downloads-settings'; import { TrustedSendersModal } from '@/components/trusted-senders-modal'; import { ChevronRight } from '@/components/icons'; import { usePolicyStore } from '@/stores/policy-store'; import { useContactStore } from '@/stores/contact-store'; import { useAuthStore } from '@/stores/auth-store'; /** * The Reading page: the open message. Opening it, how its body is drawn, * remote images and trusted senders (the former Content & Senders tab), and * attachments, and (Advanced) how downloads are named, the former Downloads * tab. List, delete and swipe rows live on the Message list page. */ export function ReadingSettings() { const t = useTranslations('settings.email_behavior'); const tPage = useTranslations('settings.reading_page'); const [showTrustedModal, setShowTrustedModal] = useState(false); const { isSettingLocked, isSettingHidden, isFeatureEnabled } = usePolicyStore(); const { markAsReadDelay, returnToListAfterAction, mailAttachmentAction, attachmentPosition, hideInlineImageAttachments, attachmentImagePreviewsEnabled, messageSpacing, plainTextFont, externalContentPolicy, emailAlwaysLightMode, trustedSenders, trustedSendersAddressBook, updateSetting, } = useSettingsStore(); 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 count = trustedSendersAddressBook ? trustedSenderEmails.length : trustedSenders.length; if (count === 0) return t('trusted_senders.count_zero'); if (count === 1) return t('trusted_senders.count_one'); return t('trusted_senders.count_other', { count }); }; return (
{!isSettingHidden('markAsReadDelay') && ( updateSetting('messageSpacing', value as typeof messageSpacing)} options={[ { value: 'auto', label: t('message_spacing.auto') }, { value: 'always', label: t('message_spacing.always') }, { value: 'edge', label: t('message_spacing.edge') }, ]} /> )} {!isSettingHidden('plainTextFont') && ( updateSetting('externalContentPolicy', value as 'ask' | 'block' | 'allow') } options={[ { value: 'ask', label: t('external_content.ask') }, { value: 'block', label: t('external_content.block') }, { value: 'allow', label: t('external_content.allow') }, ]} /> )} updateSetting('trustedSendersAddressBook', checked)} /> setShowTrustedModal(false)} /> updateSetting('mailAttachmentAction', value as 'preview' | 'download')} options={[ { value: 'preview', label: t('attachment_click_action.preview') }, { value: 'download', label: t('attachment_click_action.download') }, ]} /> updateSetting('attachmentImagePreviewsEnabled', checked)} /> updateSetting('hideInlineImageAttachments', checked)} />
); }