fix: use processed image blob from modal for backend submission

Critical fix: modal processes image and returns blob, but AIOnboarding
was not actually using that blob. Now properly calls setExtractedImageBlob()
so confirmSingleItem sends the processed image to backend.

Before: Backend received original image, applied original AI crop/rotation
After: Backend receives processed image (already cropped/rotated by user)

Now the saved image matches exactly what user sees after adjusting.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 13:46:11 +03:00
parent f61c1fbe5f
commit 8ed8265a7a
2 changed files with 9 additions and 17 deletions

View File

@@ -34,6 +34,8 @@ export default function AIOnboarding({ onCancel, onComplete, categories, invento
fileInputRef,
existingTypes,
existingBoxes,
extractedImageBlob,
setExtractedImageBlob,
startLiveCamera,
stopLiveCamera,
captureSnapshot,
@@ -81,27 +83,17 @@ export default function AIOnboarding({ onCancel, onComplete, categories, invento
user_adjusted: true
}
};
setExtractedItems(updatedItems);
// If modal processed and returned image blob, use that instead of original
// If modal processed and returned image blob, update the hook's state
// so confirmSingleItem uses the processed blob instead of original
if (adjustments.imageBlob) {
// Convert blob to base64 for extracted_image_bytes
const reader = new FileReader();
reader.onload = () => {
const base64 = (reader.result as string).split(',')[1];
updatedItems[index].extractedImageBlob = adjustments.imageBlob;
updatedItems[index]._base64ImageData = base64;
setExtractedItems(updatedItems);
hookConfirmSingleItem(index);
};
reader.readAsDataURL(adjustments.imageBlob);
} else {
setExtractedItems(updatedItems);
hookConfirmSingleItem(index);
setExtractedImageBlob(adjustments.imageBlob);
}
} else {
hookConfirmSingleItem(index);
}
// Always call confirm, even without adjustments
hookConfirmSingleItem(index);
setShowImageAdjustment(false);
setAdjustingItemIndex(null);
setPendingItemData(null);