feat(nutrition): headline totals, abbreviated units, stacked viewer #5

Merged
dana merged 1 commits from feat/nutrition-ui-polish into mealie-next 2026-12-03 02:52:17 +00:00
2 changed files with 83 additions and 15 deletions

No files matched your search

@@ -7,6 +7,25 @@
<v-card-subtitle class="pb-1">
{{ $t("recipe.per-serving") }}
</v-card-subtitle>
<!-- At-a-glance totals. Shown in both edit and view mode so the headline
figures are readable without scanning eleven rows. -->
<div
v-if="headlineTotals.length"
class="d-flex flex-wrap px-4 pt-1 pb-2"
style="gap: 2px 14px"
>
<div
v-for="total in headlineTotals"
:key="total.key"
class="text-caption"
>
<span class="font-weight-medium">{{ total.label }}</span>
<span class="ml-1">{{ total.value }}</span>
<span class="ml-1 text-medium-emphasis">{{ total.suffix }}</span>
</div>
</div>
<v-divider class="mx-2 my-1" />
<v-card-text v-if="edit">
<v-btn
@@ -36,10 +55,11 @@
<v-number-input
:model-value="parseNutritionValue(modelValue[key])"
:label="labels[key].label"
:suffix="labels[key].suffix"
:suffix="unitFor(key)"
density="compact"
autocomplete="off"
variant="underlined"
control-variant="hidden"
inset
:precision="null"
:min="0"
@@ -47,25 +67,30 @@
/>
</div>
</v-card-text>
<v-list
<!-- Mirrors the stacked layout of the edit fields: label on its own line,
value and unit beneath, hairline rule between. Full labels stay
readable in a narrow column without truncating. -->
<div
v-if="showViewer"
density="compact"
class="mt-0 pt-0"
class="px-4 pb-3"
>
<v-list-item
<div
v-for="(item, key, index) in renderedList"
:key="index"
style="min-height: 25px"
class="mb-2"
>
<v-list-item-title class="pl-2 d-flex">
<div>{{ item.label }}</div>
<div class="ml-auto mr-1">
{{ item.value }}
<div class="text-caption text-medium-emphasis">
{{ item.label }}
</div>
<div class="d-flex align-baseline">
<div>{{ item.value }}</div>
<div class="ml-auto text-caption text-medium-emphasis">
{{ item.suffix }}
</div>
<div>{{ item.suffix }}</div>
</v-list-item-title>
</v-list-item>
</v-list>
</div>
<v-divider class="mt-1" />
</div>
</div>
</v-card>
<RecipeNutritionCalculator
@@ -105,6 +130,29 @@ const i18n = useI18n();
const calculatorOpen = ref(false);
const lastResult = ref<NutritionCalculation | null>(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],
};
}
+9 -1
View File
@@ -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",