diff --git a/src/components/ImageWithPreview.tsx b/src/components/ImageWithPreview.tsx index da677302..76490e9a 100644 --- a/src/components/ImageWithPreview.tsx +++ b/src/components/ImageWithPreview.tsx @@ -1,17 +1,60 @@ import RcImage, { ImageProps } from 'rc-image'; +import { useEffect, useState } from 'react'; import { AiOutlineClose } from 'react-icons/ai'; import 'rc-image/assets/index.css'; +import GifPlayButton from './loading/GifPlayButton'; + const ImageWithPreview = (props: ImageProps) => { + const [imgSrc, setImgSrc] = useState( + props.src?.endsWith('gif') ? `${props.src}!gif` : (props.src as string) + ); + const isGifThumb = imgSrc.endsWith('!gif'); + const isGif = imgSrc?.endsWith('gif') && !isGifThumb; + const sourceIsGif = props.src?.endsWith('gif'); + + useEffect(() => { + if (props.src?.endsWith('gif')) { + setImgSrc(`${props.src}!gif`); + } else { + setImgSrc(props.src as string); + } + }, [props.src]); + + const handleLoadGif = (e: any) => { + e.stopPropagation(); + setTimeout(() => { + if (sourceIsGif) { + setImgSrc(imgSrc?.replace('!gif', '')); + } + }, 300); + }; + return ( - }, - toolbarRender: () => <>, - }} - /> +
+ }, + toolbarRender: () => <>, + }} + /> + {sourceIsGif && ( +
+
+ +
+
+ )} +
); }; diff --git a/src/components/loading/GifPlayButton.tsx b/src/components/loading/GifPlayButton.tsx new file mode 100644 index 00000000..28152437 --- /dev/null +++ b/src/components/loading/GifPlayButton.tsx @@ -0,0 +1,40 @@ +// GifPlayButton.tsx +import React from 'react'; + +const GifPlayButton = () => ( + + + + + + + + + + + +); + +export default GifPlayButton;