1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-23 15:19:41 +02:00

feat: Add Servings/Yield to Recipe Actions (#4952)

Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
Michael Genson 2025-01-27 01:37:09 -06:00 committed by Ian Pösse-Koch
parent 45b5d5b9de
commit 49d0f58c6f
3 changed files with 13 additions and 4 deletions

View file

@ -49,7 +49,10 @@ export const useGroupRecipeActions = function (
return `${window.location.origin}/g/${groupSlug}/shared/r/${token}`;
}
async function parseRecipeActionUrl(url: string, recipe: Recipe): Promise<string> {
async function parseRecipeActionUrl(url: string, recipe: Recipe, recipeScale: number): Promise<string> {
const recipeServings = (recipe.recipeServings || 1) * recipeScale;
const recipeYieldQuantity = (recipe.recipeYieldQuantity || 1) * recipeScale;
/* eslint-disable no-template-curly-in-string */
const shareLinkRegex = /\$\{share-link-expires-seconds-[0-9]+\}/g;
const group = (await api.groups.getOne(recipe.groupId || "")).data;
@ -83,11 +86,14 @@ export const useGroupRecipeActions = function (
.replace("${url}", window.location.href)
.replace("${id}", recipe.id || "")
.replace("${slug}", recipe.slug || "")
.replace("${servings}", recipeServings.toString())
.replace("${yieldQuantity}", recipeYieldQuantity.toString())
.replace("${yieldText}", recipe.recipeYield || "")
/* eslint-enable no-template-curly-in-string */
};
async function execute(action: GroupRecipeActionOut, recipe: Recipe): Promise<void | RequestResponse<unknown>> {
const url = await parseRecipeActionUrl(action.url, recipe);
async function execute(action: GroupRecipeActionOut, recipe: Recipe, recipeScale: number): Promise<void | RequestResponse<unknown>> {
const url = await parseRecipeActionUrl(action.url, recipe, recipeScale);
switch (action.actionType) {
case "link":