Skip to content

Commit

Permalink
Merge branch 'feature/GODIET-53-favorite-meal-add-general-information…
Browse files Browse the repository at this point in the history
…-about-favorite-meal' into develop
  • Loading branch information
vitorrsousaa committed Mar 22, 2024
2 parents 287c703 + a12a720 commit 42d4830
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,21 @@ export function SetFavoriteMealModal(props: SetFavoriteMealModalProps) {
<SelectContent>
<SelectGroup>
{favoritesMeals.map((option) => (
<SelectItem key={option.id} value={option.id}>
{option.name} - {option.energy} kcal
<SelectItem
key={option.id}
value={option.id}
className="flex flex-col items-start"
>
<div>
{option.name} - {option.energy} kcal
</div>
<div>
<span>Carb: {option.carb} (g)</span>
{' | '}
<span>Prot: {option.prot} (g)</span>
{' | '}
<span>Lipid: {option.prot} (g)</span>
</div>
</SelectItem>
))}
</SelectGroup>
Expand Down

0 comments on commit 42d4830

Please sign in to comment.