From d43fae5c1704b4d589fdcd14eea0fdb2c5237ba8 Mon Sep 17 00:00:00 2001 From: danaharper151 Date: Wed, 2 Dec 2026 18:36:37 -0800 Subject: [PATCH] feat(nutrition): headline totals, abbreviated units, stacked viewer Hides the number steppers that covered values in the recipe page's narrow aside, adds a row of the five headline figures above the fields, abbreviates units to kcal/g/mg within this card, and restyles the read-only list to match the edit layout so long labels no longer truncate. Co-Authored-By: Claude Opus 5 --- .../Domain/Recipe/RecipeNutrition.vue | 88 ++++++++++++++++--- frontend/app/lang/messages/en-US.json | 10 ++- 2 files changed, 83 insertions(+), 15 deletions(-) diff --git a/frontend/app/components/Domain/Recipe/RecipeNutrition.vue b/frontend/app/components/Domain/Recipe/RecipeNutrition.vue index 30a4f86d4..bebd25346 100644 --- a/frontend/app/components/Domain/Recipe/RecipeNutrition.vue +++ b/frontend/app/components/Domain/Recipe/RecipeNutrition.vue @@ -7,6 +7,25 @@ {{ $t("recipe.per-serving") }} + + +
+
+ {{ total.label }} + {{ total.value }} + {{ total.suffix }} +
+
+ - +
- - -
{{ item.label }}
-
- {{ item.value }} +
+ {{ item.label }} +
+
+
{{ item.value }}
+
+ {{ item.suffix }}
-
{{ item.suffix }}
- - - +
+ +
+
(null); +/** Abbreviated units. Mealie's own suffixes are spelled out ("milligrams"), + * which is wider than the value column in the recipe page's narrow aside. + * Scoped to this card rather than changing the shared i18n strings. */ +const MILLIGRAM_FIELDS = new Set(["cholesterolContent", "sodiumContent"]); + +function unitFor(key: number | string): string { + if (key === "calories") { + return i18n.t("recipe.nutrition-unit-calories"); + } + return MILLIGRAM_FIELDS.has(String(key)) + ? i18n.t("recipe.nutrition-unit-milligrams") + : i18n.t("recipe.nutrition-unit-grams"); +} + +/** The five figures people actually look for first. */ +const HEADLINE_KEYS: { key: keyof Nutrition; labelKey: string }[] = [ + { key: "calories", labelKey: "recipe.nutrition-abbr-calories" }, + { key: "fatContent", labelKey: "recipe.nutrition-abbr-fat" }, + { key: "proteinContent", labelKey: "recipe.nutrition-abbr-protein" }, + { key: "carbohydrateContent", labelKey: "recipe.nutrition-abbr-carbs" }, + { key: "fiberContent", labelKey: "recipe.nutrition-abbr-fiber" }, +]; + const valueNotNull = computed(() => { let key: keyof Nutrition; for (key in modelValue.value) { @@ -117,6 +165,17 @@ const valueNotNull = computed(() => { const showViewer = computed(() => !props.edit && valueNotNull.value); +const headlineTotals = computed(() => + HEADLINE_KEYS + .filter(({ key }) => modelValue.value[key]?.trim()) + .map(({ key, labelKey }) => ({ + key, + label: i18n.t(labelKey), + value: modelValue.value[key] as string, + suffix: unitFor(key), + })), +); + // The calculator works on the rendered ingredient text, which is what the // backend's parser expects as input. const ingredientLines = computed(() => @@ -158,6 +217,7 @@ const renderedList = computed(() => { if (modelValue.value[key]?.trim()) { item[key] = { ...label, + suffix: unitFor(key), value: modelValue.value[key], }; } diff --git a/frontend/app/lang/messages/en-US.json b/frontend/app/lang/messages/en-US.json index d92174376..1eb0ea857 100644 --- a/frontend/app/lang/messages/en-US.json +++ b/frontend/app/lang/messages/en-US.json @@ -744,7 +744,15 @@ "nutrition-lookup-failed": "Could not reach the nutrition service.", "nutrition-no-match": "No match found - this ingredient will be skipped.", "nutrition-not-configured": "Nutrition lookup is not configured on this server.", - "nutrition-skipped": "skipped" + "nutrition-skipped": "skipped", + "nutrition-abbr-calories": "Cal", + "nutrition-abbr-carbs": "Carbs", + "nutrition-abbr-fat": "Fat", + "nutrition-abbr-fiber": "Fiber", + "nutrition-abbr-protein": "Protein", + "nutrition-unit-calories": "kcal", + "nutrition-unit-grams": "g", + "nutrition-unit-milligrams": "mg" }, "recipe-finder": { "recipe-finder": "Recipe Finder", -- 2.47.3