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 { updateHideEmbeddedImages } from '@proton/shared/lib/api/mailSettings';
10 import { SHOW_IMAGES } from '@proton/shared/lib/mail/mailSettings';
14 hideEmbeddedImages: number;
15 onChange: (value: number) => void;
18 const EmbeddedToggle = ({ id, hideEmbeddedImages, onChange }: Props) => {
19 const { createNotification } = useNotifications();
20 const [loading, withLoading] = useLoading();
21 const { call } = useEventManager();
23 const { state, toggle } = useToggle(hideEmbeddedImages === SHOW_IMAGES.SHOW);
25 const handleChange = async (checked: boolean) => {
26 const bit = checked ? SHOW_IMAGES.SHOW : SHOW_IMAGES.HIDE;
27 await api(updateHideEmbeddedImages(bit));
31 createNotification({ text: c('Success').t`Preference saved` });
37 onChange={({ target }) => withLoading(handleChange(target.checked))}
43 export default EmbeddedToggle;