import React, { useState, useEffect, useRef, memo } from 'react'; import { LazyLoadImage } from 'react-lazy-load-image-component'; import * as Dialog from '@radix-ui/react-dialog'; import DialogImage from './DialogImage'; import { cn } from '~/utils'; const Image = ({ imagePath, altText, height, width, }: // n, // i, { imagePath: string; altText: string; height: number; width: number; // n: number; // i: number; }) => { const prevImagePathRef = useRef(null); const [isLoaded, setIsLoaded] = useState(false); const handleImageLoad = () => setIsLoaded(true); const [minDisplayTimeElapsed, setMinDisplayTimeElapsed] = useState(false); useEffect(() => { let timer: NodeJS.Timeout; if (isLoaded) { timer = setTimeout(() => setMinDisplayTimeElapsed(true), 150); } return () => clearTimeout(timer); }, [isLoaded]); useEffect(() => { const prevImagePath = prevImagePathRef.current; if (prevImagePath && prevImagePath?.startsWith('blob:') && prevImagePath !== imagePath) { URL.revokeObjectURL(prevImagePath); } prevImagePathRef.current = imagePath; }, [imagePath]); // const makeSquare = n >= 3 && i < 2; const placeholderHeight = height > width ? '900px' : '288px'; return (
); }; export default memo(Image);