feat: Listen-Dialog mit Mengen/Einheiten, Mitai ohne Kochrezepte
Deploy Development / deploy (push) Successful in 1m7s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 22s

Roh-Kombinationen statt Rezept-Sprache; Zutaten suchen, EL/TL/Prise auf Gramm. Gekochte Gerichte und Ausbeute bleiben Tandoor.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-09-12 18:23:01 +02:00
1 parent a7e5511039
commit fa542e0fb9
17 files changed
+776 -203

No files matched your search

+47 -30
View File
@@ -2,7 +2,8 @@ import { useEffect, useMemo, useRef, useState } from 'react'
import { api } from '../utils/api'
import FoodSearchModal from './FoodSearchModal'
import FoodNutrientFields, { foodCreatePayload } from './FoodNutrientFields'
import FoodRecipeEditor, { RecipeForm } from './FoodRecipeEditor'
import FoodRecipeEditor from './FoodRecipeEditor'
import FoodRecipeDialog from './FoodRecipeDialog'
const PERIODS = [
{ days: 14, label: '14 Tage' },
@@ -52,14 +53,14 @@ function RecipePickModal({ recipes, sourceName, onPick, onClose }) {
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '14px 16px', borderBottom: '1px solid var(--border)' }}>
<h2 className="card-title" style={{ margin: 0, fontSize: 16 }}>Eigenes Rezept wählen</h2>
<h2 className="card-title" style={{ margin: 0, fontSize: 16 }}>Eigene Liste wählen</h2>
<button type="button" className="btn btn-secondary" onClick={onClose}>Schließen</button>
</div>
<div style={{ padding: '12px 16px' }}>
<input className="form-input" style={{ width: '100%', textAlign: 'left' }} autoFocus placeholder="Rezeptname filtern" value={q} onChange={(e) => setQ(e.target.value)} />
<input className="form-input" style={{ width: '100%', textAlign: 'left' }} autoFocus placeholder="Listenname filtern" value={q} onChange={(e) => setQ(e.target.value)} />
</div>
<div style={{ overflowY: 'auto', padding: '0 16px 16px', flex: 1 }}>
{filtered.length === 0 && <p style={{ fontSize: 13, color: 'var(--text3)' }}>Kein passendes Rezept.</p>}
{filtered.length === 0 && <p style={{ fontSize: 13, color: 'var(--text3)' }}>Keine passende Liste.</p>}
{filtered.map((r) => (
<button key={r.id} type="button" className="btn btn-secondary btn-full" style={{ marginTop: 8, justifyContent: 'flex-start', textAlign: 'left', height: 'auto', padding: '10px 12px' }} onClick={() => onPick(r.id)}>
<span>
@@ -74,7 +75,7 @@ function RecipePickModal({ recipes, sourceName, onPick, onClose }) {
)
}
function InlineCreate({ defaultName, disabled, learned, allowRecipe, onCreateFood, onCreateRecipe }) {
function InlineCreate({ defaultName, disabled, allowRecipe, onCreateFood, onWantRecipe }) {
const [kind, setKind] = useState(allowRecipe ? null : 'food')
const [name, setName] = useState(defaultName || '')
const [macros, setMacros] = useState({ kcal: '0', protein_g: '0', fat_g: '0', carbs_g: '0' })
@@ -83,28 +84,16 @@ function InlineCreate({ defaultName, disabled, learned, allowRecipe, onCreateFoo
if (!kind) {
return (
<div style={{ marginTop: 8, padding: 10, background: 'var(--surface2)', borderRadius: 8 }}>
<p style={{ fontSize: 12, margin: '0 0 8px', color: 'var(--text2)' }}>Lebensmittel (ein Eintrag im Katalog) oder Rezept (mehrere Zutaten)?</p>
<p style={{ fontSize: 12, margin: '0 0 8px', color: 'var(--text2)' }}>Lebensmittel (ein Eintrag im Katalog) oder Liste (Roh-Kombination, z. B. Müsli)?</p>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
<button type="button" className="btn btn-primary" disabled={disabled} onClick={() => setKind('food')}>Lebensmittel</button>
{allowRecipe && (
<button type="button" className="btn btn-secondary" disabled={disabled} onClick={() => setKind('recipe')}>Rezept</button>
<button type="button" className="btn btn-secondary" disabled={disabled} onClick={onWantRecipe}>Liste</button>
)}
</div>
</div>
)
}
if (kind === 'recipe') {
return (
<RecipeForm
defaultName={defaultName}
learned={learned}
disabled={disabled}
submitLabel="Rezept anlegen und zuordnen"
onCancel={() => setKind(null)}
onSave={onCreateRecipe}
/>
)
}
return (
<div style={{ marginTop: 8, padding: 10, background: 'var(--surface2)', borderRadius: 8 }}>
<p style={{ fontSize: 12, margin: '0 0 8px', color: 'var(--text2)' }}>Neuer Katalogeintrag. Salz: Makros 0. Öl/Supplement: Stoffe wie EPA dazusuchen.</p>
@@ -142,6 +131,7 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
const [saving, setSaving] = useState(null)
const [searchFor, setSearchFor] = useState(null)
const [recipeFor, setRecipeFor] = useState(null)
const [recipeDraft, setRecipeDraft] = useState(null)
const [createFor, setCreateFor] = useState(null)
const [filter, setFilter] = useState('all')
const [sinceDays, setSinceDays] = useState(28)
@@ -273,7 +263,7 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
await api.applyNutritionRecipe(rec.id, row.source_name_raw)
setCreateFor(null)
setSearchFor(null)
setNotice(`Rezept angelegt. Offene Zutaten erscheinen in der Liste.`)
setNotice('Liste angelegt. Offene Zutaten erscheinen unten zum Zuordnen.')
await load()
onMapped?.()
} catch (e) {
@@ -290,7 +280,7 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
try {
await api.applyNutritionRecipe(recipeId, sourceName)
setRecipeFor(null)
setNotice('Rezept verknüpft. Offene Zutaten erscheinen in der Liste.')
setNotice('Liste verknüpft. Offene Zutaten erscheinen unten zum Zuordnen.')
await load()
onMapped?.()
} catch (e) {
@@ -371,7 +361,7 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
<input ref={listRef} type="file" accept=".csv,text/csv" style={{ display: 'none' }} onChange={(e) => { const f = e.target.files?.[0]; e.target.value = ''; if (f) importLists(f) }} />
<button type="button" className="btn btn-secondary btn-full" disabled={importing} onClick={() => listRef.current?.click()}>
{importing ? 'Importiere Listen…' : 'FDDB-Listen / Rezepte importieren'}
{importing ? 'Importiere Listen…' : 'FDDB-Listen importieren'}
</button>
<FoodRecipeEditor recipes={recipes} learned={learned} onChanged={() => { load(); onChanged?.() }} />
<input ref={bundleRef} type="file" accept=".json,application/json" style={{ display: 'none' }} onChange={(e) => { const f = e.target.files?.[0]; e.target.value = ''; if (f) importBundle(f) }} />
@@ -422,7 +412,7 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
<div>
<div style={{ fontWeight: 600 }}>{suggestQuery(u.source_name_raw) || u.source_name_raw}</div>
<div style={{ fontSize: 12, color: 'var(--text3)' }}>
{u.kind === 'recipe_ingredient' ? 'Rezeptzutat' : `${u.count}×`}
{u.kind === 'recipe_ingredient' ? 'Listenzutat' : `${u.count}×`}
{u.variant_count > 1 ? ` · ${u.variant_count} Mengen` : ''}
{u.last_date ? ` · zuletzt ${formatDay(u.last_date)}` : ''}
</div>
@@ -455,24 +445,30 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 8 }}>
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => setCreateFor(createFor === key ? null : key)}>
{createFor === key ? 'Anlegen schließen' : (u.kind === 'recipe_ingredient' ? 'Neu anlegen' : 'Lebensmittel oder Rezept')}
{createFor === key ? 'Anlegen schließen' : (u.kind === 'recipe_ingredient' ? 'Neu anlegen' : 'Lebensmittel oder Liste')}
</button>
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => setSearchFor(u)}>Mehr suchen</button>
{u.kind !== 'recipe_ingredient' && u.matching_recipe_id && (
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => applyRecipe(u.source_name_raw, u.matching_recipe_id)}>Als Rezept</button>
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => applyRecipe(u.source_name_raw, u.matching_recipe_id)}>Als Liste</button>
)}
{u.kind !== 'recipe_ingredient' && recipes.length > 0 && (
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => setRecipeFor(u)}>Rezept wählen</button>
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => setRecipeFor(u)}>Liste wählen</button>
)}
</div>
{createFor === key && (
<InlineCreate
defaultName={suggestQuery(u.source_name_raw) || u.source_name_raw}
disabled={busyRow}
learned={learned}
allowRecipe={u.kind !== 'recipe_ingredient'}
onCreateFood={(body) => createAndAssign(u, body)}
onCreateRecipe={(body) => createRecipeAndAssign(u, body)}
onWantRecipe={() => {
setCreateFor(null)
setSearchFor(null)
setRecipeDraft({
row: u,
defaultName: suggestQuery(u.source_name_raw) || u.source_name_raw,
})
}}
/>
)}
</div>
@@ -509,10 +505,31 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
initialQuery={suggestQuery(searchFor.source_name_raw)}
quantityHint={searchFor.sample_quantity_raw || searchFor.source_name_raw}
allowRecipe={searchFor.kind !== 'recipe_ingredient'}
learned={learned}
onClose={() => setSearchFor(null)}
onSelect={(food, extras) => assign(searchFor, food.id, extras, food)}
onCreateRecipe={searchFor.kind === 'recipe_ingredient' ? undefined : (body) => createRecipeAndAssign(searchFor, body)}
onWantRecipe={searchFor.kind === 'recipe_ingredient' ? undefined : () => {
const row = searchFor
setSearchFor(null)
setCreateFor(null)
setRecipeDraft({
row,
defaultName: suggestQuery(row.source_name_raw) || row.source_name_raw,
})
}}
/>
)}
{recipeDraft && (
<FoodRecipeDialog
title="Liste anlegen"
defaultName={recipeDraft.defaultName}
learned={learned}
disabled={saving === recipeDraft.row.source_name_raw}
submitLabel="Liste anlegen und zuordnen"
onClose={() => setRecipeDraft(null)}
onSave={async (body) => {
await createRecipeAndAssign(recipeDraft.row, body)
setRecipeDraft(null)
}}
/>
)}
{recipeFor && (