import { FC, useEffect, useState } from "react"; import { LineWobble, Ping } from "@uiball/loaders"; import { getDefaultSize, isMobile } from "@/utils"; type Props = { uploading: boolean; progress: number; thumbnail: string; download: string; content: string; properties: { width: number; height: number }; }; const ImageMessage: FC = ({ uploading, progress, thumbnail, download, content, properties }) => { const url = thumbnail || content; const [status, setStatus] = useState<"loading" | "error" | "loaded">("loading"); const { width = 0, height = 0 } = getDefaultSize(properties, { min: 200, max: isMobile() ? 300 : 480 }); useEffect(() => { const img = new Image(); img.onload = () => { setStatus("loaded"); }; img.onerror = () => { setStatus("error"); }; img.src = url; }, [url]); return (
{uploading && (
{progress}%
)} {status == "error" ? (

load image error

) : status == "loading" ? (

) : ( )}
); }; export default ImageMessage;