feat: implement scan-to-add flow (#25)
Some checks failed
Deploy to Coolify / Run Tests (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Development (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Production (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Test (pull_request) Has been cancelled
Pull Request Checks / Validate PR (pull_request) Has been cancelled
Deploy to Coolify / Code Quality (pull_request) Has been cancelled

- Create useProductLookup composable
- Integrate real product lookup in scan page
- Add query parameter handling in index.vue
- Pre-fill AddItemForm from scan data
- Parse quantity and unit from product data
- Include barcode and brand in notes

Complete end-to-end scan workflow:
1. Scan barcode
2. Fetch from Open Food Facts
3. Navigate to inventory with data
4. Pre-filled add form
5. One-click add to inventory

Closes #25
This commit is contained in:
Pantry Lead Agent
2026-02-24 00:04:10 +00:00
parent 670b2f9200
commit 7d35a3e7b3
4 changed files with 151 additions and 32 deletions

View File

@@ -72,49 +72,33 @@ definePageMeta({
const scannedBarcode = ref<string | null>(null)
const productData = ref<any>(null)
const isLookingUp = ref(false)
const lookupError = ref<string | null>(null)
const showManualEntry = ref(false)
// Use product lookup composable
const { lookupProduct, isLoading: isLookingUp, error: lookupError } = useProductLookup()
const handleBarcodeDetected = async (barcode: string) => {
scannedBarcode.value = barcode
lookupError.value = null
isLookingUp.value = true
try {
// TODO: Implement product lookup via Edge Function (Issue #24)
// For now, create a basic product object
await new Promise(resolve => setTimeout(resolve, 1000)) // Simulate API call
productData.value = {
name: `Product ${barcode}`,
brand: 'Unknown Brand',
barcode: barcode,
image_url: null
}
lookupError.value = 'Product lookup not yet implemented. Using default data.'
} catch (error) {
console.error('Product lookup error:', error)
lookupError.value = 'Failed to look up product. You can still add it manually.'
productData.value = {
name: `Product ${barcode}`,
barcode: barcode
}
} finally {
isLookingUp.value = false
// Fetch product data from Edge Function
const data = await lookupProduct(barcode)
if (data) {
productData.value = data
}
}
const addToInventory = () => {
// TODO: Implement scan-to-add flow (Issue #25)
// Navigate to add form with pre-filled data
// Navigate to home page with add form open and pre-filled
navigateTo({
path: '/',
query: {
action: 'add',
barcode: scannedBarcode.value,
name: productData.value?.name,
brand: productData.value?.brand
name: productData.value?.name || undefined,
brand: productData.value?.brand || undefined,
image_url: productData.value?.image_url || undefined,
quantity: productData.value?.quantity || undefined
}
})
}