diff --git a/apps/shinkai-visor/src/components/image-capture/image-capture.tsx b/apps/shinkai-visor/src/components/image-capture/image-capture.tsx index 44d0ce635..78e9c5600 100644 --- a/apps/shinkai-visor/src/components/image-capture/image-capture.tsx +++ b/apps/shinkai-visor/src/components/image-capture/image-capture.tsx @@ -22,7 +22,7 @@ htmlRoot.prepend(baseContainer); export const ImageCapture = () => { const [baseImage, setBaseImage] = useState(undefined); const [crop, setCrop] = useState(); - const imageRef= useRef(null); + const imageRef = useRef(null); const finishCaptureRef = useRef<(image: string) => void>(); useGlobalImageCaptureChromeMessage({ capture: ({ image: baseImage, finishCapture }) => { @@ -45,39 +45,49 @@ export const ImageCapture = () => { } return blob; }; - return baseImage && ( - { - console.log('crop change', _, percentCrop); - setCrop(percentCrop); - }} - onComplete={async (c) => { - console.log('crop completed', c); - if (typeof finishCaptureRef.current === 'function' && imageRef.current) { - if (c.width === 0 || c.height === 0) { - return; + return ( + baseImage && ( + { + console.log('crop change', _, percentCrop); + setCrop(percentCrop); + }} + onComplete={async (c) => { + console.log('crop completed', c); + if ( + typeof finishCaptureRef.current === 'function' && + imageRef.current + ) { + if (c.width === 0 || c.height === 0) { + return; + } + const croppedImage = await getCroppedImage( + imageRef.current, + c, + 1, + 0, + ); + if (!croppedImage) { + return; + } + const croppedImageAsBase64 = await blobToBase64(croppedImage); + finishCaptureRef.current(croppedImageAsBase64); + setBaseImage(''); + setCrop(undefined); } - const croppedImage = await getCroppedImage(imageRef.current, c, 1, 0); - if (!croppedImage) { - return; - } - const croppedImageAsBase64 = await blobToBase64(croppedImage); - finishCaptureRef.current(croppedImageAsBase64); - setBaseImage(''); - setCrop(undefined); - } - }} - style={{pointerEvents: 'all'}} - > - capture-placeholder - + }} + style={{ pointerEvents: 'all' }} + > + capture-placeholder + + ) ); }; const root = createRoot(container); @@ -86,8 +96,8 @@ root.render( -
- +
+
,