import React, { memo, useCallback, useMemo, useRef, } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; import { SettingsScreens } from '../../../types'; import type { ISettings } from '../../../types'; import type { ApiSticker, ApiStickerSet } from '../../../api/types'; import renderText from '../../common/helpers/renderText'; import { pick } from '../../../util/iteratees'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useHistoryBack from '../../../hooks/useHistoryBack'; import useLang from '../../../hooks/useLang'; import ReactionStaticEmoji from '../../common/ReactionStaticEmoji'; import Checkbox from '../../ui/Checkbox'; import ListItem from '../../ui/ListItem'; import StickerSetCard from '../../common/StickerSetCard'; type OwnProps = { isActive?: boolean; onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; type StateProps = Pick & { addedSetIds?: string[]; customEmojiSetIds?: string[]; stickerSetsById: Record; defaultReaction?: string; }; const SettingsStickers: FC = ({ isActive, addedSetIds, customEmojiSetIds, stickerSetsById, defaultReaction, shouldSuggestStickers, shouldLoopStickers, onReset, onScreenSelect, }) => { const { setSettingOption, openStickerSet, } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null const stickerSettingsRef = useRef(null); const { observe: observeIntersectionForCovers } = useIntersectionObserver({ rootRef: stickerSettingsRef }); const handleStickerSetClick = useCallback((sticker: ApiSticker) => { openStickerSet({ stickerSetInfo: sticker.stickerSetInfo, }); }, [openStickerSet]); const handleSuggestStickersChange = useCallback((newValue: boolean) => { setSettingOption({ shouldSuggestStickers: newValue }); }, [setSettingOption]); const handleShouldLoopStickersChange = useCallback((newValue: boolean) => { setSettingOption({ shouldLoopStickers: newValue }); }, [setSettingOption]); const stickerSets = useMemo(() => ( addedSetIds && Object.values(pick(stickerSetsById, addedSetIds)) ), [addedSetIds, stickerSetsById]); useHistoryBack({ isActive, onBack: onReset, }); return (
onScreenSelect(SettingsScreens.CustomEmoji)} icon="smile" > {lang('StickersList.EmojiItem')} {customEmojiSetIds && {customEmojiSetIds.length}} {defaultReaction && ( onScreenSelect(SettingsScreens.QuickReaction)} >
{lang('DoubleTapSetting')}
)}
{stickerSets && (

{lang('ChooseStickerMyStickerSets')}

{stickerSets.map((stickerSet: ApiStickerSet) => ( ))}

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

)}
); }; export default memo(withGlobal( (global): StateProps => { return { ...pick(global.settings.byKey, [ 'shouldSuggestStickers', 'shouldLoopStickers', ]), addedSetIds: global.stickers.added.setIds, customEmojiSetIds: global.customEmojis.added.setIds, stickerSetsById: global.stickers.setsById, defaultReaction: global.appConfig?.defaultReaction, }; }, )(SettingsStickers));