@@ -15,7 +15,7 @@ import { theme, addOpacityToHex } from '../../theme';
1515import { FullScreenModal } from './FullScreenModal' ;
1616import { FoodDetailsModal } from './FoodDetailsModal' ;
1717import { useFoodSearch , useProductDetails } from '../../hooks/useSearchFood' ;
18- import { type FoodProduct } from '../../types/openFoodFacts' ;
18+ import { type SearchResultProduct } from '../../types/openFoodFacts' ;
1919
2020type FoodItem = {
2121 id : string ;
@@ -323,36 +323,34 @@ export function FoodSearchModal({
323323 { id : 'recipes' , label : t ( 'foodSearch.filters.recipes' ) } ,
324324 ] ;
325325
326- const handleFoodClick = ( food : FoodProduct ) => {
327- setSelectedBarcode ( food . id ) ;
326+ const handleFoodClick = ( food : SearchResultProduct ) => {
327+ setSelectedBarcode ( food . code || null ) ;
328328
329- // Convert FoodProduct to FoodItem format
329+ // Convert SearchResultProduct to FoodItem format
330330 const foodItem : FoodItem = {
331- id : food . id ,
332- name : food . name ,
333- description : `${ food . brand || 'Generic' } • ${ formatCalories ( food ) } ` ,
334- brand : food . brand ,
331+ id : food . code || String ( Math . random ( ) ) ,
332+ name : food . product_name || 'Unknown Product' ,
333+ description : `${ food . brands || food . generic_name || 'Generic' } • ${ formatCalories ( food ) } ` ,
334+ brand : food . brands ,
335335 imageUrl : food . image_url ,
336336 serving_size : food . serving_size ,
337337 nutriments : food . nutriments ,
338- _raw : food . _raw ,
338+ _raw : food ,
339339 } ;
340340
341341 setSelectedFood ( foodItem ) ;
342342 setIsFoodDetailsVisible ( true ) ;
343343 } ;
344344
345- const formatCalories = useCallback ( ( food : FoodProduct ) => {
346- const kcalPer100g = food . nutriments ?. [ 'energy-kcal_100g' ] ;
347- const kcalServing = food . nutriments ?. [ 'energy-kcal_serving' ] ;
345+ const formatCalories = useCallback ( ( food : SearchResultProduct ) => {
346+ const kcal = food . nutriments ?. [ 'energy-kcal' ] ;
348347
349- if ( kcalPer100g ) {
350- return `${ Math . round ( kcalPer100g ) } kcal / 100g ` ;
348+ if ( kcal ) {
349+ return `${ Math . round ( kcal ) } kcal` ;
351350 }
352- if ( kcalServing && food . serving_size ) {
353- return `${ Math . round ( kcalServing ) } kcal / ${ food . serving_size } ` ;
354- }
355- return 'Nutrition info unavailable' ;
351+
352+ // TODO: calculate using macro values
353+ return 'N/A' ;
356354 } , [ ] ) ;
357355
358356 const headerRight = (
@@ -464,16 +462,16 @@ export function FoodSearchModal({
464462 { ! isLoading && ! error && foods . length > 0
465463 ? foods . map ( ( food ) => (
466464 < FoodItemCard
467- key = { food . id }
465+ key = { food . code }
468466 food = { {
469- id : food . id ,
470- name : food . name ,
471- description : `${ food . brand || 'Generic' } • ${ formatCalories ( food ) } ` ,
472- brand : food . brand ,
467+ id : food . code || String ( Math . random ( ) ) ,
468+ name : food . product_name || 'Unknown Product' ,
469+ description : `${ food . brands || food . generic_name || 'Generic' } • ${ formatCalories ( food ) } ` ,
470+ brand : food . brands ,
473471 imageUrl : food . image_url ,
474472 serving_size : food . serving_size ,
475473 nutriments : food . nutriments ,
476- _raw : food . _raw ,
474+ _raw : food ,
477475 } }
478476 onAddPress = { ( ) => handleFoodClick ( food ) }
479477 />
0 commit comments