import type { FC } from '../../../lib/teact/teact'; import React, { useCallback, memo, } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ISettings, TimeFormat } from '../../../types'; import { SettingsScreens } from '../../../types'; import { getSystemTheme, IS_IOS, IS_MAC_OS, IS_TOUCH_ENV, } from '../../../util/windowEnvironment'; import { pick } from '../../../util/iteratees'; import { setTimeFormat } from '../../../util/langProvider'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; import ListItem from '../../ui/ListItem'; import RangeSlider from '../../ui/RangeSlider'; import type { IRadioOption } from '../../ui/RadioGroup'; import RadioGroup from '../../ui/RadioGroup'; type OwnProps = { isActive?: boolean; onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; type StateProps = Pick & { theme: ISettings['theme']; shouldUseSystemTheme: boolean; }; const TIME_FORMAT_OPTIONS: IRadioOption[] = [{ label: '12-hour', value: '12h', }, { label: '24-hour', value: '24h', }]; const SettingsGeneral: FC = ({ isActive, onScreenSelect, onReset, messageTextSize, messageSendKeyCombo, timeFormat, theme, shouldUseSystemTheme, }) => { const { setSettingOption, } = getActions(); const lang = useLang(); const APPEARANCE_THEME_OPTIONS: IRadioOption[] = [{ label: lang('EmptyChat.Appearance.Light'), value: 'light', }, { label: lang('EmptyChat.Appearance.Dark'), value: 'dark', }, { label: lang('EmptyChat.Appearance.System'), value: 'auto', }]; const KEYBOARD_SEND_OPTIONS = !IS_TOUCH_ENV ? [ { value: 'enter', label: lang('lng_settings_send_enter'), subLabel: 'New line by Shift + Enter' }, { value: 'ctrl-enter', label: lang(IS_MAC_OS ? 'lng_settings_send_cmdenter' : 'lng_settings_send_ctrlenter'), subLabel: 'New line by Enter', }, ] : 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()); setSettingOption({ messageTextSize: newSize }); }, [setSettingOption]); const handleAppearanceThemeChange = useCallback((value: string) => { const newTheme = value === 'auto' ? getSystemTheme() : value as ISettings['theme']; setSettingOption({ theme: newTheme }); setSettingOption({ shouldUseSystemTheme: value === 'auto' }); }, [setSettingOption]); const handleTimeFormatChange = useCallback((newTimeFormat: string) => { setSettingOption({ timeFormat: newTimeFormat as TimeFormat }); setSettingOption({ wasTimeFormatSetManually: true }); setTimeFormat(newTimeFormat as TimeFormat); }, [setSettingOption]); const handleMessageSendComboChange = useCallback((newCombo: string) => { setSettingOption({ messageSendKeyCombo: newCombo as ISettings['messageSendKeyCombo'] }); }, [setSettingOption]); useHistoryBack({ isActive, onBack: onReset, }); return (

{lang('SETTINGS')}

onScreenSelect(SettingsScreens.GeneralChatBackground)} > {lang('ChatBackground')}

{lang('Theme')}

Time Format

{KEYBOARD_SEND_OPTIONS && (

{lang('VoiceOver.Keyboard')}

)}
); }; export default memo(withGlobal( (global): StateProps => { const { theme, shouldUseSystemTheme } = global.settings.byKey; return { ...pick(global.settings.byKey, [ 'messageTextSize', 'animationLevel', 'messageSendKeyCombo', 'isSensitiveEnabled', 'canChangeSensitive', 'timeFormat', ]), theme, shouldUseSystemTheme, }; }, )(SettingsGeneral));