1 import { c } from 'ttag';
3 import { useUserSettings } from '@proton/account/userSettings/hooks';
4 import Info from '@proton/components/components/link/Info';
5 import Loader from '@proton/components/components/loader/Loader';
6 import SettingsSectionWide from '@proton/components/containers/account/SettingsSectionWide';
7 import useApi from '@proton/components/hooks/useApi';
8 import useEventManager from '@proton/components/hooks/useEventManager';
9 import useNotifications from '@proton/components/hooks/useNotifications';
10 import { useLoading } from '@proton/hooks';
11 import { useMailSettings } from '@proton/mail/mailSettings/hooks';
12 import { updateComposerMode, updateViewLayout } from '@proton/shared/lib/api/mailSettings';
13 import { updateDensity } from '@proton/shared/lib/api/settings';
14 import type { DENSITY } from '@proton/shared/lib/constants';
15 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
16 import type { COMPOSER_MODE, VIEW_LAYOUT } from '@proton/shared/lib/mail/mailSettings';
17 import { DEFAULT_MAILSETTINGS } from '@proton/shared/lib/mail/mailSettings';
19 import ComposerModeCards from './ComposerModeCards';
20 import DensityRadiosCards from './DensityRadiosCards';
21 import ViewLayoutCards from './ViewLayoutCards';
23 const LayoutsSection = () => {
24 const [{ ComposerMode, ViewLayout } = DEFAULT_MAILSETTINGS, loadingMailSettings] = useMailSettings();
25 const [{ Density }, loadingUserSettings] = useUserSettings();
26 const { call } = useEventManager();
27 const { createNotification } = useNotifications();
29 const [loadingComposerMode, withLoadingComposerMode] = useLoading();
30 const [loadingViewLayout, withLoadingViewLayout] = useLoading();
31 const [loadingDensity, withLoadingDensity] = useLoading();
33 const notifyPreferenceSaved = () => createNotification({ text: c('Success').t`Preference saved` });
35 const handleChangeComposerMode = async (mode: COMPOSER_MODE) => {
36 await api(updateComposerMode(mode));
38 notifyPreferenceSaved();
41 const handleChangeViewLayout = async (layout: VIEW_LAYOUT) => {
42 await api(updateViewLayout(layout));
44 notifyPreferenceSaved();
47 const handleChangeDensity = async (density: DENSITY) => {
48 await api(updateDensity(density));
50 notifyPreferenceSaved();
54 <SettingsSectionWide className="flex flex-wrap">
55 {loadingMailSettings || loadingUserSettings ? (
59 <div className="flex flex-column flex-nowrap mb-4">
60 <span className="mb-4 text-semibold">
61 <span className="mr-2" id="layoutMode_desc">{c('Label').t`Inbox`}</span>
63 url={getKnowledgeBaseUrl('/change-inbox-layout')}
64 title={c('Tooltip').t`Set the default layout for your Inbox.`}
68 describedByID="layoutMode_desc"
69 viewLayout={ViewLayout}
70 onChange={(value) => withLoadingViewLayout(handleChangeViewLayout(value))}
71 loading={loadingViewLayout}
75 <div className="flex flex-column flex-nowrap mb-4">
76 <span className="mb-4 text-semibold">
77 <span className="mr-2" id="composerMode_desc">{c('Label').t`Composer`}</span>
79 url={getKnowledgeBaseUrl('/composer')}
80 title={c('Tooltip').t`Set the default Composer popup size as small or full screen.`}
85 describedByID="composerMode_desc"
86 composerMode={ComposerMode}
87 onChange={(value) => withLoadingComposerMode(handleChangeComposerMode(value))}
88 loading={loadingComposerMode}
92 <div className="flex flex-column flex-nowrap mb-4">
93 <span className="mb-4 text-semibold">
94 <span className="mr-2" id="densityMode_desc">{c('Label').t`Density`}</span>
96 url={getKnowledgeBaseUrl('/change-inbox-layout')}
97 title={c('Tooltip').t`Set how your list of messages looks like by default.`}
102 describedByID="densityMode_desc"
103 onChange={(value) => withLoadingDensity(handleChangeDensity(value))}
104 loading={loadingDensity}
109 </SettingsSectionWide>
113 export default LayoutsSection;