Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f95956205b | ||
|
|
06a0cb9cf4 | ||
|
|
10831c7f65 | ||
|
|
582b4a0fca |
No files matched your search
@@ -7,7 +7,7 @@
|
||||
> **Plattform:** Olares One (Kubernetes), Repo und CI auf Gitea — kein Supabase,
|
||||
> kein Vercel (E-0001). Eigene Gestaltung, nicht AImighty (E-0002).
|
||||
> Verteilung über den Markt, Repo öffentlich (E-0005).
|
||||
> **Status:** 26.11.48 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut:
|
||||
> **Status:** 26.11.52 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut:
|
||||
> Anmeldung (Passkeys, Kinder mit Gerät + PIN), Gerichte (Link, Kochbuchfoto, AI über den
|
||||
> Olares Router), Wünschen, Plan, Einkaufsliste (Echtzeit, offline), Kochmodus mit
|
||||
> Bewertung, Web-App; Einzahl bei Stück-Mengen (26.11.15), Preise und Kosten mit Ampel
|
||||
@@ -22,7 +22,7 @@
|
||||
> (26.11.39, E-0016), Anmelden per Mail-Link über Resend (26.11.40, E-0017; nur
|
||||
> anmelden, keine Geräte oder Passkeys aus einer Mail-Sitzung), Leiste bleibt nach der
|
||||
> Tastatur unten (26.11.41), Icon Kochmütze mit Herz (26.11.42), Fotos aus der Mediathek (26.11.43), gleich große Karten (26.11.44), Runde beenden/löschen/ändern,
|
||||
> Tage je Gericht von Hand und Kalender-Abo je Haushalt (26.11.45, E-0018), Einkaufsliste einsprechen (26.11.46), Herz für „Mein Gericht“ auf jeder Wunschkarte (26.11.47), Kochbuch mit bis zu sechs Seiten (26.11.48). Offen: Kai trägt
|
||||
> Tage je Gericht von Hand und Kalender-Abo je Haushalt (26.11.45, E-0018), Einkaufsliste einsprechen (26.11.46), Herz für „Mein Gericht“ auf jeder Wunschkarte (26.11.47), Kochbuch mit bis zu sechs Seiten (26.11.48), Portionen rechnen beim Bearbeiten mit und mehr Maße (26.11.49), ml und l bei jeder Zutat (26.11.50), Fehlendes im Formular am Feld markiert und gezählt (26.11.51), Desktop zeigt die Handy-Spalte (26.11.52). Offen: Kai trägt
|
||||
> den Resend-Schlüssel unter Mehr › Mails verschicken ein und abonniert den Kalender-Link einmal auf dem iPhone.
|
||||
> **Letzte Aktualisierung:** 8. November 2026
|
||||
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ metadata:
|
||||
title: foodplanhero
|
||||
description: Plan. Cook. Smile. The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box.
|
||||
icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png
|
||||
version: 26.11.48
|
||||
version: 26.11.52
|
||||
categories:
|
||||
- Applications
|
||||
|
||||
@@ -61,7 +61,7 @@ permission:
|
||||
appData: true
|
||||
|
||||
spec:
|
||||
versionName: '26.11.48'
|
||||
versionName: '26.11.52'
|
||||
|
||||
featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png
|
||||
promoteImage:
|
||||
|
||||
@@ -4,16 +4,17 @@ import { DishForm } from "@/components/dishes/dish-form";
|
||||
import { requireSession } from "@/lib/auth/session";
|
||||
import { withHousehold } from "@/lib/db";
|
||||
import { getDish } from "@/lib/dishes";
|
||||
import { fromBase, type BaseUnit, type KitchenUnit } from "@/lib/units";
|
||||
import { fromBase, niceQty, type BaseUnit, type DisplayUnit } from "@/lib/units";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// Bearbeiten zeigt die Mengen für vier Portionen (oder was man dort einträgt).
|
||||
const PORTIONS = 4;
|
||||
// Bearbeiten zeigt die Mengen für so viele Portionen, wie das Rezept eingegeben wurde
|
||||
// (26.11.49); ältere Gerichte für vier. Gerundet, wie man es tippen würde.
|
||||
const OLDER = 4;
|
||||
|
||||
function amountIn(qty: number, unit: BaseUnit, display: KitchenUnit | null, packSize: number | null) {
|
||||
function amountIn(qty: number, unit: BaseUnit, display: DisplayUnit | null, packSize: number | null) {
|
||||
const n = display ? fromBase(qty, display, unit, packSize) : null;
|
||||
return n === null ? { qty, unit } : { qty: Math.round(n * 100) / 100, unit: display as string };
|
||||
return n === null ? { qty: niceQty(qty, unit), unit } : { qty: niceQty(n, display!), unit: display as string };
|
||||
}
|
||||
|
||||
export default async function EditDishPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
@@ -25,6 +26,7 @@ export default async function EditDishPage({ params }: { params: Promise<{ id: s
|
||||
const t = await getTranslations("dishes");
|
||||
const dish = await withHousehold(session.householdId, (c) => getDish(c, id, locale));
|
||||
if (!dish) notFound();
|
||||
const portions = dish.recipePortions ?? OLDER;
|
||||
return (
|
||||
<main className="mx-auto flex max-w-md flex-col gap-5 px-4 py-6">
|
||||
<header className="flex flex-col gap-1">
|
||||
@@ -35,16 +37,16 @@ export default async function EditDishPage({ params }: { params: Promise<{ id: s
|
||||
initial={{
|
||||
id: dish.id,
|
||||
title: dish.title,
|
||||
portions: PORTIONS,
|
||||
portions,
|
||||
base: dish.base,
|
||||
tags: dish.tags,
|
||||
effortMinutes: dish.effortMinutes,
|
||||
isTrial: dish.isTrial,
|
||||
sourceUrl: dish.sourceUrl,
|
||||
ingredients: dish.ingredients.map((i) => ({
|
||||
ingredient: { id: i.ingredientId, name: i.name, unit: i.unit, kitchenUnit: i.kitchenUnit, packKind: i.packKind, packSize: i.packSize },
|
||||
ingredient: { id: i.ingredientId, name: i.name, unit: i.unit, kitchenUnit: i.kitchenUnit, packKind: i.packKind, packSize: i.kindSize, sizes: i.sizes },
|
||||
// Im Maß, in dem sie eingegeben wurde: „2 EL“, „1 Dose“ (26.11.39).
|
||||
...amountIn(i.qtyPerPortion * PORTIONS, i.unit, i.displayUnit, i.packSize),
|
||||
...amountIn(i.qtyPerPortion * portions, i.unit, i.displayUnit, i.packSize),
|
||||
note: i.note,
|
||||
product: i.product,
|
||||
})),
|
||||
|
||||
@@ -51,7 +51,7 @@ export default async function DishPage({ params }: { params: Promise<{ id: strin
|
||||
.join(" · ");
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex max-w-2xl flex-col gap-5 pb-6">
|
||||
<main className="mx-auto flex max-w-md flex-col gap-5 pb-6">
|
||||
<div className="relative aspect-[4/3] overflow-hidden sm:mx-4 sm:mt-4 sm:rounded-2xl">
|
||||
<DishPhoto dishId={dish.id} photo={dish.photo} />
|
||||
<Link
|
||||
|
||||
@@ -47,7 +47,7 @@ export default async function DishesPage({ searchParams }: { searchParams: Promi
|
||||
[d.effortMinutes ? t("minutes", { n: d.effortMinutes }) : null, d.base ? t(`bases.${d.base}`) : null, cost(d.id)].filter(Boolean).join(" · ");
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex max-w-2xl flex-col gap-5 px-4 py-6">
|
||||
<main className="mx-auto flex max-w-md flex-col gap-5 px-4 py-6">
|
||||
<header className="flex items-end justify-between gap-3">
|
||||
<div className="flex flex-col gap-1">
|
||||
<p className="eyebrow">{t("eyebrow")}</p>
|
||||
@@ -83,7 +83,7 @@ export default async function DishesPage({ searchParams }: { searchParams: Promi
|
||||
</nav>
|
||||
|
||||
{dishes.length ? (
|
||||
<ul className="grid grid-cols-2 gap-3 sm:grid-cols-3">
|
||||
<ul className="grid grid-cols-2 gap-3">
|
||||
{dishes.map((d) => (
|
||||
<li key={d.id} className="h-full">
|
||||
<DishTile id={d.id} title={d.title} photo={d.photo} meta={meta(d)} />
|
||||
@@ -107,7 +107,7 @@ export default async function DishesPage({ searchParams }: { searchParams: Promi
|
||||
href="/gerichte/hinzufuegen"
|
||||
className={cn(
|
||||
buttonVariants({ size: "lg" }),
|
||||
"kb-shift fixed bottom-[calc(4.5rem+env(safe-area-inset-bottom))] right-4 z-10 shadow-lg",
|
||||
"kb-shift fixed bottom-[calc(4.5rem+env(safe-area-inset-bottom))] right-[max(1rem,calc((100vw-28rem)/2+1rem))] z-10 shadow-lg",
|
||||
)}
|
||||
>
|
||||
<Plus aria-hidden />
|
||||
|
||||
@@ -4,6 +4,8 @@ import { requireSession } from "@/lib/auth/session";
|
||||
// Alles hier drin verlangt eine Sitzung. Die Prüfung steht im Layout und
|
||||
// zusätzlich in jeder Seite, die Daten liest (requireSession) — Layouts
|
||||
// werden beim Navigieren nicht jedes Mal neu ausgeführt.
|
||||
// Jede Seite steht in einer Spalte wie am Handy, auch am Desktop (max-w-md; Kai,
|
||||
// 9.11.2026). Nur Küchendisplay, Präsentation und Kochmodus im Querformat sind breiter.
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AppLayout({ children }: { children: React.ReactNode }) {
|
||||
|
||||
@@ -20,7 +20,7 @@ export default async function WishPage() {
|
||||
return { round, tiles: await wishTiles(c), entries: await roundWishes(c, round.id, { memberId: session.memberId, adult }), budget: await budget(c, round.id, session.memberId) };
|
||||
});
|
||||
return (
|
||||
<main className="mx-auto flex max-w-2xl flex-col gap-4 px-4 py-6">
|
||||
<main className="mx-auto flex max-w-md flex-col gap-4 px-4 py-6">
|
||||
<header className="flex flex-col gap-1">
|
||||
<p className="eyebrow">{t("eyebrow")}</p>
|
||||
<h1 className="text-4xl leading-tight">{t("title")}</h1>
|
||||
|
||||
@@ -16,7 +16,8 @@ export async function PUT(request: Request, { params }: { params: Promise<{ id:
|
||||
await withHousehold(session.householdId, (c) => saveDish(c, session.householdId, session.memberId, body.data, id));
|
||||
return json({ id });
|
||||
} catch (error) {
|
||||
if (error instanceof InvalidAmount) return fail("amount", 400);
|
||||
// Welche Zutat nicht passt, sagt die Antwort mit — das Formular markiert die Zeile (26.11.51).
|
||||
if (error instanceof InvalidAmount) return json({ error: "amount", ingredientId: error.message }, 400);
|
||||
if (error instanceof Error && error.message === "not found") return fail("notFound", 404);
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ export async function POST(request: Request) {
|
||||
if (body.data.imageUrl) await attachImage(session.householdId, id, session.memberId, body.data.imageUrl);
|
||||
return json({ id }, 201);
|
||||
} catch (error) {
|
||||
if (error instanceof InvalidAmount) return fail("amount", 400);
|
||||
// Welche Zutat nicht passt, sagt die Antwort mit — das Formular markiert die Zeile (26.11.51).
|
||||
if (error instanceof InvalidAmount) return json({ error: "amount", ingredientId: error.message }, 400);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,11 @@ import { fail, json, readJson } from "@/lib/auth/http";
|
||||
import { PLANNERS } from "@/lib/auth/roles";
|
||||
import { withHousehold } from "@/lib/db";
|
||||
import { setPackSize } from "@/lib/ingredients";
|
||||
import { COUNT_UNITS } from "@/lib/units";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const body = z.object({ size: z.number().positive().max(100000) });
|
||||
const body = z.object({ size: z.number().positive().max(100000), unit: z.enum([...COUNT_UNITS, "g", "ml"]).optional() });
|
||||
|
||||
// Gebindegröße für den Haushalt (26.11.39): „bei uns hat die Dose 500 g“ — gilt für
|
||||
// alle Gerichte des Haushalts; ein Produkt mit Packung am Gericht geht vor.
|
||||
@@ -18,6 +19,6 @@ export async function PUT(request: Request, { params }: { params: Promise<{ id:
|
||||
const parsed = body.safeParse(await readJson(request));
|
||||
if (!parsed.success || !/^[0-9a-f-]{36}$/.test(id)) return fail("invalid", 400);
|
||||
const size = Math.round(parsed.data.size * 1000) / 1000;
|
||||
const ok = await withHousehold(session.householdId, (c) => setPackSize(c, session.householdId, id, size));
|
||||
const ok = await withHousehold(session.householdId, (c) => setPackSize(c, session.householdId, id, size, parsed.data.unit));
|
||||
return ok ? json({ size }) : fail("noPack", 404);
|
||||
}
|
||||
@@ -24,6 +24,7 @@ const view = (i: IngredientEntry, locale: string, all: IngredientEntry[], produc
|
||||
kitchenUnit: i.kitchenUnit ?? null,
|
||||
packKind: i.packKind ?? null,
|
||||
packSize: i.packSize ?? null,
|
||||
sizes: i.sizes ?? {},
|
||||
});
|
||||
|
||||
// Zutaten-Suche beim Tippen, in der Sprache der Person — mit den eigenen des
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { labelFor } from "@/lib/ingredient-name";
|
||||
import type { Section } from "@/lib/recipe-style";
|
||||
import { timerFromText } from "@/lib/timer";
|
||||
import { type BaseUnit, type KitchenUnit } from "@/lib/units";
|
||||
import { type BaseUnit, type DisplayUnit } from "@/lib/units";
|
||||
import { useKitchenAmount } from "@/lib/use-kitchen-amount";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
@@ -21,7 +21,7 @@ export type Ingredient = {
|
||||
qtyPerPortion: number;
|
||||
unit: BaseUnit;
|
||||
note: string | null;
|
||||
displayUnit?: KitchenUnit | null;
|
||||
displayUnit?: DisplayUnit | null;
|
||||
packSize?: number | null;
|
||||
};
|
||||
export type Step = { section: Section; text: string; timerSeconds: number | null; ingredientIds: string[]; timerFrom?: string };
|
||||
|
||||
+224
-49
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { ArrowDown, ArrowUp, Plus, Sparkles, X, Package, Wand2 } from "lucide-react";
|
||||
import { ArrowDown, ArrowUp, CircleAlert, Plus, Sparkles, X, Package, Wand2 } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
@@ -9,7 +9,7 @@ import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { ErrorNotice } from "@/components/ui/notice";
|
||||
import { BASES, TAGS } from "@/lib/categories";
|
||||
import { formatQuantity, isPackKind, parseNumber, type BaseUnit } from "@/lib/units";
|
||||
import { COUNT_UNITS, FIXED_UNITS, formatQuantity, isMetric, isPackKind, needsSize, niceQty, parseNumber, sizeKey, sizeOf, type BaseUnit, type CountUnit } from "@/lib/units";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { SECTIONS, type Section } from "@/lib/recipe-style";
|
||||
|
||||
@@ -18,7 +18,8 @@ import { PackSize } from "./pack-size";
|
||||
export { IngredientPicker, type Picked };
|
||||
// Produkt (optional): Name, Packung in der Einheit der Zeile, Kochzeit laut Packung.
|
||||
// inherited: Lieblingsprodukt des Haushalts für diese Zutat (26.11.38); remember: dieses Produkt für alle Gerichte merken.
|
||||
type Row = { key: number; ingredient: Picked | null; qty: string; unit: string; note: string; product: string; pack: string; cook: string; open: boolean; remember?: boolean; inherited?: string | null };
|
||||
// size: Größe eines Zählmaßes, das der Haushalt noch nicht kennt („1 Packung = 500 g“, 26.11.49).
|
||||
type Row = { key: number; ingredient: Picked | null; qty: string; unit: string; size?: string; note: string; product: string; pack: string; cook: string; open: boolean; remember?: boolean; inherited?: string | null };
|
||||
type StepRow = { key: number; text: string; timer: string; section: Section | "" };
|
||||
|
||||
export type DishFormValue = {
|
||||
@@ -48,27 +49,27 @@ export type DishFormValue = {
|
||||
styledByAi?: boolean;
|
||||
};
|
||||
|
||||
const UNITS_FOR: Record<BaseUnit, string[]> = {
|
||||
g: ["g", "kg", "tbsp", "tsp", "pinch"],
|
||||
ml: ["ml", "l", "tbsp", "tsp", "pinch"],
|
||||
piece: ["piece"],
|
||||
};
|
||||
|
||||
/** Maße für eine Zutat: die ihrer Basiseinheit und, wenn sie eins hat, ihr Gebinde (26.11.39). */
|
||||
const unitsFor = (p: Picked | null) => {
|
||||
const list = UNITS_FOR[p?.unit ?? "g"];
|
||||
return p?.packKind && p.packSize ? [...list, p.packKind] : list;
|
||||
/**
|
||||
* Maße für eine Zutat in drei Gruppen (26.11.49, Kai: „es fehlen Einheiten“): ihre
|
||||
* Grundeinheit, feste Küchenmaße (nicht bei Stück-Zutaten) und Zählmaße mit Größe.
|
||||
*/
|
||||
const unitGroups = (p: Picked | null): [string[], string[], string[]] => {
|
||||
const base = p?.unit ?? "g";
|
||||
// ml und l überall, auch bei Stück-Zutaten (26.11.50): dann mit Größe je Stück.
|
||||
if (base === "piece") return [["piece", "g", "kg", "ml", "l"], [], COUNT_UNITS.filter((u) => u !== "piece")];
|
||||
return [base === "g" ? ["g", "kg", "ml", "l"] : ["ml", "l", "g", "kg"], [...FIXED_UNITS], [...COUNT_UNITS]];
|
||||
};
|
||||
const unitsFor = (p: Picked | null) => unitGroups(p).flat();
|
||||
/** Bekannte Größe eines Zählmaßes für diese Zutat, sonst null. */
|
||||
const knownSize = (p: Picked | null, unit: string) => (p && needsSize(unit, p.unit) ? sizeOf(unit, p.unit, p) : null);
|
||||
|
||||
/**
|
||||
* Vorgewählte Einheit beim Wählen einer Zutat: ihr Löffelmaß (Olivenöl in EL), sonst
|
||||
* die Basiseinheit. Ein Gebinde wird angeboten, aber nie vorgewählt — wer nach
|
||||
* „Kokosmilch“ gleich „400“ tippt, meint Milliliter, nicht 400 Dosen.
|
||||
*/
|
||||
const preferredUnit = (p: Picked) => (p.kitchenUnit && unitsFor(p).includes(p.kitchenUnit) ? p.kitchenUnit : p.unit);
|
||||
const preferredUnit = (p: Picked) => (p.kitchenUnit && !isPackKind(p.kitchenUnit) && unitsFor(p).includes(p.kitchenUnit) ? p.kitchenUnit : p.unit);
|
||||
|
||||
let counter = 0;
|
||||
const next = () => ++counter;
|
||||
|
||||
const formatQty = (n: number) => String(Math.round(n * 100) / 100).replace(".", ",");
|
||||
|
||||
@@ -83,6 +84,10 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
return `${f.amount}${f.unit ? ` ${f.unit}` : ""}`;
|
||||
};
|
||||
const router = useRouter();
|
||||
// Schlüssel der Zeilen je Formular, auf Server und Gerät gleich — sie stecken in den
|
||||
// Feld-Kennungen (qty-…, size-…), an denen die Fehlersätze hängen (26.11.51).
|
||||
const counter = useRef(0);
|
||||
const next = () => ++counter.current;
|
||||
const [title, setTitle] = useState(initial?.title ?? "");
|
||||
const [portions, setPortions] = useState(String(initial?.portions ?? 4));
|
||||
const [base, setBase] = useState(initial?.base ?? "");
|
||||
@@ -142,8 +147,70 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
}
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [checked, setChecked] = useState(false);
|
||||
// Vom Server abgelehnte Menge (26.11.51): gilt, bis sich Zutat, Menge oder Maß der Zeile ändern.
|
||||
const [rejected, setRejected] = useState<{ key: number; ingredientId: string; qty: string; unit: string } | null>(null);
|
||||
|
||||
// Alles, was vor dem Speichern fehlt — auf einmal, am Feld, und live nach dem ersten Versuch (Kai, 8.11.2026).
|
||||
type Problem = { id: string; rowKey?: number; text: string };
|
||||
function findProblems(): Problem[] {
|
||||
const out: Problem[] = [];
|
||||
if (!title.trim()) out.push({ id: "title", text: t("form.problem.titleMissing") });
|
||||
const n = parseNumber(portions);
|
||||
if (!n || n < 1 || n > 30) out.push({ id: "portions", text: t("form.problem.portions") });
|
||||
for (const r of rows) {
|
||||
if (!r.ingredient) continue;
|
||||
const q = r.qty.trim();
|
||||
if (!q) out.push({ id: `qty-${r.key}`, rowKey: r.key, text: t("form.problem.amountMissing") });
|
||||
else if (!((parseNumber(q) ?? 0) > 0)) out.push({ id: `qty-${r.key}`, rowKey: r.key, text: t("form.problem.amountInvalid") });
|
||||
else if (rejected && rejected.key === r.key && rejected.ingredientId === r.ingredient.id && rejected.qty === r.qty && rejected.unit === r.unit)
|
||||
out.push({ id: `unit-${r.key}`, rowKey: r.key, text: t("form.problem.amountServer") });
|
||||
if (needsSize(r.unit, r.ingredient.unit) && knownSize(r.ingredient, r.unit) === null && !((parseNumber(r.size ?? "") ?? 0) > 0))
|
||||
out.push({ id: `size-${r.key}`, rowKey: r.key, text: t("form.problem.sizeMissing") });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
const problems = checked ? findProblems() : [];
|
||||
const problemAt = (id: string) => problems.find((p) => p.id === id);
|
||||
const invalid = (id: string) => (problemAt(id) ? true : undefined);
|
||||
const describedBy = (id: string) => (problemAt(id) ? `${id}-error` : undefined);
|
||||
function goTo(p: Problem | undefined) {
|
||||
const el = p ? document.getElementById(p.id) : null;
|
||||
if (!el) return;
|
||||
shown.current = p!.id;
|
||||
el.scrollIntoView({ block: "center", behavior: "smooth" });
|
||||
el.focus({ preventScroll: true });
|
||||
}
|
||||
// „Zeigen“: zum nächsten fehlenden Feld nach dem, in dem man gerade steht.
|
||||
// Beim Tippen auf den Knopf liegt der Fokus auf ihm — deshalb das zuletzt gezeigte merken.
|
||||
const shown = useRef<string | null>(null);
|
||||
function showNext() {
|
||||
const at = problems.findIndex((p) => p.id === shown.current);
|
||||
goTo(problems[(at + 1) % problems.length]);
|
||||
}
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
// Portionen umstellen rechnet die Mengen mit (Kai, 8.11.2026, 26.11.49) — immer vom
|
||||
// Stand beim Betreten des Feldes aus, damit sich Rundungen nicht aufsummieren.
|
||||
const scaleFrom = useRef<{ portions: number; qty: Map<number, string> } | null>(null);
|
||||
function rememberAmounts() {
|
||||
const n = parseNumber(portions);
|
||||
scaleFrom.current = n && n >= 1 ? { portions: n, qty: new Map(rows.map((r) => [r.key, r.qty])) } : null;
|
||||
}
|
||||
function changePortions(value: string) {
|
||||
setPortions(value);
|
||||
const n = parseNumber(value);
|
||||
const from = scaleFrom.current;
|
||||
if (!from || !n || n < 1 || n > 30) return;
|
||||
setRows((rs) =>
|
||||
rs.map((r) => {
|
||||
const before = from.qty.get(r.key);
|
||||
const q = before !== undefined ? parseNumber(before) : null;
|
||||
if (before === undefined || q === null) return r;
|
||||
return { ...r, qty: n === from.portions ? before : formatQty(niceQty((q * n) / from.portions, r.unit)) };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const update = (key: number, patch: Partial<Row>) => setRows((rs) => rs.map((r) => (r.key === key ? { ...r, ...patch } : r)));
|
||||
const updateStep = (key: number, patch: Partial<StepRow>) => setSteps((ss) => ss.map((s) => (s.key === key ? { ...s, ...patch } : s)));
|
||||
const move = (index: number, by: number) =>
|
||||
@@ -158,9 +225,12 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
event.preventDefault();
|
||||
const n = parseNumber(portions);
|
||||
setChecked(true);
|
||||
// Eine gewählte Zutat ohne Menge fällt nicht still weg: Die Person ergänzt sie oder entfernt die Zeile.
|
||||
if (rows.some((r) => r.ingredient && !r.qty.trim())) {
|
||||
setError("missingAmount");
|
||||
setError(null);
|
||||
// Eine gewählte Zutat ohne Menge fällt nicht still weg, ein Zählmaß braucht seine Größe:
|
||||
// Alles Fehlende ist am Feld markiert, der Fokus springt zum ersten (26.11.51).
|
||||
const open = findProblems();
|
||||
if (open.length) {
|
||||
goTo(open[0]);
|
||||
return;
|
||||
}
|
||||
const ingredients = rows
|
||||
@@ -169,6 +239,7 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
ingredientId: r.ingredient!.id,
|
||||
qty: parseNumber(r.qty) ?? -1,
|
||||
unit: r.unit,
|
||||
size: r.ingredient && needsSize(r.unit, r.ingredient.unit) && knownSize(r.ingredient, r.unit) === null ? parseNumber(r.size ?? "") : null,
|
||||
note: r.note.trim() || null,
|
||||
product: r.product.trim()
|
||||
? {
|
||||
@@ -211,7 +282,11 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setBusy(false);
|
||||
if (res.ok) router.push(`/gerichte/${data.id}`);
|
||||
else setError(["invalid", "amount"].includes(data.error) ? data.error : "unknown");
|
||||
else if (data.error === "amount" && rows.some((r) => r.ingredient?.id === data.ingredientId)) {
|
||||
const row = rows.find((r) => r.ingredient?.id === data.ingredientId)!;
|
||||
setRejected({ key: row.key, ingredientId: data.ingredientId, qty: row.qty, unit: row.unit });
|
||||
requestAnimationFrame(() => goTo({ id: `unit-${row.key}`, text: "" }));
|
||||
} else setError(["invalid", "amount"].includes(data.error) ? data.error : "unknown");
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -225,7 +300,16 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
<section className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="title">{t("form.title")}</Label>
|
||||
<Input id="title" value={title} onChange={(e) => setTitle(e.target.value)} maxLength={120} required placeholder={t("form.titlePlaceholder")} />
|
||||
<Input
|
||||
id="title"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
maxLength={120}
|
||||
aria-invalid={invalid("title")}
|
||||
aria-describedby={describedBy("title")}
|
||||
placeholder={t("form.titlePlaceholder")}
|
||||
/>
|
||||
<FieldProblem id="title" problem={problemAt("title")} />
|
||||
</div>
|
||||
<div className="feldreihe grid grid-cols-2 gap-3">
|
||||
<div className="flex flex-col gap-2">
|
||||
@@ -285,8 +369,21 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
<Label htmlFor="portions" className="flex-1">
|
||||
{t("form.portions")}
|
||||
</Label>
|
||||
<Input id="portions" inputMode="numeric" className="w-20 text-center" value={portions} onChange={(e) => setPortions(e.target.value)} />
|
||||
<Input
|
||||
id="portions"
|
||||
inputMode="numeric"
|
||||
aria-describedby={["portions-hint", describedBy("portions")].filter(Boolean).join(" ")}
|
||||
aria-invalid={invalid("portions")}
|
||||
className="w-20 text-center"
|
||||
value={portions}
|
||||
onFocus={rememberAmounts}
|
||||
onChange={(e) => changePortions(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<p id="portions-hint" className="-mt-1 text-sm text-muted-foreground">
|
||||
{t("form.portionsHint")}
|
||||
</p>
|
||||
<FieldProblem id="portions" problem={problemAt("portions")} />
|
||||
{initial?.unmatched?.length ? (
|
||||
<div role="note" className="flex flex-col gap-2 rounded-2xl border border-border p-4 text-sm">
|
||||
<p className="font-medium">{t("form.unmatched")}</p>
|
||||
@@ -299,7 +396,7 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
) : null}
|
||||
<ul className="flex flex-col gap-4">
|
||||
{rows.map((row) => (
|
||||
<li key={row.key} className="flex flex-col gap-2 rounded-2xl bg-muted p-3">
|
||||
<li key={row.key} className={cn("flex flex-col gap-2 rounded-2xl bg-muted p-3", problems.some((p) => p.rowKey === row.key) && "ring-2 ring-over")}>
|
||||
<div className="flex items-start gap-2">
|
||||
<IngredientPicker canCreate value={row.ingredient} onPick={(p) => update(row.key, { ingredient: p, unit: preferredUnit(p), inherited: row.product ? row.inherited : (p.product ?? null) })} />
|
||||
<Button
|
||||
@@ -314,38 +411,91 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
</div>
|
||||
<div className="grid grid-cols-[1fr_auto] gap-2">
|
||||
<Input
|
||||
id={`qty-${row.key}`}
|
||||
aria-label={t("form.amount")}
|
||||
aria-invalid={checked && !!row.ingredient && !row.qty.trim() ? true : undefined}
|
||||
aria-invalid={invalid(`qty-${row.key}`)}
|
||||
aria-describedby={describedBy(`qty-${row.key}`)}
|
||||
inputMode="decimal"
|
||||
placeholder={t("form.amount")}
|
||||
value={row.qty}
|
||||
onChange={(e) => update(row.key, { qty: e.target.value })}
|
||||
/>
|
||||
<select
|
||||
id={`unit-${row.key}`}
|
||||
aria-label={t("form.unit")}
|
||||
aria-invalid={invalid(`unit-${row.key}`)}
|
||||
aria-describedby={describedBy(`unit-${row.key}`)}
|
||||
value={row.unit}
|
||||
onChange={(e) => update(row.key, { unit: e.target.value })}
|
||||
className="min-h-11 rounded-xl border border-border bg-background px-3 text-base"
|
||||
className="min-h-11 rounded-xl border border-border bg-background px-3 text-base aria-[invalid=true]:border-2 aria-[invalid=true]:border-over"
|
||||
>
|
||||
{unitsFor(row.ingredient).map((u) => (
|
||||
<option key={u} value={u}>
|
||||
{/* Ein Gebinde nennt seine Größe gleich mit: „Dose (400 g)“. */}
|
||||
{isPackKind(u) && row.ingredient?.packSize
|
||||
? t("form.unitWithSize", { unit: t(`form.units.${u}`), size: sizeText(row.ingredient.packSize, row.ingredient.unit) })
|
||||
: t(`form.units.${u}`)}
|
||||
</option>
|
||||
))}
|
||||
{unitGroups(row.ingredient).map((group, g) =>
|
||||
group.length ? (
|
||||
<optgroup key={g} label={t(`form.unitGroups.${["base", "kitchen", "count"][g]}`)}>
|
||||
{group.map((u) => {
|
||||
const size = knownSize(row.ingredient, u);
|
||||
return (
|
||||
<option key={u} value={u}>
|
||||
{/* Ein Zählmaß nennt seine Größe gleich mit: „Dose (400 g)“. */}
|
||||
{size && row.ingredient && row.ingredient.unit !== "piece"
|
||||
? t("form.unitWithSize", { unit: t(`form.units.${u}`), size: sizeText(size, row.ingredient.unit) })
|
||||
: t(`form.units.${u}`)}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</optgroup>
|
||||
) : null,
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
{row.ingredient && isPackKind(row.unit) && row.ingredient.packSize ? (
|
||||
<PackSize
|
||||
ingredient={row.ingredient}
|
||||
kind={row.unit}
|
||||
sizeText={sizeText}
|
||||
onSaved={(size) =>
|
||||
setRows((rs) => rs.map((r) => (r.ingredient?.id === row.ingredient!.id ? { ...r, ingredient: { ...r.ingredient!, packSize: size } } : r)))
|
||||
}
|
||||
/>
|
||||
<FieldProblem id={`qty-${row.key}`} problem={problemAt(`qty-${row.key}`)} />
|
||||
<FieldProblem id={`unit-${row.key}`} problem={problemAt(`unit-${row.key}`)} />
|
||||
{row.ingredient && needsSize(row.unit, row.ingredient.unit) ? (
|
||||
knownSize(row.ingredient, row.unit) !== null ? (
|
||||
<PackSize
|
||||
ingredient={row.ingredient}
|
||||
kind={sizeKey(row.unit) as CountUnit | "g" | "ml"}
|
||||
perPiece={isMetric(row.unit)}
|
||||
size={knownSize(row.ingredient, row.unit)!}
|
||||
sizeText={sizeText}
|
||||
onSaved={(size) =>
|
||||
setRows((rs) =>
|
||||
rs.map((r) =>
|
||||
r.ingredient?.id === row.ingredient!.id
|
||||
? {
|
||||
...r,
|
||||
ingredient: {
|
||||
...r.ingredient!,
|
||||
sizes: { ...r.ingredient!.sizes, [sizeKey(row.unit)]: size },
|
||||
packSize: r.ingredient!.packKind === row.unit ? size : r.ingredient!.packSize,
|
||||
},
|
||||
}
|
||||
: r,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor={`size-${row.key}`} className="flex-1 text-sm">
|
||||
{isMetric(row.unit)
|
||||
? t("form.sizeAskPerPiece", { base: sizeKey(row.unit) })
|
||||
: t("form.sizeAsk", { unit: t(`form.units.${row.unit}`), base: t(`form.units.${row.ingredient.unit}`) })}
|
||||
</Label>
|
||||
<Input
|
||||
id={`size-${row.key}`}
|
||||
inputMode="decimal"
|
||||
className="w-24 text-center"
|
||||
aria-invalid={invalid(`size-${row.key}`)}
|
||||
aria-describedby={describedBy(`size-${row.key}`)}
|
||||
value={row.size ?? ""}
|
||||
onChange={(e) => update(row.key, { size: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
{row.ingredient && needsSize(row.unit, row.ingredient.unit) && knownSize(row.ingredient, row.unit) === null ? (
|
||||
<FieldProblem id={`size-${row.key}`} problem={problemAt(`size-${row.key}`)} />
|
||||
) : null}
|
||||
<Input
|
||||
aria-label={t("form.note")}
|
||||
@@ -491,13 +641,27 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
</section>
|
||||
|
||||
{error ? <ErrorNotice>{t(`form.errors.${error}`)}</ErrorNotice> : null}
|
||||
<div className="kb-shift sticky bottom-[var(--nav-space)] z-10 flex gap-2 bg-background py-2">
|
||||
<Button type="button" variant="outline" onClick={() => router.back()}>
|
||||
{t("form.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" size="lg" className="flex-1" disabled={busy}>
|
||||
{busy ? t("form.saving") : t("form.save")}
|
||||
</Button>
|
||||
<div className="kb-shift sticky bottom-[var(--nav-space)] z-10 flex flex-col gap-2 bg-background py-2">
|
||||
{/* Solange etwas fehlt: wie viel, und ein Knopf, der hinführt (26.11.51). */}
|
||||
{problems.length ? (
|
||||
<div role="status" className="flex items-center justify-between gap-2 rounded-xl border-2 border-over px-3">
|
||||
<span className="flex items-center gap-1.5 text-sm font-medium">
|
||||
<CircleAlert aria-hidden className="size-4 shrink-0 text-over" />
|
||||
{t("form.problemsLeft", { n: problems.length })}
|
||||
</span>
|
||||
<Button type="button" variant="ghost" className="min-h-11 px-3" onClick={showNext}>
|
||||
{t("form.problemsShow")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" variant="outline" onClick={() => router.back()}>
|
||||
{t("form.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" size="lg" className="flex-1" disabled={busy}>
|
||||
{busy ? t("form.saving") : t("form.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
@@ -505,3 +669,14 @@ export function DishForm({ initial }: { initial?: DishFormValue }) {
|
||||
|
||||
// Zutat suchen und wählen. Tippen sucht in der Sprache der Person, auch über
|
||||
// Synonyme (lib/ingredient-search.ts); ein Tipp auf einen Treffer wählt ihn.
|
||||
|
||||
/** Satz am Feld, wenn dort etwas fehlt — mit Zeichen, Farbe trägt nie allein (26.11.51). */
|
||||
function FieldProblem({ id, problem }: { id: string; problem?: { text: string } }) {
|
||||
if (!problem) return null;
|
||||
return (
|
||||
<p id={`${id}-error`} className="-mt-1 flex items-center gap-1.5 text-sm font-medium">
|
||||
<CircleAlert aria-hidden className="size-4 shrink-0 text-over" />
|
||||
{problem.text}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
@@ -21,6 +21,8 @@ export type Picked = {
|
||||
kitchenUnit?: KitchenUnit | null;
|
||||
packKind?: PackKind | null;
|
||||
packSize?: number | null;
|
||||
/** Größen des Haushalts je Zählmaß (26.11.49). */
|
||||
sizes?: Partial<Record<string, number>>;
|
||||
};
|
||||
type Hit = Picked & { kinds: number; parentId: string | null; own: boolean };
|
||||
|
||||
@@ -55,7 +57,7 @@ export function IngredientPicker({ value, onPick, canCreate = false }: { value:
|
||||
}, [query, open, value?.name]);
|
||||
|
||||
const pick = (h: Picked) => {
|
||||
onPick({ id: h.id, name: h.name, unit: h.unit, group: h.group, product: h.product ?? null, kitchenUnit: h.kitchenUnit, packKind: h.packKind, packSize: h.packSize });
|
||||
onPick({ id: h.id, name: h.name, unit: h.unit, group: h.group, product: h.product ?? null, kitchenUnit: h.kitchenUnit, packKind: h.packKind, packSize: h.packSize, sizes: h.sizes });
|
||||
setQuery(h.name);
|
||||
setOpen(false);
|
||||
setCreating(false);
|
||||
|
||||
@@ -6,38 +6,44 @@ import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { ErrorNotice } from "@/components/ui/notice";
|
||||
import { parseNumber, type BaseUnit, type PackKind } from "@/lib/units";
|
||||
import { parseNumber, type BaseUnit, type CountUnit } from "@/lib/units";
|
||||
|
||||
// Größe eines Gebindes (26.11.39): „1 Dose = 400 g“ — wer Gerichte pflegt, kann sie
|
||||
// für den Haushalt ändern („unsere Dose hat 500 g“). Gilt für alle Gerichte.
|
||||
// Größe eines Zählmaßes (26.11.39, alle Zählmaße seit 26.11.49): „1 Dose = 400 g“,
|
||||
// „1 Zehe = 3 g“ — wer Gerichte pflegt, kann sie für den Haushalt ändern. Gilt für alle Gerichte.
|
||||
export function PackSize({
|
||||
ingredient,
|
||||
kind,
|
||||
perPiece = false,
|
||||
size,
|
||||
sizeText,
|
||||
onSaved,
|
||||
}: {
|
||||
ingredient: { id: string; unit: BaseUnit; packSize?: number | null };
|
||||
kind: PackKind;
|
||||
ingredient: { id: string; unit: BaseUnit };
|
||||
/** Zählmaß, oder g/ml je Stück einer Stück-Zutat (perPiece, 26.11.50: „1 Stück = 500 ml“). */
|
||||
kind: CountUnit | "g" | "ml";
|
||||
perPiece?: boolean;
|
||||
size: number;
|
||||
sizeText: (size: number, unit: BaseUnit) => string;
|
||||
onSaved: (size: number) => void;
|
||||
}) {
|
||||
const t = useTranslations("dishes.form");
|
||||
const id = useId();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [value, setValue] = useState(String(ingredient.packSize ?? ""));
|
||||
const [value, setValue] = useState(String(size));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
const unit = t(`units.${kind}`);
|
||||
const unit = t(`units.${perPiece ? "piece" : kind}`);
|
||||
const base: BaseUnit = perPiece ? (kind as BaseUnit) : ingredient.unit;
|
||||
|
||||
async function save() {
|
||||
const size = parseNumber(value);
|
||||
if (!size || size <= 0) return setError(true);
|
||||
const next = parseNumber(value);
|
||||
if (!next || next <= 0) return setError(true);
|
||||
setBusy(true);
|
||||
setError(false);
|
||||
const res = await fetch(`/api/ingredients/${ingredient.id}/pack`, {
|
||||
method: "PUT",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ size }),
|
||||
body: JSON.stringify({ size: next, unit: kind }),
|
||||
}).catch(() => null);
|
||||
setBusy(false);
|
||||
if (!res?.ok) return setError(true);
|
||||
@@ -48,7 +54,7 @@ export function PackSize({
|
||||
if (!open) {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-x-3 text-sm text-muted-foreground">
|
||||
<span>{t("packSize", { unit, size: sizeText(ingredient.packSize ?? 0, ingredient.unit) })}</span>
|
||||
<span>{t("packSize", { unit, size: sizeText(size, base) })}</span>
|
||||
<Button type="button" variant="ghost" className="min-h-11" onClick={() => setOpen(true)}>
|
||||
{t("packChange")}
|
||||
</Button>
|
||||
@@ -58,7 +64,7 @@ export function PackSize({
|
||||
return (
|
||||
<div className="flex flex-col gap-2 rounded-xl border border-border p-3">
|
||||
<Label htmlFor={id} className="text-sm">
|
||||
{t("packSizeLabel", { unit, base: t(`units.${ingredient.unit}`) })}
|
||||
{t("packSizeLabel", { unit, base: t(`units.${base}`) })}
|
||||
</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input id={id} inputMode="decimal" value={value} onChange={(e) => setValue(e.target.value)} className="flex-1" />
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { labelFor } from "@/lib/ingredient-name";
|
||||
import { SECTIONS, type Section } from "@/lib/recipe-style";
|
||||
import { scale, type BaseUnit, type KitchenUnit } from "@/lib/units";
|
||||
import { scale, type BaseUnit, type DisplayUnit } from "@/lib/units";
|
||||
import { useKitchenAmount } from "@/lib/use-kitchen-amount";
|
||||
|
||||
type Ingredient = {
|
||||
@@ -18,7 +18,7 @@ type Ingredient = {
|
||||
note: string | null;
|
||||
isStaple: boolean;
|
||||
product?: { name: string } | null;
|
||||
displayUnit?: KitchenUnit | null;
|
||||
displayUnit?: DisplayUnit | null;
|
||||
packSize?: number | null;
|
||||
};
|
||||
type Step = { section: Section; text: string; timerSeconds: number | null; ingredientIds: string[]; timerFrom?: string };
|
||||
|
||||
@@ -8,6 +8,8 @@ export const Input = React.forwardRef<HTMLInputElement, React.InputHTMLAttribute
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex min-h-11 w-full rounded-xl border border-border bg-background px-4 py-2 text-base text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50",
|
||||
// Fehlt etwas, sieht man es (26.11.51): rote, breitere Kante — dazu immer ein Satz am Feld.
|
||||
"aria-[invalid=true]:border-2 aria-[invalid=true]:border-over",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -188,7 +188,7 @@ export function WishBoard({
|
||||
) : null}
|
||||
|
||||
{shown.length ? (
|
||||
<ul className="grid grid-cols-2 gap-3 sm:grid-cols-3">
|
||||
<ul className="grid grid-cols-2 gap-3">
|
||||
{shown.map((tile) => {
|
||||
const own = mine(tile.id);
|
||||
const names = wishers(tile.id).map((e) => (e.memberId === me ? t("you") : e.memberName));
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
-- Rezept bearbeiten (Kai, 8.11.2026, 26.11.49).
|
||||
--
|
||||
-- 1. Ein Gericht merkt sich, für wie viele Portionen es eingegeben wurde. Bearbeiten
|
||||
-- zeigt die Mengen dann wieder so („500 g für 6“), statt immer für vier.
|
||||
-- 2. Mehr Maße: Tasse, Schuss, Messerspitze (fest), Becher, Stück, Würfel, Zehe,
|
||||
-- Scheibe (mit Größe je Zutat). Die Größen eines Haushalts gelten jetzt je
|
||||
-- Zutat und Maß: „1 Packung Hackfleisch = 500 g“, „1 Zehe Knoblauch = 3 g“.
|
||||
|
||||
alter table dishes add column recipe_portions integer check (recipe_portions between 1 and 30);
|
||||
|
||||
alter table ingredients drop constraint ingredients_kitchen_unit_check;
|
||||
alter table ingredients add constraint ingredients_kitchen_unit_check check (kitchen_unit in
|
||||
('tbsp', 'tsp', 'pinch', 'cup', 'dash', 'knifepoint', 'can', 'jar', 'pack', 'tub', 'bunch', 'piece', 'cube', 'clove', 'slice'));
|
||||
alter table ingredients drop constraint ingredients_pack_kind_check;
|
||||
alter table ingredients add constraint ingredients_pack_kind_check check (pack_kind in ('can', 'jar', 'pack', 'tub', 'bunch'));
|
||||
|
||||
alter table dish_ingredients drop constraint dish_ingredients_display_unit_check;
|
||||
alter table dish_ingredients add constraint dish_ingredients_display_unit_check check (display_unit in
|
||||
('tbsp', 'tsp', 'pinch', 'cup', 'dash', 'knifepoint', 'can', 'jar', 'pack', 'tub', 'bunch', 'piece', 'cube', 'clove', 'slice'));
|
||||
|
||||
alter table shopping_items drop constraint shopping_items_pack_kind_check;
|
||||
alter table shopping_items add constraint shopping_items_pack_kind_check check (pack_kind in ('can', 'jar', 'pack', 'tub', 'bunch'));
|
||||
|
||||
-- Größen je Zutat und Maß. Bisherige Zeilen galten dem Gebinde der Zutat.
|
||||
-- Unter FORCE sähe dieses Update keine Zeile (kein Haushalt gesetzt) — für die Dauer
|
||||
-- der Migration (eine Transaktion, scripts/migrate.mjs) ohne FORCE, danach wieder mit.
|
||||
alter table household_pack_sizes add column unit text;
|
||||
alter table household_pack_sizes no force row level security;
|
||||
alter table ingredients no force row level security;
|
||||
update household_pack_sizes h set unit = i.pack_kind from ingredients i where i.id = h.ingredient_id;
|
||||
delete from household_pack_sizes where unit is null;
|
||||
alter table ingredients force row level security;
|
||||
alter table household_pack_sizes force row level security;
|
||||
alter table household_pack_sizes alter column unit set not null;
|
||||
alter table household_pack_sizes add constraint household_pack_sizes_unit_check check (unit in
|
||||
('can', 'jar', 'pack', 'tub', 'bunch', 'piece', 'cube', 'clove', 'slice'));
|
||||
alter table household_pack_sizes drop constraint household_pack_sizes_pkey;
|
||||
alter table household_pack_sizes add primary key (household_id, ingredient_id, unit);
|
||||
@@ -0,0 +1,13 @@
|
||||
-- Milliliter und Liter überall (Kai, 8.11.2026, 26.11.50): auch bei Stück-Zutaten
|
||||
-- („750 ml Brühe“ aus Brühwürfeln). Die Größe steht dann als ml bzw. g je Stück
|
||||
-- unter dem Maß „ml“ bzw. „g“; kg und l nutzen sie mit. Das Rezept merkt sich das
|
||||
-- eingegebene Maß auch, wenn es Gewicht oder Volumen ist („200 ml“ Joghurt).
|
||||
|
||||
alter table household_pack_sizes drop constraint household_pack_sizes_unit_check;
|
||||
alter table household_pack_sizes add constraint household_pack_sizes_unit_check check (unit in
|
||||
('can', 'jar', 'pack', 'tub', 'bunch', 'piece', 'cube', 'clove', 'slice', 'g', 'ml'));
|
||||
|
||||
alter table dish_ingredients drop constraint dish_ingredients_display_unit_check;
|
||||
alter table dish_ingredients add constraint dish_ingredients_display_unit_check check (display_unit in
|
||||
('tbsp', 'tsp', 'pinch', 'cup', 'dash', 'knifepoint', 'can', 'jar', 'pack', 'tub', 'bunch', 'piece', 'cube', 'clove', 'slice',
|
||||
'g', 'kg', 'ml', 'l'));
|
||||
@@ -386,3 +386,28 @@ Transaktion (`setMine` mit `wishIn`): ohne Jeton entsteht nichts. Gefüllt
|
||||
nimmt ein Tipp es zurück, der Wunsch bleibt. Eins pro Runde, ein neues ersetzt
|
||||
das alte. Kein Herz an eigenen Vetos und an Wünschen aus einem Veto. Der Weg
|
||||
über „…“ bleibt.
|
||||
|
||||
**Nachtrag 26.11.49 · Portionen und mehr Maße** (Kai, 8.11.2026: „Mengen, Einheiten
|
||||
und Portionen kann ich nicht sauber eingeben“):
|
||||
- Ein Gericht merkt sich, für wie viele Portionen es eingegeben wurde
|
||||
(`dishes.recipe_portions`). Bearbeiten zeigt die Mengen wieder so, lesbar gerundet
|
||||
(`niceQty`), statt immer für vier.
|
||||
- Portionen umstellen rechnet die Mengen mit (Kai: „Mengen rechnen mit“), immer vom
|
||||
Stand beim Betreten des Feldes aus.
|
||||
- Feste Maße kommen dazu: Tasse, Schuss, Messerspitze.
|
||||
- Zählmaße gelten für jede Zutat: Dose, Glas, Packung, Becher, Bund, Stück, Würfel,
|
||||
Zehe, Scheibe. Ihre Größe kennt der Haushalt je Zutat und Maß
|
||||
(`household_pack_sizes.unit`), sonst das Gebinde der Zutat. Würfel, Zehe und
|
||||
Scheibe einer Stück-Zutat sind je ein Stück.
|
||||
- Fehlt eine Größe, fragt das Formular („Wie viel ist 1 Packung? (in g)“) und merkt
|
||||
sie sich. Gerechnet wird nie ohne sie.
|
||||
- Die Migration nimmt FORCE für die Dauer des Daten-Updates von
|
||||
`household_pack_sizes` und `ingredients`. Abzüge von vorher bekommen beim
|
||||
Zurückspielen das Maß aus dem Gebinde der Zutat.
|
||||
|
||||
**Nachtrag 26.11.50 · Milliliter und Liter überall** (Kai, 8.11.2026, „auch bei
|
||||
Stück-Zutaten“): Gramm-Zutaten nehmen auch ml und l, Flüssiges auch g und kg (1 zu 1,
|
||||
wie beim Löffel). Stück-Zutaten nehmen g, kg, ml und l mit einer Größe je Stück
|
||||
(„1 Brühwürfel = 500 ml“), gespeichert unter dem Maß `g` bzw. `ml` in
|
||||
`household_pack_sizes` (Migration 0027). Das Rezept zeigt das eingegebene Maß
|
||||
(„750 ml (1½ Stück)“), die Einkaufsliste weiter Stück.
|
||||
+113
-6
@@ -153,7 +153,7 @@ test.describe("recipe link", () => {
|
||||
recipeYield: "4 Portionen",
|
||||
totalTime: "PT45M",
|
||||
image: "/bild.jpg",
|
||||
recipeIngredient: ["250 g rote Linsen", "2 Zwiebeln", "1 Becher Sahne", "1 Schuss Milch", "1 Handvoll Glück"],
|
||||
recipeIngredient: ["250 g rote Linsen", "2 Zwiebeln", "1 Becher Sahne", "2 EL Eier", "1 Handvoll Glück"],
|
||||
recipeInstructions: [{ "@type": "HowToStep", text: "Zwiebeln anschwitzen." }, { "@type": "HowToStep", text: "Linsen dazu und weich kochen." }],
|
||||
},
|
||||
],
|
||||
@@ -202,10 +202,12 @@ test.describe("recipe link", () => {
|
||||
await expect(amounts.nth(2)).toHaveValue("1");
|
||||
await expect(page.getByRole("combobox", { name: "Einheit" }).nth(2).locator("option:checked")).toHaveText("Packung (200 ml)");
|
||||
await expect(amounts.nth(3)).toHaveValue("");
|
||||
// Ein Schuss Milch: Menge fehlt — Speichern sagt es, statt die Zeile wegzulassen.
|
||||
// Eier in Esslöffeln passen nicht: Menge fehlt — Speichern sagt es, statt die Zeile wegzulassen.
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
await expect(page.locator("main [role=alert]")).toContainText("fehlt die Menge");
|
||||
await amounts.nth(3).fill("50");
|
||||
await expect(page.getByRole("status").filter({ hasText: "1 Angabe fehlt noch" })).toBeVisible();
|
||||
await expect(amounts.nth(3)).toBeFocused();
|
||||
await expect(page.getByText("Menge fehlt.")).toBeVisible();
|
||||
await amounts.nth(3).fill("2");
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Linsensuppe vom Blog");
|
||||
// Gespeichert unter „Ausprobieren“ — und die Seite sagt es (26.11.41).
|
||||
@@ -443,7 +445,7 @@ test("spoons and cans: the ingredient preselects its measure, the dish shows spo
|
||||
await expect(page.getByText("1 Dose = 400 g")).toBeVisible();
|
||||
// Unsere Dose hat 500 g.
|
||||
await page.getByRole("button", { name: "Größe ändern" }).click();
|
||||
await page.getByLabel("Größe einer Dose in g").fill("500");
|
||||
await page.getByLabel("Wie viel ist 1 Dose? (in g)").fill("500");
|
||||
await page.getByRole("button", { name: "Übernehmen" }).click();
|
||||
await expect(page.getByText("1 Dose = 500 g")).toBeVisible();
|
||||
await page.getByRole("textbox", { name: "Menge", exact: true }).nth(1).fill("1");
|
||||
@@ -474,7 +476,7 @@ test("spoons and cans: the ingredient preselects its measure, the dish shows spo
|
||||
|
||||
// Aufräumen: Größe zurück, Gericht aus dem Pool — damit Plan und Einkauf gleich bleiben.
|
||||
await page.getByRole("button", { name: "Größe ändern" }).click();
|
||||
await page.getByLabel("Größe einer Dose in g").fill("400");
|
||||
await page.getByLabel("Wie viel ist 1 Dose? (in g)").fill("400");
|
||||
await page.getByRole("button", { name: "Übernehmen" }).click();
|
||||
await expect(page.getByText("1 Dose = 400 g")).toBeVisible();
|
||||
await page.goto("/gerichte");
|
||||
@@ -485,6 +487,111 @@ test("spoons and cans: the ingredient preselects its measure, the dish shows spo
|
||||
|
||||
// Kai: „Neue Gerichte werden nicht gespeichert“ — sie standen unter „Ausprobieren“, ohne dass
|
||||
// die Seite es sagte (26.11.41). Jetzt: Hinweis, Weg dorthin, und mit einem Tipp in den Pool.
|
||||
test("portions are remembered and scale the amounts; a pack and cloves for any ingredient (26.11.49)", async ({ page }) => {
|
||||
await page.goto("/gerichte/neu");
|
||||
await page.fill("#title", "Hackbraten");
|
||||
await page.fill("#portions", "6");
|
||||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Gemischtes Hack");
|
||||
await page.getByRole("option", { name: "Gemischtes Hackfleisch", exact: true }).click();
|
||||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||||
const units = page.getByRole("combobox", { name: "Einheit" });
|
||||
await amounts.nth(0).fill("1");
|
||||
await units.nth(0).selectOption("pack");
|
||||
// Hackfleisch hat keine Packungsgröße: Speichern fragt danach, statt still zu rechnen.
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
await expect(page.getByText("Größe fehlt – bitte eintragen.")).toBeVisible();
|
||||
await expect(page.getByLabel("Wie viel ist 1 Packung? (in g)")).toBeFocused();
|
||||
await page.getByLabel("Wie viel ist 1 Packung? (in g)").fill("500");
|
||||
await page.getByRole("button", { name: "Zutaten" }).click();
|
||||
await page.getByRole("combobox", { name: "Zutat suchen" }).nth(1).fill("Knoblauchz");
|
||||
await page.getByRole("option", { name: "Knoblauchzehe", exact: true }).click();
|
||||
await amounts.nth(1).fill("3");
|
||||
await units.nth(1).selectOption("clove");
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Hackbraten");
|
||||
|
||||
// Bearbeiten zeigt das Rezept wieder für 6 Portionen, im eingegebenen Maß.
|
||||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||||
await expect(page.locator("#portions")).toHaveValue("6");
|
||||
await expect(amounts.nth(0)).toHaveValue("1");
|
||||
await expect(units.nth(0).locator("option:checked")).toHaveText("Packung (500 g)");
|
||||
await expect(amounts.nth(1)).toHaveValue("3");
|
||||
await expect(units.nth(1)).toHaveValue("clove");
|
||||
// Portionen umstellen rechnet mit.
|
||||
await page.fill("#portions", "3");
|
||||
await expect(amounts.nth(0)).toHaveValue("0,5");
|
||||
await expect(amounts.nth(1)).toHaveValue("1,5");
|
||||
await page.fill("#portions", "6");
|
||||
await expect(amounts.nth(0)).toHaveValue("1");
|
||||
await page.fill("#portions", "3");
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Hackbraten");
|
||||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||||
await expect(page.locator("#portions")).toHaveValue("3");
|
||||
await expect(amounts.nth(0)).toHaveValue("0,5");
|
||||
// Wieder aus dem Pool, damit der Plan später nicht anders vorschlägt.
|
||||
await page.goto("/gerichte");
|
||||
await page.getByRole("link", { name: /Hackbraten/ }).click();
|
||||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||||
await expect(page).toHaveURL(/entfernt=/);
|
||||
});
|
||||
|
||||
test("millilitres for a piece ingredient: stock cubes in ml with the size per piece (26.11.50)", async ({ page }) => {
|
||||
await page.goto("/gerichte/neu");
|
||||
await page.fill("#title", "Brühnudeln");
|
||||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Brühwürf");
|
||||
await page.getByRole("option", { name: "Brühwürfel", exact: true }).click();
|
||||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||||
const units = page.getByRole("combobox", { name: "Einheit" });
|
||||
await amounts.nth(0).fill("750");
|
||||
await units.nth(0).selectOption("ml");
|
||||
await page.getByLabel("Wie viel ml ist 1 Stück?").fill("500");
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Brühnudeln");
|
||||
await page.getByRole("link", { name: "Bearbeiten" }).click();
|
||||
await expect(amounts.nth(0)).toHaveValue("750");
|
||||
await expect(units.nth(0)).toHaveValue("ml");
|
||||
await expect(page.getByText("1 Stück = 500 ml")).toBeVisible();
|
||||
await page.goto("/gerichte");
|
||||
await page.getByRole("link", { name: /Brühnudeln/ }).click();
|
||||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||||
await expect(page).toHaveURL(/entfernt=/);
|
||||
});
|
||||
|
||||
test("what is missing is marked at the field, counted below and shown on tap (26.11.51)", async ({ page }) => {
|
||||
await page.goto("/gerichte/neu");
|
||||
const amounts = page.getByRole("textbox", { name: "Menge", exact: true });
|
||||
const units = page.getByRole("combobox", { name: "Einheit" });
|
||||
await page.getByRole("combobox", { name: "Zutat suchen" }).first().fill("Zwieb");
|
||||
await page.getByRole("option", { name: "Zwiebeln", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Zutaten" }).click();
|
||||
await page.getByRole("combobox", { name: "Zutat suchen" }).nth(1).fill("Eier");
|
||||
await page.getByRole("option", { name: "Eier", exact: true }).click();
|
||||
await amounts.nth(1).fill("100");
|
||||
await units.nth(1).selectOption("ml");
|
||||
// Ohne Titel, ohne Menge bei den Zwiebeln, ohne Größe für Eier in ml.
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
const left = page.getByRole("status").filter({ hasText: "fehlen noch" });
|
||||
await expect(left).toHaveText(/3 Angaben fehlen noch/);
|
||||
const title = page.locator("#title");
|
||||
await expect(title).toBeFocused();
|
||||
await expect(title).toHaveAttribute("aria-invalid", "true");
|
||||
expect(await title.evaluate((e) => getComputedStyle(e).borderTopWidth)).toBe("2px");
|
||||
await expect(page.getByText("Titel fehlt.")).toBeVisible();
|
||||
// „Zeigen“ führt zum nächsten.
|
||||
await left.getByRole("button", { name: "Zeigen" }).click();
|
||||
await expect(amounts.nth(0)).toBeFocused();
|
||||
await amounts.nth(0).fill("2");
|
||||
await expect(left).toHaveText(/2 Angaben fehlen noch/);
|
||||
await title.fill("Zwiebelkuchen");
|
||||
await page.getByLabel("Wie viel ml ist 1 Stück?").fill("50");
|
||||
await expect(left).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "Speichern" }).click();
|
||||
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Zwiebelkuchen");
|
||||
await page.getByRole("button", { name: "Entfernen" }).click();
|
||||
await expect(page).toHaveURL(/entfernt=/);
|
||||
});
|
||||
|
||||
test("a dish to try says so, links to its tab and moves to the pool with one tap", async ({ page }) => {
|
||||
await page.goto("/gerichte/neu");
|
||||
await page.fill("#title", "Probe-Auflauf");
|
||||
|
||||
+2
-1
@@ -65,7 +65,8 @@ test("buttons pinned to the bottom sit on the keyboard while typing, above the b
|
||||
const height = page.viewportSize()!.height;
|
||||
const nav = page.getByRole("navigation", { name: "Navigation" });
|
||||
const bottomOf = async () => {
|
||||
const box = (await save.locator("xpath=..").boundingBox())!;
|
||||
// Die feste Leiste: seit 26.11.51 mit Zeile „… fehlen noch“ über den Knöpfen, deshalb zwei Ebenen.
|
||||
const box = (await save.locator("xpath=../..").boundingBox())!;
|
||||
return Math.round(box.y + box.height);
|
||||
};
|
||||
await page.locator("#title").focus();
|
||||
|
||||
@@ -162,3 +162,22 @@ test("signed out: the sign-in page is centred and its intro has no orphan line",
|
||||
if (widths.length > 1) expect(widths.at(-1)!).toBeGreaterThan(widths[0]! / 4);
|
||||
await context.close();
|
||||
});
|
||||
|
||||
// Am Desktop dieselbe Ansicht wie am Handy (Kai, 9.11.2026): eine Spalte, zwei Karten
|
||||
// je Reihe, „Gericht hinzufügen“ an der Spalte statt am Bildschirmrand.
|
||||
test("the desktop shows the phone column", async ({ page }) => {
|
||||
test.skip(test.info().project.name !== "desktop", "nur am Desktop");
|
||||
for (const path of ["/gerichte", "/wuenschen", "/plan", "/mehr"]) {
|
||||
await page.goto(path);
|
||||
const width = (await page.locator("main").boundingBox())!.width;
|
||||
expect(width, path).toBeLessThanOrEqual(448);
|
||||
}
|
||||
await page.goto("/gerichte");
|
||||
const main = (await page.locator("main").boundingBox())!;
|
||||
const cards = page.locator("main ul > li");
|
||||
const tops = await cards.evaluateAll((els) => els.slice(0, 3).map((e) => Math.round(e.getBoundingClientRect().top)));
|
||||
expect(tops[0]).toBe(tops[1]);
|
||||
expect(tops[2]).toBeGreaterThan(tops[0]!);
|
||||
const add = (await page.getByRole("link", { name: "Gericht hinzufügen" }).boundingBox())!;
|
||||
expect(add.x + add.width).toBeLessThanOrEqual(main.x + main.width + 1);
|
||||
});
|
||||
@@ -197,6 +197,14 @@ export async function restoreBackup(backup: Backup): Promise<void> {
|
||||
createdBy = rows[0]?.created_by ?? null;
|
||||
rows = rows.map((r) => ({ ...r, created_by: null }));
|
||||
}
|
||||
if (table === "household_pack_sizes" && rows.some((r) => !r.unit)) {
|
||||
// Abzüge vor 26.11.49 kennen nur das Gebinde der Zutat — dessen Maß nachtragen.
|
||||
const kinds = new Map(
|
||||
(await client.query("select id, pack_kind from ingredients where pack_kind is not null")).rows.map((r) => [r.id as string, r.pack_kind as string]),
|
||||
);
|
||||
rows = rows.map((r) => (r.unit ? r : { ...r, unit: kinds.get(r.ingredient_id as string) ?? null })).filter((r) => r.unit);
|
||||
if (!rows.length) continue;
|
||||
}
|
||||
const existing = (
|
||||
await client.query<{ column_name: string }>(
|
||||
"select column_name from information_schema.columns where table_schema = 'public' and table_name = $1",
|
||||
|
||||
+53
-18
@@ -5,15 +5,16 @@ import { BASES, TAGS } from "./categories";
|
||||
import type { IngredientEntry } from "./ingredient-search";
|
||||
import { allIngredients } from "./ingredients";
|
||||
import { linkIngredients, orderSections, SECTIONS, sectionsByRules, styleByRules, type Section, type StepIngredient } from "./recipe-style";
|
||||
import { impliedKitchenUnit, isKitchenUnit, isPackKind, toBase, type BaseUnit, type InputUnit, type KitchenUnit, type PackKind } from "./units";
|
||||
import { COUNT_UNITS, FIXED_UNITS, impliedKitchenUnit, isKitchenUnit, isMetric, isPackKind, needsSize, sizeKey, sizeOf, toBase, type BaseUnit, type DisplayUnit, type InputUnit, type KitchenUnit, type PackKind } from "./units";
|
||||
|
||||
// Gerichte des Haushalts lesen und schreiben. Mengen kommen so, wie man sie
|
||||
// für das ganze Rezept eintippt (z. B. „500 g für 4 Portionen“), und werden
|
||||
// hier in Basiseinheiten pro Portion umgerechnet (CLAUDE.md, Regel 2).
|
||||
// Alle Funktionen laufen in withHousehold(…).
|
||||
|
||||
// Seit 26.11.39 auch Gebinde: Dose, Glas, Packung, Bund — Größe aus der Zutat oder dem Produkt.
|
||||
export const INPUT_UNITS = ["g", "kg", "ml", "l", "piece", "tbsp", "tsp", "pinch", "can", "jar", "pack", "bunch"] as const;
|
||||
// Seit 26.11.39 auch Gebinde, seit 26.11.49 alle Küchenmaße (lib/units.ts): Tasse, Schuss,
|
||||
// Msp., Becher, Stück, Würfel, Zehe, Scheibe — Zählmaße mit Größe je Zutat.
|
||||
export const INPUT_UNITS = ["g", "kg", "ml", "l", ...FIXED_UNITS, ...COUNT_UNITS] as const;
|
||||
|
||||
export const dishInput = z.object({
|
||||
title: z.string().trim().min(1).max(120),
|
||||
@@ -32,6 +33,8 @@ export const dishInput = z.object({
|
||||
qty: z.number().positive().max(100000),
|
||||
unit: z.enum(INPUT_UNITS),
|
||||
note: z.string().trim().max(120).nullable().optional(),
|
||||
// Größe eines Zählmaßes in der Basiseinheit, wenn der Haushalt sie noch nicht kennt (26.11.49).
|
||||
size: z.number().positive().max(100000).nullable().optional(),
|
||||
// Produkt, das man nimmt; Packung in der Einheit der Zeile, Kochzeit laut Packung.
|
||||
product: z
|
||||
.object({
|
||||
@@ -71,6 +74,8 @@ export type DishSummary = {
|
||||
|
||||
export type DishDetail = DishSummary & {
|
||||
sourceUrl: string | null;
|
||||
/** Für wie viele Portionen das Rezept eingegeben wurde (26.11.49); null bei älteren Gerichten. */
|
||||
recipePortions: number | null;
|
||||
ingredients: {
|
||||
ingredientId: string;
|
||||
name: string;
|
||||
@@ -82,11 +87,13 @@ export type DishDetail = DishSummary & {
|
||||
isStaple: boolean;
|
||||
product: Product | null;
|
||||
/** Eingegebenes Küchenmaß („2 EL“, „1 Dose“), sonst null (26.11.39). */
|
||||
displayUnit: KitchenUnit | null;
|
||||
displayUnit: DisplayUnit | null;
|
||||
/** Gebinde der Zutat und seine Größe in der Basiseinheit: Produkt, sonst Haushalt, sonst Vorgabe. */
|
||||
packKind: PackKind | null;
|
||||
packSize: number | null;
|
||||
kitchenUnit: KitchenUnit | null;
|
||||
kindSize: number | null;
|
||||
sizes: Partial<Record<string, number>>;
|
||||
}[];
|
||||
// timerFrom: Name des Produkts, wenn der Timer von seiner Packung stammt.
|
||||
steps: { section: Section; text: string; timerSeconds: number | null; ingredientIds: string[]; timerFrom?: string }[];
|
||||
@@ -110,7 +117,7 @@ export async function listDishes(client: PoolClient): Promise<DishSummary[]> {
|
||||
}
|
||||
|
||||
export async function getDish(client: PoolClient, id: string, locale: string): Promise<DishDetail | null> {
|
||||
const dish = (await client.query(`select ${summaryColumns}, source_url as "sourceUrl" from dishes where id = $1 and archived_at is null`, [id]))
|
||||
const dish = (await client.query(`select ${summaryColumns}, source_url as "sourceUrl", recipe_portions as "recipePortions" from dishes where id = $1 and archived_at is null`, [id]))
|
||||
.rows[0];
|
||||
if (!dish) return null;
|
||||
const entries = new Map((await allIngredients(client)).map((i) => [i.id, i]));
|
||||
@@ -136,10 +143,14 @@ export async function getDish(client: PoolClient, id: string, locale: string): P
|
||||
: r.house_product
|
||||
? { name: r.house_product, pack: r.house_pack, cookMinutes: r.house_cook, fromHousehold: true }
|
||||
: null,
|
||||
displayUnit: r.display_unit as KitchenUnit | null,
|
||||
displayUnit: r.display_unit as DisplayUnit | null,
|
||||
packKind: entries.get(r.ingredient_id)?.packKind ?? null,
|
||||
packSize: ((r.product ? r.product_pack : r.house_pack) ?? entries.get(r.ingredient_id)?.packSize ?? null) as number | null,
|
||||
// Größe zum eingegebenen Maß (26.11.49): beim Gebinde Produkt, sonst Haushalt bzw. Zutat.
|
||||
packSize: sizeForDisplay(r, entries.get(r.ingredient_id)),
|
||||
kitchenUnit: entries.get(r.ingredient_id)?.kitchenUnit ?? null,
|
||||
// Fürs Bearbeiten (26.11.49): Gebindegröße der Zutat und alle Größen des Haushalts.
|
||||
kindSize: entries.get(r.ingredient_id)?.packSize ?? null,
|
||||
sizes: entries.get(r.ingredient_id)?.sizes ?? {},
|
||||
})).map((i) => ({
|
||||
...i,
|
||||
// Ohne eingegebenes Maß (ältere Gerichte, Vorlagen): Löffel oder Gebinde, wo es passt (26.11.39).
|
||||
@@ -181,6 +192,16 @@ export function withProductTimers<S extends { section: Section; timerSeconds: nu
|
||||
});
|
||||
}
|
||||
|
||||
function sizeForDisplay(
|
||||
r: { display_unit: string | null; unit: BaseUnit; product: string | null; product_pack: number | null; house_pack: number | null },
|
||||
entry: IngredientEntry | undefined,
|
||||
): number | null {
|
||||
const productPack = (r.product ? r.product_pack : r.house_pack) ?? null;
|
||||
const d = r.display_unit;
|
||||
if (!d || isPackKind(d)) return productPack ?? (d ? sizeOf(d, r.unit, entry ?? {}) : (entry?.packSize ?? null));
|
||||
return needsSize(d, r.unit) ? sizeOf(d, r.unit, entry ?? {}) : null;
|
||||
}
|
||||
|
||||
export class InvalidAmount extends Error {}
|
||||
|
||||
/** Legt an (id leer) oder ersetzt Inhalt, Zutaten und Schritte. Gibt die Kennung zurück. */
|
||||
@@ -195,16 +216,22 @@ export async function saveDish(client: PoolClient, householdId: string, memberId
|
||||
if (!entry) throw new InvalidAmount(i.ingredientId);
|
||||
const base = entry.unit;
|
||||
const unit = i.unit as InputUnit;
|
||||
// Ein Gebinde nur, wenn die Zutat eines hat — „1 Dose Zwiebeln“ gibt es nicht.
|
||||
if (isPackKind(unit) && entry.packKind !== unit) throw new InvalidAmount(i.ingredientId);
|
||||
// Packung des Produkts: bei einem Gebinde in der Basiseinheit („400“ g), sonst in der Einheit der Zeile.
|
||||
const pack = i.product?.pack ? toBase(i.product.pack, isPackKind(unit) ? base : unit, base) : null;
|
||||
// Größe des Gebindes: Produkt am Gericht, sonst Lieblingsprodukt, sonst Haushalt bzw. Vorgabe.
|
||||
const size = (i.product ? pack : null) ?? house.get(i.ingredientId) ?? entry.packSize ?? null;
|
||||
const counted = needsSize(unit, base);
|
||||
// Packung des Produkts: bei einem Zählmaß in der Basiseinheit („400“ g), sonst in der Einheit der Zeile.
|
||||
const pack = i.product?.pack ? toBase(i.product.pack, counted ? base : unit, base) : null;
|
||||
// Größe eines Zählmaßes (26.11.49): beim Gebinde zuerst das Produkt bzw. Lieblingsprodukt,
|
||||
// dann was der Haushalt für Zutat und Maß kennt, dann das Gebinde der Zutat, zuletzt die
|
||||
// im Formular eingetragene Größe — die wird dann für den Haushalt gemerkt.
|
||||
const known = counted ? ((isPackKind(unit) ? ((i.product ? pack : null) ?? house.get(i.ingredientId) ?? null) : null) ?? sizeOf(unit, base, entry)) : null;
|
||||
const size = known ?? (counted ? (i.size ?? null) : null);
|
||||
const total = toBase(i.qty, unit, base, size);
|
||||
if (total === null) throw new InvalidAmount(i.ingredientId);
|
||||
const displayUnit = isKitchenUnit(unit) ? unit : null;
|
||||
return { ...i, base, perPortion: Math.round((total / input.portions) * 1000) / 1000, position, pack, displayUnit };
|
||||
// Eingegebenes Maß merken: Küchenmaße, und Gewicht/Volumen einer anderen Familie
|
||||
// („200 ml“ Joghurt, „750 ml“ Brühwürfel, 26.11.50); kg bei g und l bei ml nicht.
|
||||
const family = (u: string) => (u === "g" || u === "kg" ? "g" : u === "ml" || u === "l" ? "ml" : u);
|
||||
const displayUnit = (unit !== base && isKitchenUnit(unit)) || (isMetric(unit) && family(unit) !== base) ? (unit as DisplayUnit) : null;
|
||||
const rememberSize = counted && known === null && size ? { unit: sizeKey(unit), size } : null;
|
||||
return { ...i, base, perPortion: Math.round((total / input.portions) * 1000) / 1000, position, pack, displayUnit, rememberSize };
|
||||
});
|
||||
const values = [
|
||||
input.title,
|
||||
@@ -213,11 +240,12 @@ export async function saveDish(client: PoolClient, householdId: string, memberId
|
||||
input.effortMinutes,
|
||||
input.isTrial,
|
||||
input.sourceUrl ?? null,
|
||||
input.portions, // recipe_portions (26.11.49): Bearbeiten zeigt die Mengen wieder so
|
||||
];
|
||||
let dishId = id;
|
||||
if (dishId) {
|
||||
const updated = await client.query(
|
||||
`update dishes set title = $2, base = $3, tags = $4, effort_minutes = $5, is_trial = $6, source_url = $7, updated_at = now()
|
||||
`update dishes set title = $2, base = $3, tags = $4, effort_minutes = $5, is_trial = $6, source_url = $7, recipe_portions = $8, updated_at = now()
|
||||
where id = $1 and archived_at is null`,
|
||||
[dishId, ...values],
|
||||
);
|
||||
@@ -227,8 +255,8 @@ export async function saveDish(client: PoolClient, householdId: string, memberId
|
||||
} else {
|
||||
dishId = (
|
||||
await client.query(
|
||||
`insert into dishes (household_id, title, base, tags, effort_minutes, is_trial, source_url, created_by)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8) returning id`,
|
||||
`insert into dishes (household_id, title, base, tags, effort_minutes, is_trial, source_url, recipe_portions, created_by)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8, $9) returning id`,
|
||||
[householdId, ...values, memberId],
|
||||
)
|
||||
).rows[0].id as string;
|
||||
@@ -241,6 +269,13 @@ export async function saveDish(client: PoolClient, householdId: string, memberId
|
||||
[householdId, dishId, r.ingredientId, r.perPortion, r.base, r.note ?? null, r.position,
|
||||
r.product?.name ?? null, r.product ? r.pack : null, r.product?.cookMinutes ?? null, r.displayUnit],
|
||||
);
|
||||
if (r.rememberSize) {
|
||||
await client.query(
|
||||
`insert into household_pack_sizes (household_id, ingredient_id, unit, pack_size) values ($1, $2, $3, $4)
|
||||
on conflict (household_id, ingredient_id, unit) do nothing`,
|
||||
[householdId, r.ingredientId, r.rememberSize.unit, r.rememberSize.size],
|
||||
);
|
||||
}
|
||||
if (r.product?.remember) {
|
||||
await client.query(
|
||||
`insert into household_products (household_id, ingredient_id, product, product_pack, cook_minutes) values ($1, $2, $3, $4, $5)
|
||||
|
||||
@@ -23,6 +23,8 @@ export type IngredientEntry = {
|
||||
/** Übliches Gebinde und seine Größe in der Basiseinheit (Haushaltsgröße schon eingerechnet). */
|
||||
packKind?: PackKind | null;
|
||||
packSize?: number | null;
|
||||
/** Größen des Haushalts je Zählmaß, in der Basiseinheit (26.11.49). */
|
||||
sizes?: Partial<Record<string, number>>;
|
||||
};
|
||||
|
||||
export function normalize(text: string): string {
|
||||
|
||||
+23
-10
@@ -2,6 +2,10 @@ import "server-only";
|
||||
import type { PoolClient } from "pg";
|
||||
import { pool } from "@/lib/db";
|
||||
import type { IngredientEntry } from "./ingredient-search";
|
||||
import { needsSize, type CountUnit } from "./units";
|
||||
|
||||
/** Maß einer Haushaltsgröße: ein Zählmaß, oder g/ml je Stück einer Stück-Zutat (26.11.50). */
|
||||
export type SizeUnit = CountUnit | "g" | "ml";
|
||||
|
||||
// Die kanonischen Zutaten sind global und ändern sich nur beim Einspielen
|
||||
// (Neustart). Einmal laden, im Speicher halten. Eigene Zutaten eines Haushalts
|
||||
@@ -30,21 +34,30 @@ export async function allIngredients(client?: PoolClient): Promise<IngredientEnt
|
||||
const global = await globalIngredients();
|
||||
if (!client) return global;
|
||||
const own = (await client.query(`select ${COLUMNS}, true as own from ingredients where household_id is not null order by key`)).rows as IngredientEntry[];
|
||||
const sizes = new Map(
|
||||
(await client.query("select ingredient_id, pack_size::float as size from household_pack_sizes")).rows.map((r) => [r.ingredient_id as string, r.size as number]),
|
||||
);
|
||||
// Größen je Zutat und Maß (26.11.49): „1 Packung Hackfleisch = 500 g“.
|
||||
const sizes = new Map<string, Record<string, number>>();
|
||||
for (const r of (await client.query("select ingredient_id, unit, pack_size::float as size from household_pack_sizes")).rows) {
|
||||
sizes.set(r.ingredient_id, { ...sizes.get(r.ingredient_id), [r.unit]: r.size });
|
||||
}
|
||||
const all = own.length ? [...global, ...own] : global;
|
||||
return sizes.size ? all.map((i) => (sizes.has(i.id) && i.packKind ? { ...i, packSize: sizes.get(i.id)! } : i)) : all;
|
||||
if (!sizes.size) return all;
|
||||
return all.map((i) => {
|
||||
const own = sizes.get(i.id);
|
||||
if (!own) return i;
|
||||
// Das Gebinde der Zutat nimmt die Haushaltsgröße gleich mit (Einkaufsliste, Anzeige).
|
||||
return { ...i, sizes: own, packSize: i.packKind && own[i.packKind] ? own[i.packKind] : i.packSize };
|
||||
});
|
||||
}
|
||||
|
||||
/** Gebindegröße für den Haushalt setzen (wer Gerichte pflegt). Nur für Zutaten mit Gebinde. */
|
||||
export async function setPackSize(client: PoolClient, householdId: string, ingredientId: string, size: number): Promise<boolean> {
|
||||
/** Größe eines Zählmaßes für den Haushalt setzen (wer Gerichte pflegt). Ohne Maß: das Gebinde der Zutat. */
|
||||
export async function setPackSize(client: PoolClient, householdId: string, ingredientId: string, size: number, unit?: SizeUnit): Promise<boolean> {
|
||||
const entry = (await allIngredients(client)).find((i) => i.id === ingredientId);
|
||||
if (!entry?.packKind) return false;
|
||||
const kind = unit ?? entry?.packKind;
|
||||
if (!entry || !kind || !needsSize(kind, entry.unit)) return false;
|
||||
await client.query(
|
||||
`insert into household_pack_sizes (household_id, ingredient_id, pack_size) values ($1, $2, $3)
|
||||
on conflict (household_id, ingredient_id) do update set pack_size = excluded.pack_size, updated_at = now()`,
|
||||
[householdId, ingredientId, size],
|
||||
`insert into household_pack_sizes (household_id, ingredient_id, unit, pack_size) values ($1, $2, $3, $4)
|
||||
on conflict (household_id, ingredient_id, unit) do update set pack_size = excluded.pack_size, updated_at = now()`,
|
||||
[householdId, ingredientId, kind, size],
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
+16
-4
@@ -4,7 +4,7 @@
|
||||
// lib/fetch-safe.ts, das Zuordnen der Zutaten lib/ingredient-search.ts.
|
||||
|
||||
import { searchIngredients, type IngredientEntry } from "./ingredient-search";
|
||||
import { isPackKind, parseNumber, toBase, type InputUnit, type KitchenUnit, type PackKind } from "./units";
|
||||
import { isPackKind, needsSize, parseNumber, sizeOf, toBase, type InputUnit, type KitchenUnit, type PackKind } from "./units";
|
||||
|
||||
export type RawRecipe = {
|
||||
title: string;
|
||||
@@ -126,14 +126,21 @@ const UNIT_WORDS: [RegExp, InputUnit, number?][] = [
|
||||
[/^(tl|teel[öo]ffel|tsp|teaspoons?|cc|c\.\s?à\s?c\.?|cucharaditas?)$/i, "tsp"],
|
||||
[/^(prisen?|pinch(es)?|pinc[ée]es?|pizcas?)$/i, "pinch"],
|
||||
[/^(cups?|tassen?|tazas?)$/i, "cup"],
|
||||
// Seit 26.11.49 eigene Maße: Schuss, Messerspitze, Becher, Würfel, Zehe, Scheibe.
|
||||
[/^(schuss|sch(ü|ue)sse|dash(es)?|traits?|chorritos?)$/i, "dash"],
|
||||
[/^(msp|messerspitzen?)$/i, "knifepoint"],
|
||||
[/^(becher|tubs?|pots?|tarrinas?)$/i, "tub"],
|
||||
[/^(w(ü|ue)rfel|cubes?|cubitos?)$/i, "cube"],
|
||||
[/^(zehen?|cloves?|gousses?|dientes?)$/i, "clove"],
|
||||
[/^(scheiben?|slices?|tranches?|rebanadas?|lonchas?)$/i, "slice"],
|
||||
[/^(oz|ounces?)$/i, "g", 28.35],
|
||||
[/^(lbs?|pounds?)$/i, "g", 453.6],
|
||||
// Gebinde (26.11.39): Größe kommt aus der Zutat, nie aus dem Text oder einem Modell.
|
||||
[/^(dosen?|cans?|tins?|bo[iî]tes?|latas?)$/i, "can"],
|
||||
[/^(gl(a|ä)s(er)?|jars?|bocal|bocaux|tarros?|frascos?)$/i, "jar"],
|
||||
[/^(pck|pkg|pack(ung(en)?|s)?|p(a|ä)ckchen|becher|paquets?|paquetes?|sachets?|sobres?|w(ü|ue)rfel|kugeln?)$/i, "pack"],
|
||||
[/^(pck|pkg|pack(ung(en)?|s)?|p(a|ä)ckchen|paquets?|paquetes?|sachets?|sobres?|kugeln?)$/i, "pack"],
|
||||
[/^(bund|bunch(es)?|bouquets?|bottes?|manojos?)$/i, "bunch"],
|
||||
[/^(st(ü|ue)ck|stk\.?|pieces?|pi[eè]ces?|unidad(es)?|zehen?|cloves?|gousses?|dientes?|scheiben?|slices?|tranches?|rebanadas?)$/i, "piece"],
|
||||
[/^(st(ü|ue)ck|stk\.?|pieces?|pi[eè]ces?|unidad(es)?)$/i, "piece"],
|
||||
];
|
||||
|
||||
export type ParsedLine = { raw: string; qty: number | null; unit: InputUnit | null; factor: number; name: string };
|
||||
@@ -180,6 +187,7 @@ export type MatchedLine = {
|
||||
kitchenUnit?: KitchenUnit | null;
|
||||
packKind?: PackKind | null;
|
||||
packSize?: number | null;
|
||||
sizes?: Partial<Record<string, number>>;
|
||||
} | null;
|
||||
qty: number | null;
|
||||
unit: InputUnit | null;
|
||||
@@ -202,13 +210,17 @@ export function matchLines(lines: string[], list: IngredientEntry[], locale: str
|
||||
kitchenUnit: hit.kitchenUnit ?? null,
|
||||
packKind: hit.packKind ?? null,
|
||||
packSize: hit.packSize ?? null,
|
||||
sizes: hit.sizes ?? {},
|
||||
};
|
||||
let qty = p.qty !== null ? p.qty * p.factor : null;
|
||||
let unit = p.unit;
|
||||
// Ein Gebinde ist das der Zutat („1 Becher Sahne“ → ihre Packung); ohne Gebinde
|
||||
// zählt bei Stück-Zutaten das Stück („1 Bund Petersilie“ ist ein Stück Petersilie).
|
||||
if (unit && isPackKind(unit)) unit = hit.packKind && hit.packSize ? hit.packKind : hit.unit === "piece" ? "piece" : unit;
|
||||
if (qty !== null && unit && toBase(qty, unit, hit.unit, hit.packSize) === null) {
|
||||
// Ein Zählmaß ohne bekannte Größe („2 Zehen“ bei Knoblauch in Gramm) bleibt stehen:
|
||||
// Das Formular fragt nach der Größe (26.11.49). Sonst passt das Maß nicht — Menge leer.
|
||||
const size = unit ? sizeOf(unit, hit.unit, hit) : null;
|
||||
if (qty !== null && unit && toBase(qty, unit, hit.unit, size) === null && !(needsSize(unit, hit.unit) && size === null)) {
|
||||
qty = null;
|
||||
unit = null;
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ export type Item = {
|
||||
unit: "g" | "ml" | "piece" | null;
|
||||
packCount: number | null;
|
||||
packSize: number | null;
|
||||
packKind: "can" | "jar" | "pack" | "bunch" | null;
|
||||
packKind: "can" | "jar" | "pack" | "tub" | "bunch" | null;
|
||||
dishes: string[];
|
||||
aislePosition: number | null;
|
||||
manual: boolean;
|
||||
@@ -66,7 +66,7 @@ export async function syncList(client: PoolClient, householdId: string, round: R
|
||||
join dish_ingredients di on di.dish_id = d.id
|
||||
join ingredients i on i.id = di.ingredient_id
|
||||
left join household_products hp on hp.ingredient_id = di.ingredient_id
|
||||
left join household_pack_sizes hps on hps.ingredient_id = di.ingredient_id
|
||||
left join household_pack_sizes hps on hps.ingredient_id = di.ingredient_id and hps.unit = i.pack_kind
|
||||
where s.round_id = $1 and s.cooked_at is null
|
||||
order by s.position`,
|
||||
[round.id, locale],
|
||||
|
||||
+88
-12
@@ -4,19 +4,67 @@
|
||||
|
||||
export type BaseUnit = "g" | "ml" | "piece";
|
||||
|
||||
/** Gebinde, in denen man kauft: Dose, Glas, Packung, Bund (26.11.39). */
|
||||
export const PACK_KINDS = ["can", "jar", "pack", "bunch"] as const;
|
||||
/** Gebinde, in denen man kauft: Dose, Glas, Packung, Becher, Bund (26.11.39, Becher 26.11.49). */
|
||||
export const PACK_KINDS = ["can", "jar", "pack", "tub", "bunch"] as const;
|
||||
export type PackKind = (typeof PACK_KINDS)[number];
|
||||
|
||||
/**
|
||||
* Zählmaße mit einer Größe je Zutat (26.11.49, Kai: „überall“): die Gebinde und
|
||||
* Stück, Würfel, Zehe, Scheibe. „1 Packung Hackfleisch = 500 g“, „1 Zehe = 3 g“ —
|
||||
* die Größe kennt der Haushalt (household_pack_sizes) oder die Zutat.
|
||||
*/
|
||||
export const COUNT_UNITS = [...PACK_KINDS, "piece", "cube", "clove", "slice"] as const;
|
||||
export type CountUnit = (typeof COUNT_UNITS)[number];
|
||||
|
||||
/** Feste Küchenmaße für Gramm- und Flüssig-Zutaten: Löffel, Prise, Tasse, Schuss, Messerspitze. */
|
||||
export const FIXED_UNITS = ["tbsp", "tsp", "pinch", "cup", "dash", "knifepoint"] as const;
|
||||
export type FixedUnit = (typeof FIXED_UNITS)[number];
|
||||
|
||||
/** Küchenmaße, die ein Rezept so anzeigt, wie sie eingegeben wurden (26.11.39). */
|
||||
export const KITCHEN_UNITS = ["tbsp", "tsp", "pinch", ...PACK_KINDS] as const;
|
||||
export const KITCHEN_UNITS = [...FIXED_UNITS, ...COUNT_UNITS] as const;
|
||||
export type KitchenUnit = (typeof KITCHEN_UNITS)[number];
|
||||
|
||||
export const isPackKind = (u: string): u is PackKind => (PACK_KINDS as readonly string[]).includes(u);
|
||||
export const isCountUnit = (u: string): u is CountUnit => (COUNT_UNITS as readonly string[]).includes(u);
|
||||
export const isFixedUnit = (u: string): u is FixedUnit => (FIXED_UNITS as readonly string[]).includes(u);
|
||||
export const isKitchenUnit = (u: string): u is KitchenUnit => (KITCHEN_UNITS as readonly string[]).includes(u);
|
||||
|
||||
/** Gewicht und Volumen (26.11.50, Kai: „Milliliter und Liter“ überall, auch bei Stück-Zutaten). */
|
||||
export const METRIC = ["g", "kg", "ml", "l"] as const;
|
||||
export type Metric = (typeof METRIC)[number];
|
||||
export const isMetric = (u: string): u is Metric => (METRIC as readonly string[]).includes(u);
|
||||
const METRIC_FACTOR: Record<Metric, number> = { g: 1, kg: 1000, ml: 1, l: 1000 };
|
||||
|
||||
/** Maß, in dem ein Rezept eine Menge zeigt, wie sie eingegeben wurde. */
|
||||
export type DisplayUnit = KitchenUnit | Metric;
|
||||
|
||||
/** Maße, die man tippt oder in Rezepten liest. */
|
||||
export type InputUnit = BaseUnit | "kg" | "l" | "cl" | "tbsp" | "tsp" | "pinch" | "cup" | PackKind;
|
||||
export type InputUnit = BaseUnit | "kg" | "l" | "cl" | KitchenUnit;
|
||||
|
||||
/**
|
||||
* Ein Maß, das in dieser Basiseinheit eine Größe je Zutat braucht: Zählmaße („Stück“
|
||||
* bei Stück-Zutaten ist keins) und Gewicht oder Volumen bei Stück-Zutaten
|
||||
* („750 ml Brühe“ bei Brühwürfeln: 1 Stück = 500 ml).
|
||||
*/
|
||||
export const needsSize = (unit: string, base: BaseUnit): boolean =>
|
||||
(isCountUnit(unit) && !(unit === "piece" && base === "piece")) || (base === "piece" && isMetric(unit));
|
||||
|
||||
/** Unter welchem Maß eine Größe steht: kg und l teilen sich die von g und ml (je Stück). */
|
||||
export const sizeKey = (unit: string): string => (unit === "kg" ? "g" : unit === "l" ? "ml" : unit);
|
||||
|
||||
/** Ohne Angabe: Würfel, Zehe, Scheibe einer Stück-Zutat sind je ein Stück. */
|
||||
export function defaultSize(unit: string, base: BaseUnit): number | null {
|
||||
return base === "piece" && (unit === "cube" || unit === "clove" || unit === "slice") ? 1 : null;
|
||||
}
|
||||
|
||||
/** Größe eines Zählmaßes für eine Zutat: Haushalt, sonst ihr Gebinde, sonst die Vorgabe oben. */
|
||||
export function sizeOf(
|
||||
unit: string,
|
||||
base: BaseUnit,
|
||||
entry: { packKind?: string | null; packSize?: number | null; sizes?: Partial<Record<string, number>> | null },
|
||||
): number | null {
|
||||
return entry.sizes?.[sizeKey(unit)] ?? (entry.packKind === unit ? (entry.packSize ?? null) : null) ?? defaultSize(unit, base);
|
||||
}
|
||||
|
||||
/** Hochrechnen: Menge pro Portion × Portionen. */
|
||||
export function scale(qtyPerPortion: number, portions: number): number {
|
||||
@@ -26,8 +74,8 @@ export function scale(qtyPerPortion: number, portions: number): number {
|
||||
// Küchenmaße in Basiseinheiten. Löffel und Tassen sind Volumen; für feste
|
||||
// Zutaten (Einheit g) gilt eine mittlere Dichte — genau genug für ein
|
||||
// Familienrezept, und die Planerin sieht und korrigiert die Menge.
|
||||
const VOLUME_ML: Partial<Record<InputUnit, number>> = { ml: 1, cl: 10, l: 1000, tbsp: 15, tsp: 5, cup: 240, pinch: 0.5 };
|
||||
const SOLID_G: Partial<Record<InputUnit, number>> = { g: 1, kg: 1000, tbsp: 12, tsp: 4, cup: 150, pinch: 0.5 };
|
||||
const VOLUME_ML: Partial<Record<InputUnit, number>> = { ml: 1, cl: 10, l: 1000, tbsp: 15, tsp: 5, cup: 240, pinch: 0.5, dash: 10, knifepoint: 0.5 };
|
||||
const SOLID_G: Partial<Record<InputUnit, number>> = { g: 1, kg: 1000, tbsp: 12, tsp: 4, cup: 150, pinch: 0.5, dash: 10, knifepoint: 0.5 };
|
||||
|
||||
/**
|
||||
* Eingabe in die Basiseinheit der Zutat bringen. Gibt null zurück, wenn die
|
||||
@@ -36,7 +84,12 @@ const SOLID_G: Partial<Record<InputUnit, number>> = { g: 1, kg: 1000, tbsp: 12,
|
||||
*/
|
||||
export function toBase(qty: number, unit: InputUnit, base: BaseUnit, packSize?: number | null): number | null {
|
||||
if (!Number.isFinite(qty) || qty < 0) return null;
|
||||
if (isPackKind(unit)) return packSize && packSize > 0 ? qty * packSize : null;
|
||||
// Stück-Zutat in Gewicht oder Volumen: Größe ist ml bzw. g je Stück.
|
||||
if (base === "piece" && isMetric(unit)) return packSize && packSize > 0 ? (qty * METRIC_FACTOR[unit]) / packSize : null;
|
||||
if (needsSize(unit, base)) {
|
||||
const size = packSize ?? defaultSize(unit, base);
|
||||
return size && size > 0 ? qty * size : null;
|
||||
}
|
||||
if (base === "piece") return unit === "piece" ? qty : null;
|
||||
if (unit === "piece") return null;
|
||||
if (base === "ml") {
|
||||
@@ -91,8 +144,13 @@ export function formatQuantity(qty: number, unit: BaseUnit, locale = "de"): Form
|
||||
}
|
||||
|
||||
/** Menge in Basiseinheit zurück in das Küchenmaß, in dem sie eingegeben wurde (fürs Bearbeiten). */
|
||||
export function fromBase(qty: number, unit: KitchenUnit, base: BaseUnit, packSize?: number | null): number | null {
|
||||
if (isPackKind(unit)) return packSize && packSize > 0 ? qty / packSize : null;
|
||||
export function fromBase(qty: number, unit: DisplayUnit, base: BaseUnit, packSize?: number | null): number | null {
|
||||
if (base === "piece" && isMetric(unit)) return packSize && packSize > 0 ? (qty * packSize) / METRIC_FACTOR[unit] : null;
|
||||
if (isMetric(unit)) return qty / METRIC_FACTOR[unit]; // g ↔ ml wie beim Löffel: 1 zu 1
|
||||
if (needsSize(unit, base)) {
|
||||
const size = packSize ?? defaultSize(unit, base);
|
||||
return size && size > 0 ? qty / size : null;
|
||||
}
|
||||
const f = base === "ml" ? VOLUME_ML[unit] : base === "g" ? SOLID_G[unit] : undefined;
|
||||
return f ? qty / f : null;
|
||||
}
|
||||
@@ -118,7 +176,7 @@ export type KitchenFormatted = {
|
||||
export function formatKitchen(
|
||||
qty: number,
|
||||
base: BaseUnit,
|
||||
display: KitchenUnit | null | undefined,
|
||||
display: DisplayUnit | null | undefined,
|
||||
packSize: number | null | undefined,
|
||||
locale: string,
|
||||
word: (unit: KitchenUnit, count: number) => string,
|
||||
@@ -128,15 +186,22 @@ export function formatKitchen(
|
||||
if (!display) return { main: plainText, extra: "" };
|
||||
const n = fromBase(qty, display, base, packSize);
|
||||
if (n === null) return { main: plainText, extra: "" };
|
||||
if (isMetric(display)) {
|
||||
// Im eingegebenen Maß („750 ml“, „1,5 l“); bei Stück-Zutaten die Stück dahinter (26.11.50).
|
||||
const family = display === "g" || display === "kg" ? "g" : "ml";
|
||||
const f = formatQuantity(n * METRIC_FACTOR[display], family, locale);
|
||||
return { main: `${f.amount} ${f.unit}`, extra: base === "piece" ? `${pieces(qty, locale)} ${word("piece", qty)}` : "" };
|
||||
}
|
||||
if (isPackKind(display)) {
|
||||
// Ein Achtel Packung Butter hilft niemandem — dann nur Gramm.
|
||||
if (n < 0.25 - 1e-9) return { main: plainText, extra: "" };
|
||||
const count = pieces(n, locale);
|
||||
return { main: plainText, extra: `${count} ${word(display, n)}` };
|
||||
}
|
||||
const count = spoons(n, locale);
|
||||
// Löffel auf halbe, Stück, Zehen, Würfel und Scheiben auf Küchenbrüche (26.11.49).
|
||||
const count = isCountUnit(display) ? pieces(n, locale) : spoons(n, locale);
|
||||
// Eine Prise wiegt nichts, was man nachwiegen würde — ohne Klammer.
|
||||
return { main: `${count} ${word(display, n)}`, extra: display === "pinch" || base === "piece" ? "" : plainText };
|
||||
return { main: `${count} ${word(display, n)}`, extra: display === "pinch" || display === "knifepoint" || base === "piece" ? "" : plainText };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,6 +227,17 @@ export function impliedKitchenUnit(
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Menge fürs Formular, so wie man sie tippen würde (26.11.49): Zählmaße und
|
||||
* Löffel auf Viertel, ab 10 ganze Zahlen, sonst höchstens zwei Stellen.
|
||||
* Aus 333,333 g wird 333, aus 1,4999 Dosen 1,5.
|
||||
*/
|
||||
export function niceQty(qty: number, unit: string): number {
|
||||
if (isKitchenUnit(unit)) return Math.max(0.25, Math.round(qty * 4) / 4);
|
||||
if (qty >= 10) return Math.round(qty);
|
||||
return Math.round(qty * 100) / 100;
|
||||
}
|
||||
|
||||
/** Für die Einkaufsliste: Stück immer aufrunden (½ Zwiebel kauft man nicht). */
|
||||
export function shoppingQuantity(qty: number, unit: BaseUnit): number {
|
||||
return unit === "piece" ? Math.ceil(qty - 1e-9) : qty;
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { isOne } from "./ingredient-name";
|
||||
import { formatKitchen, type BaseUnit, type KitchenUnit } from "./units";
|
||||
import { formatKitchen, type BaseUnit, type DisplayUnit, type KitchenUnit } from "./units";
|
||||
|
||||
/** Was eine Zutat für die Mengenanzeige mitbringt (lib/dishes.ts, getDish). */
|
||||
export type Measured = {
|
||||
unit: BaseUnit;
|
||||
displayUnit?: KitchenUnit | null;
|
||||
displayUnit?: DisplayUnit | null;
|
||||
packSize?: number | null;
|
||||
};
|
||||
|
||||
|
||||
+39
-5
@@ -451,13 +451,21 @@
|
||||
"can": "Dose",
|
||||
"jar": "Glas",
|
||||
"pack": "Packung",
|
||||
"bunch": "Bund"
|
||||
"bunch": "Bund",
|
||||
"cup": "Tasse",
|
||||
"dash": "Schuss",
|
||||
"knifepoint": "Msp.",
|
||||
"tub": "Becher",
|
||||
"cube": "Würfel",
|
||||
"clove": "Zehe",
|
||||
"slice": "Scheibe"
|
||||
},
|
||||
"errors": {
|
||||
"invalid": "Bitte gib einen Titel an und prüfe die Mengen.",
|
||||
"amount": "Eine Menge passt nicht zur Zutat (z. B. Gramm bei Stück).",
|
||||
"unknown": "Das hat nicht geklappt. Bitte versuch es noch einmal.",
|
||||
"missingAmount": "Bei einer Zutat fehlt die Menge. Trag sie ein oder entferne die Zeile."
|
||||
"missingAmount": "Bei einer Zutat fehlt die Menge. Trag sie ein oder entferne die Zeile.",
|
||||
"missingSize": "Bei einem Maß fehlt noch, wie viel es enthält (z. B. 1 Packung = 500 g)."
|
||||
},
|
||||
"unmatched": "Diese Zeilen konnten wir keiner Zutat zuordnen. Füge sie bei Bedarf selbst hinzu:",
|
||||
"byAi": "Von der AI gelesen. Prüf jede Zutat und Menge, bevor du speicherst.",
|
||||
@@ -480,10 +488,28 @@
|
||||
"unitWithSize": "{unit} ({size})",
|
||||
"packSize": "1 {unit} = {size}",
|
||||
"packChange": "Größe ändern",
|
||||
"packSizeLabel": "Größe einer {unit} in {base}",
|
||||
"packSizeLabel": "Wie viel ist 1 {unit}? (in {base})",
|
||||
"packSave": "Übernehmen",
|
||||
"packHint": "Gilt für alle Gerichte eures Haushalts.",
|
||||
"packError": "Die Größe ließ sich nicht speichern."
|
||||
"packError": "Die Größe ließ sich nicht speichern.",
|
||||
"unitGroups": {
|
||||
"base": "Gewicht und Menge",
|
||||
"kitchen": "Löffel & Co.",
|
||||
"count": "Stück & Gebinde"
|
||||
},
|
||||
"sizeAsk": "Wie viel ist 1 {unit}? (in {base})",
|
||||
"portionsHint": "Die Mengen rechnen mit, wenn du die Portionen änderst.",
|
||||
"sizeAskPerPiece": "Wie viel {base} ist 1 Stück?",
|
||||
"problem": {
|
||||
"titleMissing": "Titel fehlt.",
|
||||
"portions": "Portionen: bitte eine Zahl von 1 bis 30.",
|
||||
"amountMissing": "Menge fehlt.",
|
||||
"amountInvalid": "Menge muss eine Zahl über 0 sein.",
|
||||
"sizeMissing": "Größe fehlt – bitte eintragen.",
|
||||
"amountServer": "Diese Menge passt nicht zur Zutat – bitte ein anderes Maß wählen."
|
||||
},
|
||||
"problemsLeft": "{n, plural, one {1 Angabe fehlt noch} other {# Angaben fehlen noch}}",
|
||||
"problemsShow": "Zeigen"
|
||||
},
|
||||
"addLinkText": "Wir lesen Zutaten und Schritte von der Rezeptseite.",
|
||||
"link": {
|
||||
@@ -1157,7 +1183,15 @@
|
||||
"can": "{n, plural, one {Dose} other {Dosen}}",
|
||||
"jar": "{n, plural, one {Glas} other {Gläser}}",
|
||||
"pack": "{n, plural, one {Packung} other {Packungen}}",
|
||||
"bunch": "{n, plural, one {Bund} other {Bund}}"
|
||||
"bunch": "{n, plural, one {Bund} other {Bund}}",
|
||||
"cup": "{n, plural, one {Tasse} other {Tassen}}",
|
||||
"dash": "{n, plural, one {Schuss} other {Schuss}}",
|
||||
"knifepoint": "{n, plural, one {Msp.} other {Msp.}}",
|
||||
"tub": "{n, plural, one {Becher} other {Becher}}",
|
||||
"piece": "{n, plural, one {Stück} other {Stück}}",
|
||||
"cube": "{n, plural, one {Würfel} other {Würfel}}",
|
||||
"clove": "{n, plural, one {Zehe} other {Zehen}}",
|
||||
"slice": "{n, plural, one {Scheibe} other {Scheiben}}"
|
||||
},
|
||||
"mail": {
|
||||
"login": {
|
||||
|
||||
+39
-5
@@ -451,13 +451,21 @@
|
||||
"can": "Can",
|
||||
"jar": "Jar",
|
||||
"pack": "Pack",
|
||||
"bunch": "Bunch"
|
||||
"bunch": "Bunch",
|
||||
"cup": "cup",
|
||||
"dash": "dash",
|
||||
"knifepoint": "pinch (tip of knife)",
|
||||
"tub": "Tub",
|
||||
"cube": "cube",
|
||||
"clove": "clove",
|
||||
"slice": "slice"
|
||||
},
|
||||
"errors": {
|
||||
"invalid": "Please give a title and check the amounts.",
|
||||
"amount": "An amount doesn't fit the ingredient (e.g. grams for pieces).",
|
||||
"unknown": "That didn't work. Please try again.",
|
||||
"missingAmount": "An ingredient has no amount. Enter it or remove the row."
|
||||
"missingAmount": "An ingredient has no amount. Enter it or remove the row.",
|
||||
"missingSize": "A measure still needs its size (e.g. 1 pack = 500 g)."
|
||||
},
|
||||
"unmatched": "We could not match these lines to an ingredient. Add them yourself if needed:",
|
||||
"byAi": "Read by the AI. Check every ingredient and amount before you save.",
|
||||
@@ -480,10 +488,28 @@
|
||||
"unitWithSize": "{unit} ({size})",
|
||||
"packSize": "1 {unit} = {size}",
|
||||
"packChange": "Change size",
|
||||
"packSizeLabel": "Size of one {unit} in {base}",
|
||||
"packSizeLabel": "How much is 1 {unit}? (in {base})",
|
||||
"packSave": "Apply",
|
||||
"packHint": "Applies to all dishes of your household.",
|
||||
"packError": "The size could not be saved."
|
||||
"packError": "The size could not be saved.",
|
||||
"unitGroups": {
|
||||
"base": "Weight and volume",
|
||||
"kitchen": "Spoons & co.",
|
||||
"count": "Pieces & packs"
|
||||
},
|
||||
"sizeAsk": "How much is 1 {unit}? (in {base})",
|
||||
"portionsHint": "The amounts change along when you change the portions.",
|
||||
"sizeAskPerPiece": "How many {base} is 1 piece?",
|
||||
"problem": {
|
||||
"titleMissing": "Title missing.",
|
||||
"portions": "Portions: a number from 1 to 30, please.",
|
||||
"amountMissing": "Amount missing.",
|
||||
"amountInvalid": "The amount must be a number above 0.",
|
||||
"sizeMissing": "Size missing – please fill it in.",
|
||||
"amountServer": "This amount does not fit the ingredient – please choose another measure."
|
||||
},
|
||||
"problemsLeft": "{n, plural, one {1 thing still missing} other {# things still missing}}",
|
||||
"problemsShow": "Show"
|
||||
},
|
||||
"addLinkText": "We read ingredients and steps from the recipe page.",
|
||||
"link": {
|
||||
@@ -1157,7 +1183,15 @@
|
||||
"can": "{n, plural, one {can} other {cans}}",
|
||||
"jar": "{n, plural, one {jar} other {jars}}",
|
||||
"pack": "{n, plural, one {pack} other {packs}}",
|
||||
"bunch": "{n, plural, one {bunch} other {bunches}}"
|
||||
"bunch": "{n, plural, one {bunch} other {bunches}}",
|
||||
"cup": "{n, plural, one {cup} other {cups}}",
|
||||
"dash": "{n, plural, one {dash} other {dashes}}",
|
||||
"knifepoint": "{n, plural, one {pinch} other {pinches}}",
|
||||
"tub": "{n, plural, one {tub} other {tubs}}",
|
||||
"piece": "{n, plural, one {piece} other {pieces}}",
|
||||
"cube": "{n, plural, one {cube} other {cubes}}",
|
||||
"clove": "{n, plural, one {clove} other {cloves}}",
|
||||
"slice": "{n, plural, one {slice} other {slices}}"
|
||||
},
|
||||
"mail": {
|
||||
"login": {
|
||||
|
||||
+39
-5
@@ -451,13 +451,21 @@
|
||||
"can": "Lata",
|
||||
"jar": "Tarro",
|
||||
"pack": "Paquete",
|
||||
"bunch": "Manojo"
|
||||
"bunch": "Manojo",
|
||||
"cup": "taza",
|
||||
"dash": "chorrito",
|
||||
"knifepoint": "punta de cuchillo",
|
||||
"tub": "Tarrina",
|
||||
"cube": "cubito",
|
||||
"clove": "diente",
|
||||
"slice": "loncha"
|
||||
},
|
||||
"errors": {
|
||||
"invalid": "Please give a title and check the amounts.",
|
||||
"amount": "An amount doesn't fit the ingredient (e.g. grams for pieces).",
|
||||
"unknown": "That didn't work. Please try again.",
|
||||
"missingAmount": "A un ingrediente le falta la cantidad. Escríbela o quita la fila."
|
||||
"missingAmount": "A un ingrediente le falta la cantidad. Escríbela o quita la fila.",
|
||||
"missingSize": "A una medida le falta su tamaño (p. ej. 1 paquete = 500 g)."
|
||||
},
|
||||
"unmatched": "No pudimos asignar estas líneas a un ingrediente. Añádelas tú si hace falta:",
|
||||
"byAi": "Read by the AI. Check every ingredient and amount before you save.",
|
||||
@@ -480,10 +488,28 @@
|
||||
"unitWithSize": "{unit} ({size})",
|
||||
"packSize": "1 {unit} = {size}",
|
||||
"packChange": "Cambiar tamaño",
|
||||
"packSizeLabel": "Tamaño de un(a) {unit} en {base}",
|
||||
"packSizeLabel": "¿Cuánto es 1 {unit}? (en {base})",
|
||||
"packSave": "Aplicar",
|
||||
"packHint": "Vale para todos los platos de tu hogar.",
|
||||
"packError": "No se pudo guardar el tamaño."
|
||||
"packError": "No se pudo guardar el tamaño.",
|
||||
"unitGroups": {
|
||||
"base": "Peso y volumen",
|
||||
"kitchen": "Cucharas y más",
|
||||
"count": "Piezas y envases"
|
||||
},
|
||||
"sizeAsk": "¿Cuánto es 1 {unit}? (en {base})",
|
||||
"portionsHint": "Las cantidades cambian contigo cuando cambias las raciones.",
|
||||
"sizeAskPerPiece": "¿Cuántos {base} es 1 pieza?",
|
||||
"problem": {
|
||||
"titleMissing": "Falta el título.",
|
||||
"portions": "Raciones: un número de 1 a 30, por favor.",
|
||||
"amountMissing": "Falta la cantidad.",
|
||||
"amountInvalid": "La cantidad debe ser un número mayor que 0.",
|
||||
"sizeMissing": "Falta el tamaño – escríbelo, por favor.",
|
||||
"amountServer": "Esta cantidad no encaja con el ingrediente – elige otra medida."
|
||||
},
|
||||
"problemsLeft": "{n, plural, one {Falta 1 dato} other {Faltan # datos}}",
|
||||
"problemsShow": "Mostrar"
|
||||
},
|
||||
"addLinkText": "Leemos los ingredientes y los pasos de la página de la receta.",
|
||||
"link": {
|
||||
@@ -1157,7 +1183,15 @@
|
||||
"can": "{n, plural, one {lata} other {latas}}",
|
||||
"jar": "{n, plural, one {tarro} other {tarros}}",
|
||||
"pack": "{n, plural, one {paquete} other {paquetes}}",
|
||||
"bunch": "{n, plural, one {manojo} other {manojos}}"
|
||||
"bunch": "{n, plural, one {manojo} other {manojos}}",
|
||||
"cup": "{n, plural, one {taza} other {tazas}}",
|
||||
"dash": "{n, plural, one {chorrito} other {chorritos}}",
|
||||
"knifepoint": "{n, plural, one {punta de cuchillo} other {puntas de cuchillo}}",
|
||||
"tub": "{n, plural, one {tarrina} other {tarrinas}}",
|
||||
"piece": "{n, plural, one {pieza} other {piezas}}",
|
||||
"cube": "{n, plural, one {cubito} other {cubitos}}",
|
||||
"clove": "{n, plural, one {diente} other {dientes}}",
|
||||
"slice": "{n, plural, one {loncha} other {lonchas}}"
|
||||
},
|
||||
"mail": {
|
||||
"login": {
|
||||
|
||||
+39
-5
@@ -451,13 +451,21 @@
|
||||
"can": "Boîte",
|
||||
"jar": "Bocal",
|
||||
"pack": "Paquet",
|
||||
"bunch": "Botte"
|
||||
"bunch": "Botte",
|
||||
"cup": "tasse",
|
||||
"dash": "trait",
|
||||
"knifepoint": "pointe de couteau",
|
||||
"tub": "Pot",
|
||||
"cube": "cube",
|
||||
"clove": "gousse",
|
||||
"slice": "tranche"
|
||||
},
|
||||
"errors": {
|
||||
"invalid": "Please give a title and check the amounts.",
|
||||
"amount": "An amount doesn't fit the ingredient (e.g. grams for pieces).",
|
||||
"unknown": "That didn't work. Please try again.",
|
||||
"missingAmount": "Il manque la quantité d’un ingrédient. Indique-la ou supprime la ligne."
|
||||
"missingAmount": "Il manque la quantité d’un ingrédient. Indique-la ou supprime la ligne.",
|
||||
"missingSize": "Il manque encore la taille d’une mesure (p. ex. 1 paquet = 500 g)."
|
||||
},
|
||||
"unmatched": "Nous n’avons pas pu associer ces lignes à un ingrédient. Ajoute-les toi-même si besoin :",
|
||||
"byAi": "Read by the AI. Check every ingredient and amount before you save.",
|
||||
@@ -480,10 +488,28 @@
|
||||
"unitWithSize": "{unit} ({size})",
|
||||
"packSize": "1 {unit} = {size}",
|
||||
"packChange": "Modifier la taille",
|
||||
"packSizeLabel": "Taille d’un(e) {unit} en {base}",
|
||||
"packSizeLabel": "Combien fait 1 {unit} ? (en {base})",
|
||||
"packSave": "Appliquer",
|
||||
"packHint": "Vaut pour tous les plats de votre foyer.",
|
||||
"packError": "Impossible d’enregistrer la taille."
|
||||
"packError": "Impossible d’enregistrer la taille.",
|
||||
"unitGroups": {
|
||||
"base": "Poids et volume",
|
||||
"kitchen": "Cuillères & co.",
|
||||
"count": "Pièces & emballages"
|
||||
},
|
||||
"sizeAsk": "Combien fait 1 {unit} ? (en {base})",
|
||||
"portionsHint": "Les quantités suivent quand tu changes les portions.",
|
||||
"sizeAskPerPiece": "Combien de {base} fait 1 pièce ?",
|
||||
"problem": {
|
||||
"titleMissing": "Il manque le titre.",
|
||||
"portions": "Portions : un nombre de 1 à 30, s’il te plaît.",
|
||||
"amountMissing": "Il manque la quantité.",
|
||||
"amountInvalid": "La quantité doit être un nombre supérieur à 0.",
|
||||
"sizeMissing": "Il manque la taille – merci de la saisir.",
|
||||
"amountServer": "Cette quantité ne convient pas à l’ingrédient – choisis une autre mesure."
|
||||
},
|
||||
"problemsLeft": "{n, plural, one {Il manque encore 1 information} other {Il manque encore # informations}}",
|
||||
"problemsShow": "Montrer"
|
||||
},
|
||||
"addLinkText": "Nous lisons les ingrédients et les étapes sur la page de la recette.",
|
||||
"link": {
|
||||
@@ -1157,7 +1183,15 @@
|
||||
"can": "{n, plural, one {boîte} other {boîtes}}",
|
||||
"jar": "{n, plural, one {bocal} other {bocaux}}",
|
||||
"pack": "{n, plural, one {paquet} other {paquets}}",
|
||||
"bunch": "{n, plural, one {botte} other {bottes}}"
|
||||
"bunch": "{n, plural, one {botte} other {bottes}}",
|
||||
"cup": "{n, plural, one {tasse} other {tasses}}",
|
||||
"dash": "{n, plural, one {trait} other {traits}}",
|
||||
"knifepoint": "{n, plural, one {pointe de couteau} other {pointes de couteau}}",
|
||||
"tub": "{n, plural, one {pot} other {pots}}",
|
||||
"piece": "{n, plural, one {pièce} other {pièces}}",
|
||||
"cube": "{n, plural, one {cube} other {cubes}}",
|
||||
"clove": "{n, plural, one {gousse} other {gousses}}",
|
||||
"slice": "{n, plural, one {tranche} other {tranches}}"
|
||||
},
|
||||
"mail": {
|
||||
"login": {
|
||||
|
||||
+2
-2
@@ -2,5 +2,5 @@ apiVersion: v2
|
||||
name: lunch
|
||||
description: foodplanhero (Plan. Cook. Smile.) — die Familie entscheidet gemeinsam, was es gibt; aus dem Plan entsteht die Einkaufsliste
|
||||
type: application
|
||||
version: 26.11.48 # YY.M.<n> wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen
|
||||
appVersion: "26.11.48" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran
|
||||
version: 26.11.52 # YY.M.<n> wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen
|
||||
appVersion: "26.11.52" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran
|
||||
@@ -21,7 +21,7 @@ metadata:
|
||||
title: foodplanhero
|
||||
description: Plan. Cook. Smile. The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box.
|
||||
icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png
|
||||
version: 26.11.48
|
||||
version: 26.11.52
|
||||
categories:
|
||||
- Applications
|
||||
|
||||
@@ -61,7 +61,7 @@ permission:
|
||||
appData: true
|
||||
|
||||
spec:
|
||||
versionName: '26.11.48'
|
||||
versionName: '26.11.52'
|
||||
|
||||
featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png
|
||||
promoteImage:
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Portions that scale, and more measures
|
||||
v26.11.49: Editing a dish now shows the amounts for the number of portions it was entered for, rounded the way you would type them. Changing the portions scales all amounts along. New measures: cup, dash and a knife tip, plus can, jar, pack, tub, bunch, piece, cube, clove and slice for any ingredient — the first time, the app asks how much one contains (for example 1 pack of mince = 500 g) and remembers it for your household.
|
||||
|
||||
## Deutsch
|
||||
v26.11.49: Beim Bearbeiten stehen die Mengen jetzt für so viele Portionen, wie das Gericht eingegeben wurde, gerundet wie man sie tippt. Portionen umstellen rechnet alle Mengen mit. Neue Maße: Tasse, Schuss und Messerspitze, dazu Dose, Glas, Packung, Becher, Bund, Stück, Würfel, Zehe und Scheibe für jede Zutat — beim ersten Mal fragt die App, wie viel eins enthält (etwa 1 Packung Hackfleisch = 500 g), und merkt es sich für euren Haushalt.
|
||||
@@ -0,0 +1,5 @@
|
||||
# Millilitres and litres for every ingredient
|
||||
v26.11.50: Every ingredient can now be entered in millilitres and litres as well as grams and kilos — also ingredients counted in pieces, such as stock cubes: the first time, the app asks how many millilitres one piece makes (for example 1 cube = 500 ml) and remembers it. The recipe shows "750 ml (1½ pieces)"; the shopping list still counts pieces.
|
||||
|
||||
## Deutsch
|
||||
v26.11.50: Jede Zutat lässt sich jetzt auch in Millilitern und Litern eintragen, ebenso in Gramm und Kilo — auch Zutaten, die man in Stück zählt, wie Brühwürfel: Beim ersten Mal fragt die App, wie viel ml ein Stück ergibt (etwa 1 Würfel = 500 ml), und merkt es sich. Das Rezept zeigt „750 ml (1½ Stück)“, die Einkaufsliste zählt weiter Stück.
|
||||
@@ -0,0 +1,5 @@
|
||||
# Missing details are easy to find
|
||||
v26.11.51: When a dish cannot be saved yet, every missing detail is now marked right at its field with a red edge and a short sentence, the ingredient card gets a red frame, and the bar at the bottom says how many things are still missing. "Show" jumps to them one by one; saving jumps to the first. What you fix disappears at once.
|
||||
|
||||
## Deutsch
|
||||
v26.11.51: Lässt sich ein Gericht noch nicht speichern, ist jetzt jede fehlende Angabe direkt am Feld markiert – mit roter Kante und einem kurzen Satz –, die Zutatenkarte bekommt einen roten Rahmen, und die Leiste unten sagt, wie viele Angaben noch fehlen. „Zeigen“ springt der Reihe nach hin, Speichern springt zur ersten. Was du behebst, verschwindet sofort.
|
||||
@@ -0,0 +1,5 @@
|
||||
# The desktop looks like the phone
|
||||
v26.11.52: On a computer, every page now shows the same single column as on the phone: dishes and wishes two to a row, and "Add dish" sits at the bottom right of that column instead of at the edge of the screen.
|
||||
|
||||
## Deutsch
|
||||
v26.11.52: Am Computer zeigt jetzt jede Seite dieselbe Spalte wie am Handy: Gerichte und Wünsche zwei pro Reihe, und „Gericht hinzufügen“ sitzt unten rechts an dieser Spalte statt am Bildschirmrand.
|
||||
+1
-1
@@ -89,7 +89,7 @@ export async function seedHousehold(client: pg.Client | pg.PoolClient, h: string
|
||||
await q("insert into kid_devices (household_id, label, token_hash, created_by) values ($1, 'Tablet', sha256(convert_to($2, 'utf8')), $3)", [h, `kid-${h}`, member]);
|
||||
const own = (await q("insert into ingredients (key, category, default_unit, names, household_id) values ($1, 'pasta_rice', 'g', '{\"de\":\"Gnocchi\"}', $2) returning id", [`own_${h.replace(/-/g, "")}`, h])).rows[0].id;
|
||||
await q("insert into household_products (household_id, ingredient_id, product) values ($1, $2, 'Barilla Nr. 5')", [h, own]);
|
||||
await q("insert into household_pack_sizes (household_id, ingredient_id, pack_size) select $1, id, 500 from ingredients where key = 'chopped_tomatoes'", [h]);
|
||||
await q("insert into household_pack_sizes (household_id, ingredient_id, unit, pack_size) select $1, id, 'can', 500 from ingredients where key = 'chopped_tomatoes'", [h]);
|
||||
await q("insert into household_ai (household_id, endpoint, vision_model, updated_by) values ($1, 'http://llm.test/v1', 'vision', $2)", [h, member]);
|
||||
await q("insert into household_mail (household_id, host, port, username, from_address) values ($1, 'smtp.test', 465, 'resend', 'hallo@test.example')", [h]);
|
||||
await q("insert into mail_tokens (household_id, member_id, purpose, email, token_hash, expires_at) values ($1, $2, 'verify', $3, sha256(convert_to($3, 'utf8')), now() + interval '1 hour')", [h, member, `kai-${h}@test.example`]);
|
||||
|
||||
@@ -38,8 +38,8 @@ describe.skipIf(!url)("kitchen units", () => {
|
||||
await client.end();
|
||||
});
|
||||
|
||||
const dish = (list: { ingredientId: string; qty: number; unit: string; product?: object | null }[]) =>
|
||||
({ title: "Tomatensoße", portions: 4, base: null, tags: [], effortMinutes: 20, isTrial: false, ingredients: list, steps: [] }) as never;
|
||||
const dish = (list: { ingredientId: string; qty: number; unit: string; size?: number; product?: object | null }[], portions = 4) =>
|
||||
({ title: "Tomatensoße", portions, base: null, tags: [], effortMinutes: 20, isTrial: false, ingredients: list, steps: [] }) as never;
|
||||
|
||||
it("keeps the typed spoon and can; amounts stay in base units", async () => {
|
||||
const got = await db.withHousehold(a, async (c) => {
|
||||
@@ -71,6 +71,50 @@ describe.skipIf(!url)("kitchen units", () => {
|
||||
expect(theirs.find((i) => i.id === ing.chopped_tomatoes)!.packSize).toBe(400);
|
||||
});
|
||||
|
||||
it("any ingredient takes a pack once its size is known; the size is remembered (26.11.49)", async () => {
|
||||
// Hackfleisch hat kein Gebinde: ohne Größe geht „1 Packung“ nicht …
|
||||
await expect(db.withHousehold(a, (c) => dishes.saveDish(c, a, member, dish([{ ingredientId: ing.ground_beef!, qty: 1, unit: "pack" }])))).rejects.toThrow();
|
||||
// … mit Größe schon, und der Haushalt merkt sie sich für das nächste Gericht.
|
||||
const [first, second] = await db.withHousehold(a, async (c) => {
|
||||
const one = await dishes.saveDish(c, a, member, dish([{ ingredientId: ing.ground_beef!, qty: 1, unit: "pack", size: 500 }], 2));
|
||||
const two = await dishes.saveDish(c, a, member, dish([{ ingredientId: ing.ground_beef!, qty: 2, unit: "pack" }]));
|
||||
return [await dishes.getDish(c, one, "de"), await dishes.getDish(c, two, "de")];
|
||||
});
|
||||
expect(first).toMatchObject({ recipePortions: 2 });
|
||||
expect(first!.ingredients[0]).toMatchObject({ displayUnit: "pack", qtyPerPortion: 250, packSize: 500 });
|
||||
expect(second!.ingredients[0]).toMatchObject({ displayUnit: "pack", qtyPerPortion: 250, packSize: 500 });
|
||||
// Der andere Haushalt kennt die Größe nicht.
|
||||
const theirs = await db.withHousehold(b, (c) => ingredients.allIngredients(c));
|
||||
expect(theirs.find((i) => i.id === ing.ground_beef)!.sizes).toBeUndefined();
|
||||
});
|
||||
|
||||
it("slices of a piece ingredient count as one piece each; a typed piece of it is no kitchen unit", async () => {
|
||||
const got = await db.withHousehold(a, async (c) => {
|
||||
const id = await dishes.saveDish(c, a, member, dish([
|
||||
{ ingredientId: ing.onion!, qty: 2, unit: "slice" },
|
||||
{ ingredientId: ing.onion!, qty: 3, unit: "piece" },
|
||||
]));
|
||||
return dishes.getDish(c, id, "de");
|
||||
});
|
||||
expect(got!.ingredients[0]).toMatchObject({ displayUnit: "slice", unit: "piece", qtyPerPortion: 0.5 });
|
||||
expect(got!.ingredients[1]).toMatchObject({ displayUnit: null, unit: "piece", qtyPerPortion: 0.75 });
|
||||
});
|
||||
|
||||
it("stock cubes in millilitres and yoghurt in millilitres (26.11.50)", async () => {
|
||||
const [stock, yoghurt] = (await client.query("select id from ingredients where key in ('stock_cube', 'yogurt') order by key")).rows.map((r) => r.id as string);
|
||||
const got = await db.withHousehold(a, async (c) => {
|
||||
const id = await dishes.saveDish(c, a, member, dish([
|
||||
{ ingredientId: stock!, qty: 750, unit: "ml", size: 500 },
|
||||
{ ingredientId: yoghurt!, qty: 200, unit: "ml" },
|
||||
], 2));
|
||||
return dishes.getDish(c, id, "de");
|
||||
});
|
||||
expect(got!.ingredients[0]).toMatchObject({ displayUnit: "ml", unit: "piece", qtyPerPortion: 0.75, packSize: 500 });
|
||||
expect(got!.ingredients[1]).toMatchObject({ displayUnit: "ml", unit: "g", qtyPerPortion: 100 });
|
||||
const mine = await db.withHousehold(a, (c) => ingredients.allIngredients(c));
|
||||
expect(mine.find((i) => i.id === stock)!.sizes).toMatchObject({ ml: 500 });
|
||||
});
|
||||
|
||||
it("an old dish without a typed unit shows spoons where they fit", async () => {
|
||||
const got = await db.withHousehold(a, async (c) => {
|
||||
const id = await dishes.saveDish(c, a, member, dish([{ ingredientId: ing.olive_oil!, qty: 30, unit: "ml" }]));
|
||||
|
||||
@@ -67,6 +67,17 @@ describe("recipe import", () => {
|
||||
expect(m[4]).toMatchObject({ ingredient: { id: "onion" }, qty: 1, unit: "piece" });
|
||||
});
|
||||
|
||||
it("reads cloves, slices, a knife tip and pieces of gram ingredients (26.11.49)", () => {
|
||||
const m = matchLines(["2 Zehen Knoblauch", "1 Msp. Muskat", "2 Scheiben Käsescheiben", "3 Kartoffeln", "1 Schuss Milch"], list, "de");
|
||||
// Knoblauch zählt in Zehen: eine Zehe ist ein Stück.
|
||||
expect(m[0]).toMatchObject({ ingredient: { id: "garlic" }, qty: 2, unit: "clove" });
|
||||
expect(m[1]).toMatchObject({ ingredient: { id: "nutmeg" }, qty: 1, unit: "knifepoint" });
|
||||
// Scheiben und Stück bei Gramm-Zutaten: Menge bleibt, das Formular fragt nach der Größe.
|
||||
expect(m[2]).toMatchObject({ ingredient: { id: "cheese_slices" }, qty: 2, unit: "slice" });
|
||||
expect(m[3]).toMatchObject({ ingredient: { id: "potato" }, qty: 3, unit: "piece" });
|
||||
expect(m[4]).toMatchObject({ ingredient: { id: "milk" }, qty: 1, unit: "dash" });
|
||||
});
|
||||
|
||||
it("reads cans, jars and bunches; their size comes from the ingredient (26.11.39)", () => {
|
||||
const m = matchLines(["2 Dosen gehackte Tomaten", "1 Glas Pesto", "1 Bund Petersilie", "1 Bund Frühlingszwiebeln"], list, "de");
|
||||
expect(m[0]).toMatchObject({ ingredient: { id: "chopped_tomatoes", packSize: 400 }, qty: 2, unit: "can" });
|
||||
|
||||
+54
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatKitchen, formatQuantity, fromBase, impliedKitchenUnit, parseNumber, scale, shoppingQuantity, toBase, type BaseUnit, type KitchenUnit } from "@/lib/units";
|
||||
import { formatKitchen, formatQuantity, fromBase, impliedKitchenUnit, niceQty, parseNumber, scale, shoppingQuantity, sizeOf, toBase, type BaseUnit, type KitchenUnit } from "@/lib/units";
|
||||
|
||||
describe("units", () => {
|
||||
it("scales per-portion amounts", () => {
|
||||
@@ -99,3 +99,56 @@ describe("spoons and packs (26.11.39)", () => {
|
||||
expect(impliedKitchenUnit(2, "g", "pinch", null, null)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("more measures (26.11.49)", () => {
|
||||
const word = (u: KitchenUnit, n: number) => ({ clove: n === 1 ? "Zehe" : "Zehen", piece: "Stück", cup: n === 1 ? "Tasse" : "Tassen", tub: "Becher", knifepoint: "Msp." })[u as string] ?? u;
|
||||
it("fixed measures need no size", () => {
|
||||
expect(toBase(1, "cup", "ml")).toBe(240);
|
||||
expect(toBase(1, "dash", "ml")).toBe(10);
|
||||
expect(toBase(2, "knifepoint", "g")).toBe(1);
|
||||
expect(toBase(1, "cup", "piece")).toBeNull();
|
||||
});
|
||||
it("counted measures take the size of the ingredient; cloves of a piece ingredient are one piece", () => {
|
||||
expect(toBase(3, "piece", "g", 200)).toBe(600);
|
||||
expect(toBase(3, "piece", "g")).toBeNull();
|
||||
expect(toBase(2, "clove", "piece")).toBe(2);
|
||||
expect(toBase(1, "tub", "g", 150)).toBe(150);
|
||||
expect(fromBase(600, "piece", "g", 200)).toBe(3);
|
||||
expect(sizeOf("pack", "g", { packKind: "can", packSize: 400, sizes: { pack: 500 } })).toBe(500);
|
||||
expect(sizeOf("can", "g", { packKind: "can", packSize: 400 })).toBe(400);
|
||||
expect(sizeOf("slice", "g", {})).toBeNull();
|
||||
});
|
||||
it("shows pieces and cloves in front, tubs behind", () => {
|
||||
expect(formatKitchen(6, "g", "clove", 3, "de", word)).toEqual({ main: "2 Zehen", extra: "6 g" });
|
||||
expect(formatKitchen(600, "g", "piece", 200, "de", word)).toEqual({ main: "3 Stück", extra: "600 g" });
|
||||
expect(formatKitchen(150, "g", "tub", 150, "de", word)).toEqual({ main: "150 g", extra: "1 Becher" });
|
||||
expect(formatKitchen(0.5, "g", "knifepoint", null, "de", word)).toEqual({ main: "1 Msp.", extra: "" });
|
||||
});
|
||||
it("rounds amounts the way one would type them", () => {
|
||||
expect(niceQty(333.333, "g")).toBe(333);
|
||||
expect(niceQty(2.666, "g")).toBe(2.67);
|
||||
expect(niceQty(1.4999, "can")).toBe(1.5);
|
||||
expect(niceQty(0.1, "tbsp")).toBe(0.25);
|
||||
});
|
||||
});
|
||||
|
||||
describe("millilitres and litres everywhere (26.11.50)", () => {
|
||||
const word = (u: KitchenUnit, n: number) => (u === "piece" ? "Stück" : u) + (n > 1 ? "" : "");
|
||||
it("a piece ingredient in ml takes the size per piece", () => {
|
||||
expect(toBase(750, "ml", "piece", 500)).toBe(1.5);
|
||||
expect(toBase(1, "l", "piece", 500)).toBe(2);
|
||||
expect(toBase(750, "ml", "piece")).toBeNull();
|
||||
expect(fromBase(1.5, "ml", "piece", 500)).toBe(750);
|
||||
expect(sizeOf("l", "piece", { sizes: { ml: 500 } })).toBe(500);
|
||||
});
|
||||
it("grams and millilitres are one to one", () => {
|
||||
expect(toBase(200, "ml", "g")).toBe(200);
|
||||
expect(toBase(1, "kg", "ml")).toBe(1000);
|
||||
expect(fromBase(200, "ml", "g")).toBe(200);
|
||||
});
|
||||
it("shows the typed measure, with the pieces of a piece ingredient", () => {
|
||||
expect(formatKitchen(1.5, "piece", "ml", 500, "de", word)).toEqual({ main: "750 ml", extra: "1½ Stück" });
|
||||
expect(formatKitchen(1500, "ml", "l", null, "de", word).main).toBe("1,5 l");
|
||||
expect(formatKitchen(200, "g", "ml", null, "de", word)).toEqual({ main: "200 ml", extra: "" });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user