import React, { useState, useEffect } from "react"; import { Image, Box, Spinner, Text, Flex } from "@chakra-ui/react"; import { keyframes } from "@emotion/react"; const shimmer = keyframes` 0% { background-position: -100% 0; } 100% { background-position: 100% 0; } `; const ImageWithFallback = ({ alt, src, fallbackSrc = "/fallback.png", ...props }) => { const [isLoading, setIsLoading] = useState(true); const [scrollPosition, setScrollPosition] = useState(0); const isSlowLoadingSource = src.includes("text2image.seemueller.io"); const handleImageLoad = () => setIsLoading(false); const handleImageError = () => { setIsLoading(false); props.onError?.(); }; useEffect(() => { setIsLoading(true); }, [src]); useEffect(() => { const handleScroll = () => { const scrolled = window.scrollY; setScrollPosition(scrolled); }; window.addEventListener("scroll", handleScroll); return () => { window.removeEventListener("scroll", handleScroll); }; }, []); const parallaxOffset = scrollPosition * 0.2; return ( {isLoading && isSlowLoadingSource && ( Generating... )} {alt} ); }; export default ImageWithFallback;