From a12a7207f7ce49f9ddd20a53fa7f92a83bde4deb Mon Sep 17 00:00:00 2001 From: Vitor Sousa Date: Thu, 21 Mar 2024 06:07:37 -0300 Subject: [PATCH] feat(GODIET-53): :sparkles: add informations about favorite meal --- .../SetFavoriteMealModal.hook.ts | 26 +++++++++++++++++++ .../SetFavoriteMealModal.tsx | 17 ++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.hook.ts b/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.hook.ts index 17ad31b..2061ced 100644 --- a/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.hook.ts +++ b/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.hook.ts @@ -51,10 +51,36 @@ export function useSetFavoriteMealModalHook(props: SetFavoriteMealModalProps) { return acc + energyAttribute.qty; }, 0); + const totalProt = mealFoods.reduce((acc, mealFood) => { + const protAttribute = mealFood.food.attributes.find( + (attribute) => attribute.name === 'protein' + ); + + if (!protAttribute) { + return acc; + } + + return acc + protAttribute.qty; + }, 0); + + const totalCarb = mealFoods.reduce((acc, mealFood) => { + const carbAttribute = mealFood.food.attributes.find( + (attribute) => attribute.name === 'carbohydrate' + ); + + if (!carbAttribute) { + return acc; + } + + return acc + carbAttribute.qty; + }, 0); + return { name: favorite.name, id: favorite.id, energy: Math.floor(totalEnergy), + prot: Math.floor(totalProt), + carb: Math.floor(totalCarb), }; }), [favorites] diff --git a/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.tsx b/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.tsx index a652074..6458939 100644 --- a/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.tsx +++ b/src/view/pages/CreatePlanning/components/modals/SetFavoriteMealModal/SetFavoriteMealModal.tsx @@ -67,8 +67,21 @@ export function SetFavoriteMealModal(props: SetFavoriteMealModalProps) { {favoritesMeals.map((option) => ( - - {option.name} - {option.energy} kcal + +
+ {option.name} - {option.energy} kcal +
+
+ Carb: {option.carb} (g) + {' | '} + Prot: {option.prot} (g) + {' | '} + Lipid: {option.prot} (g) +
))}