feat: add optional linked ingredients to print view (#7632)

Co-authored-by: Michael Genson <genson.michael@gmail.com>
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-08-20 17:29:31 -05:00
1 parent feaa1c73af
commit 4e346b2ef9
4 files changed
+70

No files matched your search

@@ -78,6 +78,19 @@
/>
</v-row>
</v-col>
<v-col
cols="auto"
align-self="start"
>
<v-row no-gutters>
<v-switch
v-model="preferences.showLinkedIngredients"
hide-details
color="primary"
:label="$t('recipe.linked-ingredients')"
/>
</v-row>
</v-col>
</v-row>
</v-container>
<v-card
@@ -130,6 +130,32 @@
:source="step.text"
class="recipe-step-body"
/>
<!-- Step Ingredients -->
<div
v-if="preferences.showLinkedIngredients && step.ingredientReferences && step.ingredientReferences.length > 0"
class="print-section"
>
<h6
class="ingredient-title mt-2 mb-0"
>
{{ $t("recipe.ingredients") }}
</h6>
<div
class="step-ingredient-grid"
:style="{ gridTemplateRows: `repeat(${Math.ceil(step.ingredientReferences.length / 2)}, min-content)` }"
>
<template
v-for="(ingredient, ingredientIndex) in stepLinkedIngredients.get(`${sectionIndex}-${stepIndex}`) ?? []"
:key="`ingredient-${ingredientIndex}`"
>
<!-- eslint-disable-next-line vue/no-v-html -->
<p
class="ingredient-body"
v-html="parseText(ingredient)"
/>
</template>
</div>
</div>
</div>
</div>
</div>
@@ -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<string, RecipeIngredient[]>();
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;
@@ -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<UserPrintPreferences> {
{
imagePosition: "left" as ImagePosition,
showDescription: true,
showLinkedIngredients: false,
showNotes: true,
showNutrition: false,
expandChildRecipes: false,
+1
View File
@@ -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",