diff --git a/src/viser/client/src/components/Image.tsx b/src/viser/client/src/components/Image.tsx new file mode 100644 index 000000000..3274cd490 --- /dev/null +++ b/src/viser/client/src/components/Image.tsx @@ -0,0 +1,42 @@ +import { useEffect, useState } from "react"; +import { GuiImageMessage } from "../WebsocketMessages"; +import { Box, Text } from "@mantine/core"; + +function ImageComponent({ props }: GuiImageMessage) { + if (!props.visible) return <>; + + const [imageUrl, setImageUrl] = useState(null); + + useEffect(() => { + if (props.data === null) { + setImageUrl(null); + } else { + const image_url = URL.createObjectURL( + new Blob([props.data], { type: props.media_type }), + ); + setImageUrl(image_url); + return () => { + URL.revokeObjectURL(image_url); + }; + } + }, [props.data, props.media_type]); + + return imageUrl === null ? null : ( + + {props.label === null ? null : ( + + {props.label} + + )} + + + ); +} + +export default ImageComponent;