1 import { c } from 'ttag';
3 import Toggle from '@proton/components/components/toggle/Toggle';
4 import useApi from '@proton/components/hooks/useApi';
5 import useEventManager from '@proton/components/hooks/useEventManager';
6 import useNotifications from '@proton/components/hooks/useNotifications';
7 import useToggle from '@proton/components/hooks/useToggle';
8 import { useLoading } from '@proton/hooks';
9 import { useMailSettings } from '@proton/mail/mailSettings/hooks';
10 import { updateDisplayUnreadFavicon } from '@proton/shared/lib/api/mailSettings';
17 export const UnreadFaviconCounterToggle = ({ id, className }: Props) => {
18 const [mailSettings] = useMailSettings();
19 const { call } = useEventManager();
22 const { state, toggle } = useToggle(!!mailSettings?.UnreadFavicon);
23 const { createNotification } = useNotifications();
24 const [loading, withLoading] = useLoading();
26 const handleChange = async (checked: boolean) => {
27 await api(updateDisplayUnreadFavicon(+checked));
30 createNotification({ text: c('Success').t`Preference saved` });
38 onChange={({ target }) => withLoading(handleChange(target.checked))}