1 import { useState } from 'react';
3 import { c } from 'ttag';
5 import Info from '@proton/components/components/link/Info';
6 import useApi from '@proton/components/hooks/useApi';
7 import useEventManager from '@proton/components/hooks/useEventManager';
8 import useNotifications from '@proton/components/hooks/useNotifications';
9 import { FeatureCode, useFeature } from '@proton/features';
10 import { useLoading } from '@proton/hooks';
11 import { useMailSettings } from '@proton/mail/mailSettings/hooks';
12 import { updateSpamAction, updateStickyLabels, updateViewMode } from '@proton/shared/lib/api/mailSettings';
13 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
14 import type { SPAM_ACTION } from '@proton/shared/lib/mail/mailSettings';
15 import { DEFAULT_MAILSETTINGS, STICKY_LABELS, VIEW_MODE } from '@proton/shared/lib/mail/mailSettings';
16 import { useFlag } from '@proton/unleash';
18 import SettingsLayout from '../account/SettingsLayout';
19 import SettingsLayoutLeft from '../account/SettingsLayoutLeft';
20 import SettingsLayoutRight from '../account/SettingsLayoutRight';
21 import StickyLabelsToggle from '../layouts/StickyLabelsToggle';
22 import ViewModeToggle from '../layouts/ViewModeToggle';
23 import AlmostAllMailToggle from './AlmostAllMailToggle';
24 import AutoDeleteSetting from './AutoDeleteSetting';
25 import EmbeddedToggle from './EmbeddedToggle';
26 import { PageSizeSelector } from './PageSizeSelector';
27 import RequestLinkConfirmationToggle from './RequestLinkConfirmationToggle';
28 import ShowMovedToggle from './ShowMovedToggle';
29 import SpamActionSelect from './SpamActionSelect';
31 const MessagesSection = () => {
39 AutoDeleteSpamAndTrashDays,
41 } = DEFAULT_MAILSETTINGS,
42 ] = useMailSettings();
43 const [hideEmbeddedImages, setHideEmbeddedImages] = useState(HideEmbeddedImages);
44 const { createNotification } = useNotifications();
46 const isAlmostAllMailEnabled = !!useFeature(FeatureCode.AlmostAllMail).feature?.Value;
47 const isPageSizeSettingEnabled = useFlag('WebMailPageSizeSetting');
49 const { call } = useEventManager();
52 const [loadingViewMode, withLoadingViewMode] = useLoading();
53 const [loadingStickyLabels, withLoadingStickyLabels] = useLoading();
54 const [loadingSpamAction, withLoadingSpamAction] = useLoading();
56 const handleChangeHideEmbedded = (newValue: number) => setHideEmbeddedImages(newValue);
58 const notifyPreferenceSaved = () => createNotification({ text: c('Success').t`Preference saved` });
60 const handleToggleStickyLabels = async (value: number) => {
61 await api(updateStickyLabels(value));
63 notifyPreferenceSaved();
66 const handleChangeViewMode = async (mode: VIEW_MODE) => {
67 if (mode === VIEW_MODE.SINGLE) {
68 await api(updateStickyLabels(STICKY_LABELS.DISABLED));
70 await api(updateViewMode(mode));
72 notifyPreferenceSaved();
75 const handleChangeSpamAction = async (spamAction: SPAM_ACTION | null) => {
76 await api(updateSpamAction(spamAction));
78 notifyPreferenceSaved();
85 <label htmlFor="embeddedToggle" className="text-semibold">
86 <span className="mr-2">{c('Label').t`Auto show embedded images`}</span>
88 url={getKnowledgeBaseUrl('/images-by-default')}
90 .t`When disabled, this prevents image files from loading on your device without your knowledge.`}
94 <SettingsLayoutRight isToggleContainer>
97 hideEmbeddedImages={hideEmbeddedImages}
98 onChange={handleChangeHideEmbedded}
100 </SettingsLayoutRight>
104 <label htmlFor="showMovedToggle" className="text-semibold">
105 <span className="mr-2">{c('Label').t`Keep messages in Sent/Drafts`}</span>
108 .t`Messages in the Sent or Drafts folder will continue to appear in that folder, even if you move them to another folder.`}
111 </SettingsLayoutLeft>
112 <SettingsLayoutRight isToggleContainer>
113 <ShowMovedToggle id="showMovedToggle" />
114 </SettingsLayoutRight>
117 {isAlmostAllMailEnabled && (
120 <label htmlFor="almostAllMail" className="text-semibold">
121 <span className="mr-2">{c('Label').t`Exclude Spam/Trash from All mail`}</span>
122 <Info title={c('Info').t`Not yet available in our Android mobile app.`} />
124 </SettingsLayoutLeft>
125 <SettingsLayoutRight isToggleContainer>
126 <AlmostAllMailToggle id="almostAllMail" showAlmostAllMail={AlmostAllMail} />
127 </SettingsLayoutRight>
133 <label htmlFor="requestLinkConfirmationToggle" className="text-semibold">
134 <span className="mr-2">{c('Label').t`Confirm link URLs`}</span>
137 .t`When you click on a link, this anti-phishing feature will ask you to confirm the URL of the web page.`}
140 </SettingsLayoutLeft>
141 <SettingsLayoutRight isToggleContainer>
142 <RequestLinkConfirmationToggle confirmLink={ConfirmLink} id="requestLinkConfirmationToggle" />
143 </SettingsLayoutRight>
148 <label htmlFor="viewMode" className="text-semibold">
149 <span className="mr-2">{c('Label').t`Conversation grouping`}</span>
152 .t`Group emails in the same conversation together in your Inbox or display them separately.`}
155 </SettingsLayoutLeft>
157 <SettingsLayoutRight isToggleContainer>
161 loading={loadingViewMode}
162 onToggle={(value) => withLoadingViewMode(handleChangeViewMode(value))}
163 data-testid="appearance:conversation-group-toggle"
165 </SettingsLayoutRight>
168 <AutoDeleteSetting settingValue={AutoDeleteSpamAndTrashDays} onSaved={notifyPreferenceSaved} />
172 <label htmlFor="stickyLabelsToggle" className="text-semibold">
173 <span className="mr-2">{c('Label').t`Sticky labels`}</span>
176 .t`When you add a label to a message in a conversation, it will automatically be applied to all future messages you send or receive in that conversation.`}
179 </SettingsLayoutLeft>
180 <SettingsLayoutRight isToggleContainer>
182 id="stickyLabelsToggle"
183 stickyLabels={StickyLabels}
184 loading={loadingStickyLabels}
185 onToggle={(value) => withLoadingStickyLabels(handleToggleStickyLabels(value))}
186 data-testid="appearance:sticky-labels-toggle"
187 disabled={ViewMode !== VIEW_MODE.GROUP}
189 </SettingsLayoutRight>
194 <label htmlFor="spamActionLabelSelect" className="text-semibold">
195 <span className="mr-2">{c('Label').t`Auto-unsubscribe`}</span>
198 .t`When you move an email to spam, you’ll automatically be unsubscribed from the sender’s mailing lists.`}
201 </SettingsLayoutLeft>
202 <SettingsLayoutRight>
204 id="spamActionLabelSelect"
206 onChange={(value) => withLoadingSpamAction(handleChangeSpamAction(value))}
207 loading={loadingSpamAction}
209 </SettingsLayoutRight>
212 {isPageSizeSettingEnabled && (
215 <label htmlFor="pageSizeSelector" className="text-semibold" id="label-pageSizeSelector">
216 <span className="mr-2">
217 {ViewMode === VIEW_MODE.GROUP
218 ? c('Label').t`Conversations per page`
219 : c('Label').t`Messages per page`}
222 </SettingsLayoutLeft>
223 <SettingsLayoutRight>
224 <PageSizeSelector id="pageSizeSelector" />
225 </SettingsLayoutRight>
232 export default MessagesSection;