import type { FC } from '../../../lib/teact/teact'; import { memo, useEffect, useRef, } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiVideo } from '../../../api/types'; import { SLIDE_TRANSITION_DURATION } from '../../../config'; import { selectCurrentMessageList, selectIsChatWithSelf } from '../../../global/selectors'; import { IS_TOUCH_ENV } from '../../../util/browser/windowEnvironment'; import buildClassName from '../../../util/buildClassName'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useLastCallback from '../../../hooks/useLastCallback'; import useAsyncRendering from '../../right/hooks/useAsyncRendering'; import GifButton from '../../common/GifButton'; import Loading from '../../ui/Loading'; import './GifPicker.scss'; type OwnProps = { className: string; loadAndPlay: boolean; canSendGifs?: boolean; onGifSelect?: (gif: ApiVideo, isSilent?: boolean, shouldSchedule?: boolean) => void; }; type StateProps = { savedGifs?: ApiVideo[]; isSavedMessages?: boolean; }; const INTERSECTION_DEBOUNCE = 300; const GifPicker: FC = ({ className, loadAndPlay, canSendGifs, savedGifs, isSavedMessages, onGifSelect, }) => { const { loadSavedGifs, saveGif } = getActions(); const containerRef = useRef(); const { observe: observeIntersection, } = useIntersectionObserver({ rootRef: containerRef, debounceMs: INTERSECTION_DEBOUNCE }); useEffect(() => { if (loadAndPlay) { loadSavedGifs(); } }, [loadAndPlay, loadSavedGifs]); const handleUnsaveClick = useLastCallback((gif: ApiVideo) => { saveGif({ gif, shouldUnsave: true }); }); const canRenderContents = useAsyncRendering([], SLIDE_TRANSITION_DURATION); return (
{!canSendGifs ? (
Sending GIFs is not allowed in this chat.
) : canRenderContents && savedGifs && savedGifs.length ? ( savedGifs.map((gif) => ( )) ) : canRenderContents && savedGifs ? (
No saved GIFs.
) : ( )}
); }; export default memo(withGlobal( (global): StateProps => { const { chatId } = selectCurrentMessageList(global) || {}; const isSavedMessages = Boolean(chatId) && selectIsChatWithSelf(global, chatId); return { savedGifs: global.gifs.saved.gifs, isSavedMessages, }; }, )(GifPicker));