diff --git a/src/common/component/FileBox/preview/Image.tsx b/src/common/component/FileBox/preview/Image.tsx index bf60c144..2d266b69 100644 --- a/src/common/component/FileBox/preview/Image.tsx +++ b/src/common/component/FileBox/preview/Image.tsx @@ -1,15 +1,34 @@ -import React, { FC } from "react"; +import { FC, useEffect, useState } from "react"; +import clsx from "clsx"; +import { LineWobble } from "@uiball/loaders"; interface Props { url: string; alt?: string; } -const Image: FC = ({ url, alt }) => { +const ImageBox: FC = ({ url, alt }) => { + const [status, setStatus] = useState<"loading" | "loaded" | "error">("loading"); + + useEffect(() => { + + const img = new Image(); + img.onload = () => { + setStatus("loaded"); + }; + img.onerror = () => { + setStatus("error"); + }; + img.src = url; + }, [url]); + return ( -
- {alt} +
+ {status == "loaded" ? {alt} : ( + status == "loading" ? : + Load image error + )}
); }; -export default Image; +export default ImageBox;