Skip to content

Commit

Permalink
Merge pull request #145 from simplitrac/mobile-fix-picture
Browse files Browse the repository at this point in the history
Mobile fix picture
  • Loading branch information
anpaulan authored Sep 9, 2024
2 parents 6c90f09 + 4f5fb21 commit dad3450
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions client/src/components/Camera.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ const Camera = () => {
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
setCapturedPhoto(e.target.result);
const capturedImage = e.target.result;
setCapturedPhoto(capturedImage);
if (device === 'mobile'){
submitPhoto().then(() => {
submitPhoto(capturedImage).then(() => {
setCapturedPhoto(null);
setIsUpdating(false);
});
Expand All @@ -86,11 +87,17 @@ const Camera = () => {
}
};

const submitPhoto = async () => {
const submitPhoto = async (capturedMobileImage) => {
let imageData;
if(device === "desktop"){
imageData = capturedPhoto;
} else if (device === "mobile"){
imageData = capturedMobileImage
}
try {
setIsUpdating(true);
const url = import.meta.env.VITE_PROD_OCR_ENDPOINT;
const formData = imageToFormData(capturedPhoto);
const formData = imageToFormData(imageData);
const init = {
method: 'POST',
body: formData,
Expand All @@ -115,7 +122,7 @@ const Camera = () => {
}
} catch (error) {
console.error('Error submitting photo:', error);
alert('An error occurred while processing the image. Please try again.');
alert(`An error occurred while processing the image. Please try again ${error}`);
} finally {
setIsUpdating(false);
}
Expand Down Expand Up @@ -176,7 +183,6 @@ const Camera = () => {
<BackButton />
</div>
)}

<canvas ref={canvasRef} style={styles.hiddenCanvas}></canvas>
</div>
);
Expand Down

0 comments on commit dad3450

Please sign in to comment.