import React, { FC, useCallback, memo, useEffect, useRef, useState, } from '../../../lib/teact/teact'; import { withGlobal } from '../../../lib/teact/teactn'; import { GlobalActions } from '../../../global/types'; import { SettingsScreens, ISettings, TimeFormat } from '../../../types'; import { ApiSticker, ApiStickerSet } from '../../../api/types'; import { IS_IOS, IS_MAC_OS, IS_TOUCH_ENV } from '../../../util/environment'; import { pick } from '../../../util/iteratees'; import { setTimeFormat } from '../../../util/langProvider'; import useLang from '../../../hooks/useLang'; import useFlag from '../../../hooks/useFlag'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useHistoryBack from '../../../hooks/useHistoryBack'; import ListItem from '../../ui/ListItem'; import RangeSlider from '../../ui/RangeSlider'; import Checkbox from '../../ui/Checkbox'; import RadioGroup, { IRadioOption } from '../../ui/RadioGroup'; import SettingsStickerSet from './SettingsStickerSet'; import StickerSetModal from '../../common/StickerSetModal.async'; type OwnProps = { isActive?: boolean; onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; type StateProps = Pick & { stickerSetIds?: string[]; stickerSetsById?: Record; }; type DispatchProps = Pick; const ANIMATION_LEVEL_OPTIONS = [ 'Solid and Steady', 'Nice and Fast', 'Lots of Stuff', ]; const TIME_FORMAT_OPTIONS: IRadioOption[] = [{ label: '12-hour', value: '12h', }, { label: '24-hour', value: '24h', }]; const SettingsGeneral: FC = ({ isActive, onScreenSelect, onReset, stickerSetIds, stickerSetsById, messageTextSize, animationLevel, messageSendKeyCombo, shouldAutoDownloadMediaFromContacts, shouldAutoDownloadMediaInPrivateChats, shouldAutoDownloadMediaInGroups, shouldAutoDownloadMediaInChannels, shouldAutoPlayGifs, shouldAutoPlayVideos, shouldSuggestStickers, shouldLoopStickers, timeFormat, setSettingOption, loadStickerSets, loadAddedStickers, }) => { // eslint-disable-next-line no-null/no-null const stickerSettingsRef = useRef(null); const { observe: observeIntersectionForCovers } = useIntersectionObserver({ rootRef: stickerSettingsRef }); const [isModalOpen, openModal, closeModal] = useFlag(); const [sticker, setSticker] = useState(); const lang = useLang(); 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; useEffect(() => { loadStickerSets(); }, [loadStickerSets]); useEffect(() => { if (stickerSetIds?.length) { loadAddedStickers(); } }, [stickerSetIds, loadAddedStickers]); const handleAnimationLevelChange = useCallback((newLevel: number) => { ANIMATION_LEVEL_OPTIONS.forEach((_, i) => { document.body.classList.toggle(`animation-level-${i}`, newLevel === i); }); setSettingOption({ animationLevel: newLevel }); }, [setSettingOption]); 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 handleTimeFormatChange = useCallback((value: string) => { setTimeFormat(value as TimeFormat, () => { setSettingOption({ timeFormat: value }); }); }, [setSettingOption]); const handleStickerSetClick = useCallback((value: ApiSticker) => { setSticker(value); openModal(); }, [openModal]); const stickerSets = stickerSetIds && stickerSetIds.map((id: string) => { return stickerSetsById?.[id]?.installedDate ? stickerSetsById[id] : false; }).filter(Boolean as any); useHistoryBack(isActive, onReset, onScreenSelect, SettingsScreens.General); return (

{lang('SETTINGS')}

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

Time Format

Animation Level

Choose the desired animations amount.

{KEYBOARD_SEND_OPTIONS && (

{lang('VoiceOver.Keyboard')}

setSettingOption({ messageSendKeyCombo: value })} selected={messageSendKeyCombo} />
)}

{lang('AutoDownloadMedia')}

setSettingOption({ shouldAutoDownloadMediaFromContacts: isChecked })} /> setSettingOption({ shouldAutoDownloadMediaInPrivateChats: isChecked })} /> setSettingOption({ shouldAutoDownloadMediaInGroups: isChecked })} /> setSettingOption({ shouldAutoDownloadMediaInChannels: isChecked })} />

{lang('AutoplayMedia')}

setSettingOption({ shouldAutoPlayGifs: isChecked })} /> setSettingOption({ shouldAutoPlayVideos: isChecked })} />

{lang('AccDescrStickers')}

setSettingOption({ shouldSuggestStickers: isChecked })} /> setSettingOption({ shouldLoopStickers: isChecked })} />
{stickerSets && stickerSets.map((stickerSet: ApiStickerSet) => ( ))}
{sticker && ( )}
); }; export default memo(withGlobal( (global): StateProps => { return { ...pick(global.settings.byKey, [ 'messageTextSize', 'animationLevel', 'messageSendKeyCombo', 'shouldAutoDownloadMediaFromContacts', 'shouldAutoDownloadMediaInPrivateChats', 'shouldAutoDownloadMediaInGroups', 'shouldAutoDownloadMediaInChannels', 'shouldAutoPlayGifs', 'shouldAutoPlayVideos', 'shouldSuggestStickers', 'shouldLoopStickers', 'isSensitiveEnabled', 'canChangeSensitive', 'timeFormat', ]), stickerSetIds: global.stickers.added.setIds, stickerSetsById: global.stickers.setsById, }; }, (setGlobal, actions): DispatchProps => pick(actions, [ 'setSettingOption', 'loadStickerSets', 'loadAddedStickers', ]), )(SettingsGeneral));