-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better implementation of removing and adding items on list
- Loading branch information
1 parent
bca29ef
commit ca0609b
Showing
5 changed files
with
167 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
imports/ui/organisms/groceries-list/utils/get-extra-ingredient-amount-by-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ActiveList } from "/interfaces/active-list"; | ||
|
||
export const getExtraIngredientAmountByName = ( | ||
activeList: ActiveList, | ||
name: string | ||
) => { | ||
const foundExtraIngredient = activeList.extraIngredients.find( | ||
(_ingredient) => _ingredient.name === name | ||
); | ||
|
||
let totalExtraIngredient = 0; | ||
|
||
if (foundExtraIngredient) { | ||
totalExtraIngredient = foundExtraIngredient.amount || 0; | ||
} | ||
|
||
return totalExtraIngredient; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
imports/ui/organisms/groceries-list/utils/get-total-recipe-amount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ActiveList } from "/interfaces/active-list"; | ||
|
||
export const getTotalRecipeAmountByName = ( | ||
activeList: ActiveList, | ||
name: string | ||
) => { | ||
const totalRecipeAmount = activeList.recipes.reduce((prev, current) => { | ||
const foundIngredient = current.recipe.food.ingredients.find( | ||
(_ingredient) => _ingredient.name === name | ||
); | ||
|
||
if (!foundIngredient) { | ||
return prev; | ||
} | ||
|
||
let amount = 0; | ||
|
||
if (foundIngredient) { | ||
const foundIngredientAmount = foundIngredient | ||
? foundIngredient.amount || 0 | ||
: 0; | ||
debugger; | ||
amount = | ||
(foundIngredientAmount / current.recipe.food.servings) * | ||
current.servings; | ||
} | ||
|
||
return prev + amount; | ||
}, 0); | ||
|
||
return totalRecipeAmount; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters