import React, { FC, useEffect, memo, useRef, } from '../../../lib/teact/teact'; import { withGlobal } from '../../../lib/teact/teactn'; import { GlobalActions } from '../../../global/types'; import { ApiVideo } from '../../../api/types'; import { SLIDE_TRANSITION_DURATION } from '../../../config'; import { IS_TOUCH_ENV } from '../../../util/environment'; import buildClassName from '../../../util/buildClassName'; import { pick } from '../../../util/iteratees'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useAsyncRendering from '../../right/hooks/useAsyncRendering'; import Loading from '../../ui/Loading'; import GifButton from '../../common/GifButton'; import './GifPicker.scss'; type OwnProps = { className: string; loadAndPlay: boolean; canSendGifs: boolean; onGifSelect: (gif: ApiVideo) => void; }; type StateProps = { savedGifs?: ApiVideo[]; }; type DispatchProps = Pick; const INTERSECTION_DEBOUNCE = 300; const GifPicker: FC = ({ className, loadAndPlay, canSendGifs, savedGifs, onGifSelect, loadSavedGifs, }) => { // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const { observe: observeIntersection, } = useIntersectionObserver({ rootRef: containerRef, debounceMs: INTERSECTION_DEBOUNCE }); useEffect(() => { if (loadAndPlay) { loadSavedGifs(); } }, [loadAndPlay, loadSavedGifs]); 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 => { return { savedGifs: global.gifs.saved.gifs, }; }, (setGlobal, actions): DispatchProps => pick(actions, ['loadSavedGifs']), )(GifPicker));