Tested and working, added ability to use vite

This commit is contained in:
Craig
2026-08-02 18:46:23 +01:00
parent fc30b28921
commit 42c4deca75
12 changed files with 143 additions and 25 deletions
+13 -2
View File
@@ -107,37 +107,48 @@
}
async function handleBarcode(barcode) {
console.log('[App] handleBarcode:', barcode)
resetScanFlow()
scanBarcode = barcode
scanLoading = true
// Step 1: Check local DB by barcode
try {
console.log('[App] searching local DB for barcode:', barcode)
const results = await api.searchFoodsByBarcode(barcode)
console.log('[App] local search results:', results?.length ?? 0)
if (results && results.length > 0) {
localFood = results[0]
scanLogQuantity = defaultQuantity(localFood)
scanLoading = false
scanPhase = 'localFound'
console.log('[App] local food found:', localFood.name)
return
}
console.log('[App] not found locally, trying OpenFoodFacts…')
} catch (e) {
console.warn('[App] local search failed:', e)
// Local lookup failed — try OFF anyway
}
// Step 2: Not found locally → try OFF
try {
console.log('[App] fetching OFF product:', barcode)
offFood = await api.offProduct(barcode)
scanLoading = false
scanPhase = 'offFound'
console.log('[App] OFF product found:', offFood?.product_name ?? offFood?.name)
} catch (e) {
console.warn('[App] OFF lookup failed:', e.message)
// OFF miss (404) or network error
scanLoading = false
if (e.message?.includes('404') || e.message?.includes('not found')) {
scanPhase = 'notFound'
console.log('[App] OFF product not found (404)')
} else {
scanError = e.message
scanPhase = 'error'
console.error('[App] OFF lookup error:', e.message)
}
}
}
@@ -572,8 +583,8 @@
padding: 0 0.3rem;
}
.macro-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.form-actions {