import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ISettings } from '../../../types'; import { AUTODOWNLOAD_FILESIZE_MB_LIMITS } from '../../../config'; import { pick } from '../../../util/iteratees'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; import Checkbox from '../../ui/Checkbox'; import RangeSlider from '../../ui/RangeSlider'; type OwnProps = { isActive?: boolean; onReset: () => void; }; type StateProps = Pick; const SettingsDataStorage: FC = ({ isActive, onReset, canAutoLoadPhotoFromContacts, canAutoLoadPhotoInPrivateChats, canAutoLoadPhotoInGroups, canAutoLoadPhotoInChannels, canAutoLoadVideoFromContacts, canAutoLoadVideoInPrivateChats, canAutoLoadVideoInGroups, canAutoLoadVideoInChannels, canAutoLoadFileFromContacts, canAutoLoadFileInPrivateChats, canAutoLoadFileInGroups, canAutoLoadFileInChannels, autoLoadFileMaxSizeMb, }) => { const { setSettingOption } = getActions(); const lang = useLang(); useHistoryBack({ isActive, onBack: onReset, }); const renderFileSizeCallback = useCallback((value: number) => { return lang('AutodownloadSizeLimitUpTo', lang('FileSize.MB', String(AUTODOWNLOAD_FILESIZE_MB_LIMITS[value]), 'i')); }, [lang]); const handleFileSizeChange = useCallback((value: number) => { setSettingOption({ autoLoadFileMaxSizeMb: AUTODOWNLOAD_FILESIZE_MB_LIMITS[value] }); }, [setSettingOption]); function renderContentSizeSlider() { const value = AUTODOWNLOAD_FILESIZE_MB_LIMITS.indexOf(autoLoadFileMaxSizeMb); return (
); } function renderAutoDownloadBlock( title: string, key: 'Photo' | 'Video' | 'File', canAutoLoadFromContacts: boolean, canAutoLoadInPrivateChats: boolean, canAutoLoadInGroups: boolean, canAutoLoadInChannels: boolean, ) { return (

{title}

setSettingOption({ [`canAutoLoad${key}FromContacts`]: isChecked })} /> setSettingOption({ [`canAutoLoad${key}InPrivateChats`]: isChecked })} /> setSettingOption({ [`canAutoLoad${key}InGroups`]: isChecked })} /> setSettingOption({ [`canAutoLoad${key}InChannels`]: isChecked })} /> {key === 'File' && renderContentSizeSlider()}
); } return (
{renderAutoDownloadBlock( lang('AutoDownloadPhotosTitle'), 'Photo', canAutoLoadPhotoFromContacts, canAutoLoadPhotoInPrivateChats, canAutoLoadPhotoInGroups, canAutoLoadPhotoInChannels, )} {renderAutoDownloadBlock( lang('AutoDownloadVideosTitle'), 'Video', canAutoLoadVideoFromContacts, canAutoLoadVideoInPrivateChats, canAutoLoadVideoInGroups, canAutoLoadVideoInChannels, )} {renderAutoDownloadBlock( 'Auto-download files', // Proper translation is not available yet 'File', canAutoLoadFileFromContacts, canAutoLoadFileInPrivateChats, canAutoLoadFileInGroups, canAutoLoadFileInChannels, )}
); }; export default memo(withGlobal( (global): StateProps => { return pick(global.settings.byKey, [ 'canAutoLoadPhotoFromContacts', 'canAutoLoadPhotoInPrivateChats', 'canAutoLoadPhotoInGroups', 'canAutoLoadPhotoInChannels', 'canAutoLoadVideoFromContacts', 'canAutoLoadVideoInPrivateChats', 'canAutoLoadVideoInGroups', 'canAutoLoadVideoInChannels', 'canAutoLoadFileFromContacts', 'canAutoLoadFileInPrivateChats', 'canAutoLoadFileInGroups', 'canAutoLoadFileInChannels', 'autoLoadFileMaxSizeMb', ]); }, )(SettingsDataStorage));