From 4e346b2ef9ff1cd8fbb5f1fcd3b5f463350ad61a Mon Sep 17 00:00:00 2001 From: Benedikt Wagener Date: Thu, 20 Aug 2026 22:29:31 +0000 Subject: [PATCH] feat: add optional linked ingredients to print view (#7632) Co-authored-by: Michael Genson Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> --- .../Recipe/RecipeDialogPrintPreferences.vue | 13 +++++ .../Domain/Recipe/RecipePrintView.vue | 54 +++++++++++++++++++ .../app/composables/use-users/preferences.ts | 2 + frontend/app/lang/messages/en-US.json | 1 + 4 files changed, 70 insertions(+) diff --git a/frontend/app/components/Domain/Recipe/RecipeDialogPrintPreferences.vue b/frontend/app/components/Domain/Recipe/RecipeDialogPrintPreferences.vue index b20dd2bed..681d6e063 100644 --- a/frontend/app/components/Domain/Recipe/RecipeDialogPrintPreferences.vue +++ b/frontend/app/components/Domain/Recipe/RecipeDialogPrintPreferences.vue @@ -78,6 +78,19 @@ /> + + + + + + + @@ -362,6 +388,27 @@ const hasNotes = computed(() => { return props.recipe.notes && props.recipe.notes.length > 0; }); +// Precompute each step's linked ingredients so the template doesn't re-filter recipeIngredient on every render +const stepLinkedIngredients = computed(() => { + const map = new Map(); + + instructionSections.value.forEach((section, sectionIndex) => { + section.instructions.forEach((step, stepIndex) => { + if (!step.ingredientReferences?.length) { + return; + } + + const referenceIds = new Set(step.ingredientReferences.map(ref => ref.referenceId)); + map.set( + `${sectionIndex}-${stepIndex}`, + props.recipe.recipeIngredient.filter(ing => ing.referenceId && referenceIds.has(ing.referenceId)), + ); + }); + }); + + return map; +}); + const { parseIngredientText } = useIngredientTextParser(); function parseText(ingredient: RecipeIngredient) { @@ -403,6 +450,13 @@ p { grid-gap: 0.5rem; } +.step-ingredient-grid { + display: grid; + grid-auto-flow: column; + grid-template-columns: 1fr 1fr; + grid-gap: 0.2rem; +} + .ingredient-title, .instruction-title { grid-column: 1 / span 2; diff --git a/frontend/app/composables/use-users/preferences.ts b/frontend/app/composables/use-users/preferences.ts index 401cf7e50..3fc21a125 100644 --- a/frontend/app/composables/use-users/preferences.ts +++ b/frontend/app/composables/use-users/preferences.ts @@ -6,6 +6,7 @@ import type { QueryFilterJSON } from "~/lib/api/types/non-generated"; export interface UserPrintPreferences { imagePosition: string; showDescription: boolean; + showLinkedIngredients: boolean; showNotes: boolean; showNutrition: boolean; expandChildRecipes: boolean; @@ -98,6 +99,7 @@ export function useUserPrintPreferences(): Ref { { imagePosition: "left" as ImagePosition, showDescription: true, + showLinkedIngredients: false, showNotes: true, showNutrition: false, expandChildRecipes: false, diff --git a/frontend/app/lang/messages/en-US.json b/frontend/app/lang/messages/en-US.json index 94d721214..c7e26581f 100644 --- a/frontend/app/lang/messages/en-US.json +++ b/frontend/app/lang/messages/en-US.json @@ -431,6 +431,7 @@ "milligrams": "milligrams", "note": "Note", "nutrition": "Nutrition", + "linked-ingredients": "Linked Ingredients", "original-url": "Original URL", "perform-time": "Cook Time", "prep-time": "Prep Time",