import React, { memo, useCallback, useMemo, useRef, } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; import type { ApiSticker, ApiStickerSet } from '../../../api/types'; import type { ISettings } from '../../../types'; import renderText from '../../common/helpers/renderText'; import { pick } from '../../../util/iteratees'; import { selectCanPlayAnimatedEmojis } from '../../../global/selectors'; import useHistoryBack from '../../../hooks/useHistoryBack'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useLang from '../../../hooks/useLang'; import StickerSetCard from '../../common/StickerSetCard'; import Checkbox from '../../ui/Checkbox'; type OwnProps = { isActive?: boolean; onReset: () => void; }; type StateProps = Pick & { customEmojiSetIds?: string[]; stickerSetsById: Record; canPlayAnimatedEmojis: boolean; }; const SettingsCustomEmoji: FC = ({ isActive, customEmojiSetIds, stickerSetsById, shouldSuggestCustomEmoji, canPlayAnimatedEmojis, onReset, }) => { const { openStickerSet, setSettingOption } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null const stickerSettingsRef = useRef(null); const { observe: observeIntersectionForCovers } = useIntersectionObserver({ rootRef: stickerSettingsRef }); useHistoryBack({ isActive, onBack: onReset, }); const handleStickerSetClick = useCallback((sticker: ApiSticker) => { openStickerSet({ stickerSetInfo: sticker.stickerSetInfo, }); }, [openStickerSet]); const handleSuggestCustomEmojiChange = useCallback((newValue: boolean) => { setSettingOption({ shouldSuggestCustomEmoji: newValue }); }, [setSettingOption]); const customEmojiSets = useMemo(() => ( customEmojiSetIds && Object.values(pick(stickerSetsById, customEmojiSetIds)) ), [customEmojiSetIds, stickerSetsById]); return (
{customEmojiSets && (
{customEmojiSets.map((stickerSet: ApiStickerSet) => ( ))}

{renderText(lang('EmojiBotInfo'), ['links'])}

)}
); }; export default memo(withGlobal( (global): StateProps => { return { ...pick(global.settings.byKey, [ 'shouldSuggestCustomEmoji', ]), customEmojiSetIds: global.customEmojis.added.setIds, stickerSetsById: global.stickers.setsById, canPlayAnimatedEmojis: selectCanPlayAnimatedEmojis(global), }; }, )(SettingsCustomEmoji));