import type { FC } from '../../../lib/teact/teact'; import { memo, useCallback, } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { SharedSettings } from '../../../global/types'; import type { ThemeKey, TimeFormat } from '../../../types'; import type { IRadioOption } from '../../ui/RadioGroup'; import { SettingsScreens } from '../../../types'; import { selectSharedSettings } from '../../../global/selectors/sharedState'; import { IS_ANDROID, IS_IOS, IS_MAC_OS, } from '../../../util/browser/windowEnvironment'; import { setTimeFormat } from '../../../util/oldLangProvider'; import { getSystemTheme } from '../../../util/systemTheme'; import useAppLayout from '../../../hooks/useAppLayout'; import useHistoryBack from '../../../hooks/useHistoryBack'; import useLang from '../../../hooks/useLang'; import ListItem from '../../ui/ListItem'; import RadioGroup from '../../ui/RadioGroup'; import RangeSlider from '../../ui/RangeSlider'; type OwnProps = { isActive?: boolean; onReset: () => void; }; type StateProps = Pick; const SettingsGeneral: FC = ({ isActive, messageTextSize, messageSendKeyCombo, timeFormat, theme, shouldUseSystemTheme, onReset, }) => { const { setSharedSettingOption, openSettingsScreen, } = getActions(); const lang = useLang(); const { isMobile } = useAppLayout(); const isMobileDevice = isMobile && (IS_IOS || IS_ANDROID); const timeFormatOptions: IRadioOption[] = [{ label: lang('SettingsTimeFormat12'), value: '12h', }, { label: lang('SettingsTimeFormat24'), value: '24h', }]; const appearanceThemeOptions: IRadioOption[] = [{ label: lang('EmptyChatAppearanceLight'), value: 'light', }, { label: lang('EmptyChatAppearanceDark'), value: 'dark', }, { label: lang('EmptyChatAppearanceSystem'), value: 'auto', }]; const keyboardSendOptions = !isMobileDevice ? [ { value: 'enter', label: lang('SettingsSendEnter'), subLabel: lang('SettingsSendEnterDescription') }, { value: 'ctrl-enter', label: lang(IS_MAC_OS || IS_IOS ? 'SettingsSendCmdenter' : 'SettingsSendCtrlenter'), subLabel: lang('SettingsSendPlusEnterDescription'), }, ] : undefined; const handleMessageTextSizeChange = useCallback((newSize: number) => { document.documentElement.style.setProperty( '--composer-text-size', `${Math.max(newSize, IS_IOS ? 16 : 15)}px`, ); document.documentElement.style.setProperty('--message-meta-height', `${Math.floor(newSize * 1.3125)}px`); document.documentElement.style.setProperty('--message-text-size', `${newSize}px`); document.documentElement.setAttribute('data-message-text-size', newSize.toString()); setSharedSettingOption({ messageTextSize: newSize }); }, []); const handleAppearanceThemeChange = useCallback((value: string) => { const newTheme = value === 'auto' ? getSystemTheme() : value as ThemeKey; setSharedSettingOption({ theme: newTheme }); setSharedSettingOption({ shouldUseSystemTheme: value === 'auto' }); }, []); const handleTimeFormatChange = useCallback((newTimeFormat: string) => { setSharedSettingOption({ timeFormat: newTimeFormat as TimeFormat }); setSharedSettingOption({ wasTimeFormatSetManually: true }); setTimeFormat(newTimeFormat as TimeFormat); }, []); const handleMessageSendComboChange = useCallback((newCombo: string) => { setSharedSettingOption({ messageSendKeyCombo: newCombo as SharedSettings['messageSendKeyCombo'] }); }, []); useHistoryBack({ isActive, onBack: onReset, }); return (

{lang('Settings')}

openSettingsScreen({ screen: SettingsScreens.GeneralChatBackground })} > {lang('ChatBackground')}

{lang('Theme')}

{lang('SettingsTimeFormat')}

{keyboardSendOptions && (

{lang('SettingsKeyboard')}

)}
); }; export default memo(withGlobal( (global): Complete => { const { theme, shouldUseSystemTheme, messageSendKeyCombo, messageTextSize, timeFormat, } = selectSharedSettings(global); return { messageSendKeyCombo, messageTextSize, timeFormat, theme, shouldUseSystemTheme, }; }, )(SettingsGeneral));