import React, { Suspense, useEffect, useRef, useState } from "react"; import { useImage } from "react-image"; import ImageErrorBoundary from "./ImageErrorBoundary"; import { PhotoView } from "react-photo-view"; import { toJSON } from "@wc-yat/csstojson/dist/toJSON"; import prettier from "prettier/standalone"; import prettierCss from "prettier/parser-postcss"; import Loader from "../../../lib/loader"; import { IconButton } from "@mui/material"; import { ZoomInMap, ZoomOutMap } from "@mui/icons-material"; import { useCRoot } from "../ConversationContext"; // import { engineName, isIOS, isSafari } from "react-device-detect"; interface Props { src: string; height?: string | number; width?: string | number; style?: string; small?: boolean; } function ImgComponent(props: Props) { const { height, style, width } = props; const { src } = useImage({ srcList: props.src }); const [small, setSmall] = useState(props.small || false); const [disableResize, setDisableResize] = useState(false); const cRoot = useCRoot(); const imgRef = useRef(null); const [reRender, setReRender] = useState(false); const checkCanResize = () => { //if (isIOS || isSafari || engineName === "Webkit") return; const img = imgRef.current; if (img) { const { width, height } = img; if ( (width < 200 && height < 200) || (!small && width <= 200 && height <= 200) ) setDisableResize(true); } }; useEffect(() => { checkCanResize(); setReRender(!reRender); // eslint-disable-next-line react-hooks/exhaustive-deps }, [small]); return (
{!disableResize && ( { e.preventDefault(); e.stopPropagation(); setSmall(!small); }} className={"border-radius-10-force"} sx={{ position: "absolute", bgcolor: "primary.main", "&:hover": { bgcolor: "primary.dark", opacity: 0.9, }, right: 10, bottom: 10, opacity: 0.6, }} > {small ? : } )} 800 ? "auto" : width} style={{ ...(style && toJSON( prettier .format(style, { parser: "css", plugins: [prettierCss], }) .replaceAll("\n", "") ).attributes), ...(small && { maxWidth: 200, maxHeight: 200, }), }} loading="lazy" ref={imgRef} onLoad={() => { checkCanResize(); setReRender(!reRender); }} />
); } export default function Image(props: Props) { const { src } = props; return ( { e.preventDefault(); }} > } > ); }