Skip to content

Commit

Permalink
feat: Add Servings/Yield to Recipe Actions (#4952)
Browse files Browse the repository at this point in the history
Co-authored-by: Kuchenpirat <[email protected]>
  • Loading branch information
michael-genson and Kuchenpirat authored Jan 27, 2025
1 parent 7e5c750 commit 3424568
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/docs/documentation/getting-started/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ Below is a list of all valid merge fields:
- ${id}
- ${slug}
- ${url}
- ${servings}
- ${yieldQuantity}
- ${yieldText}

To add, modify, or delete Recipe Actions, visit the Data Management page (more on that below).

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default defineComponent({
const groupRecipeActionsStore = useGroupRecipeActions();
async function executeRecipeAction(action: GroupRecipeActionOut) {
const response = await groupRecipeActionsStore.execute(action, props.recipe);
const response = await groupRecipeActionsStore.execute(action, props.recipe, props.recipeScale);
if (action.actionType === "post") {
if (!response?.error) {
Expand Down
12 changes: 9 additions & 3 deletions frontend/composables/use-group-recipe-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,23 @@ export const useGroupRecipeActions = function (
return groupRecipeActions.value;
});

function parseRecipeActionUrl(url: string, recipe: Recipe): string {
function parseRecipeActionUrl(url: string, recipe: Recipe, recipeScale: number): string {
const recipeServings = (recipe.recipeServings || 1) * recipeScale;
const recipeYieldQuantity = (recipe.recipeYieldQuantity || 1) * recipeScale;

/* eslint-disable no-template-curly-in-string */
return url
.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 = parseRecipeActionUrl(action.url, recipe);
async function execute(action: GroupRecipeActionOut, recipe: Recipe, recipeScale: number): Promise<void | RequestResponse<unknown>> {
const url = parseRecipeActionUrl(action.url, recipe, recipeScale);

switch (action.actionType) {
case "link":
Expand Down

0 comments on commit 3424568

Please sign in to comment.