feat: Listen-Dialog mit Mengen/Einheiten, Mitai ohne Kochrezepte
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:
1 parent
a7e5511039
commit
fa542e0fb9
17 files changed
+776
-203
No files matched your search
@@ -0,0 +1,477 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
const FALLBACK_UNITS = [
|
||||
{ id: 'g', label: 'g', default_g: 1, needs_unit_map: false },
|
||||
{ id: 'ml', label: 'ml', default_g: 1, needs_unit_map: false },
|
||||
{ id: 'el', label: 'EL', default_g: 15, needs_unit_map: false },
|
||||
{ id: 'tl', label: 'TL', default_g: 5, needs_unit_map: false },
|
||||
{ id: 'prise', label: 'Prise', default_g: 0.3, needs_unit_map: false },
|
||||
{ id: 'msp', label: 'Msp.', default_g: 1, needs_unit_map: false },
|
||||
{ id: 'stück', label: 'Stück', default_g: null, needs_unit_map: true },
|
||||
{ id: 'scheibe', label: 'Scheibe', default_g: null, needs_unit_map: true },
|
||||
{ id: 'portion', label: 'Portion', default_g: null, needs_unit_map: true },
|
||||
{ id: 'becher', label: 'Becher', default_g: null, needs_unit_map: true },
|
||||
{ id: 'tasse', label: 'Tasse', default_g: null, needs_unit_map: true },
|
||||
{ id: 'kg', label: 'kg', default_g: 1000, needs_unit_map: false },
|
||||
{ id: 'l', label: 'l', default_g: 1000, needs_unit_map: false },
|
||||
]
|
||||
|
||||
function emptyIng(overrides = {}) {
|
||||
return {
|
||||
source_name_raw: '',
|
||||
amount: '',
|
||||
unit: 'g',
|
||||
gramsPerUnit: '',
|
||||
foodId: null,
|
||||
mappedLabel: '',
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function unitMeta(units, id) {
|
||||
return (units || []).find((u) => u.id === id) || FALLBACK_UNITS.find((u) => u.id === id)
|
||||
}
|
||||
|
||||
function gramsHint(ing, units) {
|
||||
const amount = parseFloat(String(ing.amount).replace(',', '.'))
|
||||
if (!Number.isFinite(amount) || amount <= 0) return null
|
||||
const meta = unitMeta(units, ing.unit)
|
||||
const factor = parseFloat(String(ing.gramsPerUnit).replace(',', '.'))
|
||||
const per = Number.isFinite(factor) && factor > 0 ? factor : meta?.default_g
|
||||
if (!per) return null
|
||||
const g = Math.round(amount * per * 1000) / 1000
|
||||
return g
|
||||
}
|
||||
|
||||
function fromSavedIngredient(i, mapped) {
|
||||
let amount = i.quantity_amount
|
||||
let unit = i.source_unit || 'g'
|
||||
if (amount == null && i.quantity_raw) {
|
||||
const m = String(i.quantity_raw).trim().match(/^(\d+(?:[.,]\d+)?)\s*(.*)$/)
|
||||
if (m) {
|
||||
amount = m[1].replace(',', '.')
|
||||
const label = (m[2] || '').trim().toLowerCase()
|
||||
const hit = FALLBACK_UNITS.find((u) => u.id === label || u.label.toLowerCase() === label)
|
||||
if (hit) unit = hit.id
|
||||
}
|
||||
}
|
||||
if (amount == null && i.quantity_g != null) {
|
||||
amount = i.quantity_g
|
||||
unit = i.source_unit || 'g'
|
||||
}
|
||||
return emptyIng({
|
||||
source_name_raw: i.source_name_raw || '',
|
||||
amount: amount ?? '',
|
||||
unit,
|
||||
gramsPerUnit: mapped?.grams_per_unit ?? '',
|
||||
foodId: mapped?.food_id || null,
|
||||
mappedLabel: mapped?.food_name_de || '',
|
||||
})
|
||||
}
|
||||
|
||||
function mappingFor(name, learned) {
|
||||
const n = (name || '').trim().toLowerCase()
|
||||
if (!n) return null
|
||||
return (learned || []).find((m) => {
|
||||
const raw = (m.source_name_raw || '').toLowerCase()
|
||||
const norm = (m.source_name_normalized || '').toLowerCase()
|
||||
return raw === n || norm === n
|
||||
}) || null
|
||||
}
|
||||
|
||||
function filterLearned(term, learned) {
|
||||
const t = (term || '').trim().toLowerCase()
|
||||
if (t.length < 2) return []
|
||||
return (learned || []).filter((m) => {
|
||||
const hay = `${m.source_name_raw || ''} ${m.food_name_de || ''} ${m.bls_code || ''}`.toLowerCase()
|
||||
return hay.includes(t)
|
||||
}).slice(0, 8)
|
||||
}
|
||||
|
||||
export default function FoodRecipeDialog({
|
||||
title,
|
||||
defaultName,
|
||||
defaultPortions,
|
||||
defaultIngredients,
|
||||
learned,
|
||||
disabled,
|
||||
submitLabel,
|
||||
onSave,
|
||||
onClose,
|
||||
}) {
|
||||
const [name, setName] = useState(defaultName || '')
|
||||
const [portions, setPortions] = useState(defaultPortions != null ? String(defaultPortions) : '1')
|
||||
const [ings, setIngs] = useState(
|
||||
(defaultIngredients || []).length
|
||||
? defaultIngredients.map((i) => fromSavedIngredient(i, mappingFor(i.source_name_raw, learned)))
|
||||
: []
|
||||
)
|
||||
const [units, setUnits] = useState(FALLBACK_UNITS)
|
||||
const [q, setQ] = useState('')
|
||||
const [catalogHits, setCatalogHits] = useState([])
|
||||
const [searching, setSearching] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [localLearned, setLocalLearned] = useState(learned || [])
|
||||
const nameRef = useRef(null)
|
||||
const qtyRefs = useRef({})
|
||||
const timer = useRef(null)
|
||||
const abortRef = useRef(null)
|
||||
const seqRef = useRef(0)
|
||||
|
||||
useEffect(() => { setLocalLearned(learned || []) }, [learned])
|
||||
|
||||
useEffect(() => {
|
||||
api.listFoodUnits().then((list) => {
|
||||
if (Array.isArray(list) && list.length) setUnits(list)
|
||||
}).catch(() => {})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
nameRef.current?.focus()
|
||||
const onKey = (e) => { if (e.key === 'Escape' && !saving) onClose() }
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => {
|
||||
window.removeEventListener('keydown', onKey)
|
||||
clearTimeout(timer.current)
|
||||
abortRef.current?.abort()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const mappedHits = filterLearned(q, localLearned)
|
||||
const mappedNames = new Set(mappedHits.map((m) => (m.food_name_de || '').toLowerCase()))
|
||||
const catalogOnly = catalogHits.filter((h) => !mappedNames.has((h.name_de || '').toLowerCase()))
|
||||
|
||||
const runCatalog = async (term) => {
|
||||
const query = (term || '').trim()
|
||||
abortRef.current?.abort()
|
||||
if (query.length < 2) {
|
||||
setCatalogHits([])
|
||||
setSearching(false)
|
||||
return
|
||||
}
|
||||
const seq = ++seqRef.current
|
||||
const ac = new AbortController()
|
||||
abortRef.current = ac
|
||||
setSearching(true)
|
||||
try {
|
||||
const next = await api.searchBlsFoods(query, 12, ac.signal)
|
||||
if (seq !== seqRef.current) return
|
||||
setCatalogHits(Array.isArray(next) ? next : [])
|
||||
} catch (e) {
|
||||
if (e.name === 'AbortError') return
|
||||
if (seq !== seqRef.current) return
|
||||
setCatalogHits([])
|
||||
} finally {
|
||||
if (seq === seqRef.current) setSearching(false)
|
||||
}
|
||||
}
|
||||
|
||||
const onSearch = (value) => {
|
||||
setQ(value)
|
||||
clearTimeout(timer.current)
|
||||
if (value.trim().length < 2) {
|
||||
abortRef.current?.abort()
|
||||
setCatalogHits([])
|
||||
setSearching(false)
|
||||
return
|
||||
}
|
||||
timer.current = setTimeout(() => runCatalog(value), 300)
|
||||
}
|
||||
|
||||
const focusQty = (idx) => {
|
||||
setTimeout(() => qtyRefs.current[idx]?.focus(), 30)
|
||||
}
|
||||
|
||||
const addIngredient = (ing) => {
|
||||
const raw = (ing.source_name_raw || '').trim()
|
||||
if (!raw) return
|
||||
setIngs((list) => {
|
||||
const exists = list.findIndex((x) => (x.source_name_raw || '').trim().toLowerCase() === raw.toLowerCase())
|
||||
if (exists >= 0) {
|
||||
focusQty(exists)
|
||||
return list
|
||||
}
|
||||
const next = [...list, emptyIng({ ...ing, source_name_raw: raw })]
|
||||
focusQty(next.length - 1)
|
||||
return next
|
||||
})
|
||||
setQ('')
|
||||
setCatalogHits([])
|
||||
setError(null)
|
||||
}
|
||||
|
||||
const addMapped = (m) => addIngredient({
|
||||
source_name_raw: m.source_name_raw,
|
||||
foodId: m.food_id,
|
||||
mappedLabel: m.food_name_de || '',
|
||||
unit: m.source_unit || 'g',
|
||||
gramsPerUnit: m.grams_per_unit ?? '',
|
||||
})
|
||||
|
||||
const addCatalog = (h) => addIngredient({
|
||||
source_name_raw: h.name_de,
|
||||
foodId: h.id,
|
||||
mappedLabel: h.name_de,
|
||||
})
|
||||
|
||||
const addFreeText = () => {
|
||||
const raw = q.trim()
|
||||
if (!raw) return
|
||||
addIngredient({ source_name_raw: raw })
|
||||
}
|
||||
|
||||
const save = async () => {
|
||||
const ingredients = ings
|
||||
.map((i) => {
|
||||
const amount = i.amount === '' ? null : parseFloat(String(i.amount).replace(',', '.'))
|
||||
const gpu = i.gramsPerUnit === '' ? null : parseFloat(String(i.gramsPerUnit).replace(',', '.'))
|
||||
return {
|
||||
source_name_raw: (i.source_name_raw || '').trim(),
|
||||
quantity_amount: Number.isFinite(amount) ? amount : null,
|
||||
source_unit: i.unit || 'g',
|
||||
grams_per_unit: Number.isFinite(gpu) && gpu > 0 ? gpu : null,
|
||||
foodId: i.foodId,
|
||||
}
|
||||
})
|
||||
.filter((i) => i.source_name_raw)
|
||||
if (!name.trim()) {
|
||||
setError('Listenname fehlt')
|
||||
return
|
||||
}
|
||||
if (!ingredients.length) {
|
||||
setError('Mindestens eine Zutat angeben')
|
||||
return
|
||||
}
|
||||
if (ingredients.some((i) => i.quantity_amount == null || i.quantity_amount <= 0)) {
|
||||
setError('Jede Zutat braucht eine Menge')
|
||||
return
|
||||
}
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
try {
|
||||
const nextLearned = [...localLearned]
|
||||
for (const ing of ingredients) {
|
||||
if (!ing.foodId) continue
|
||||
const already = nextLearned.some((m) => (
|
||||
(m.source_name_raw || '').trim().toLowerCase() === ing.source_name_raw.toLowerCase()
|
||||
))
|
||||
if (already && !ing.grams_per_unit) continue
|
||||
const res = await api.upsertMyFoodMapping({
|
||||
source_name: ing.source_name_raw,
|
||||
food_id: ing.foodId,
|
||||
grams_per_unit: ing.grams_per_unit,
|
||||
source_unit: ing.source_unit,
|
||||
})
|
||||
nextLearned.unshift({
|
||||
id: res.mapping_id,
|
||||
source_name_raw: ing.source_name_raw,
|
||||
food_id: ing.foodId,
|
||||
food_name_de: res.food_name_de || ing.source_name_raw,
|
||||
})
|
||||
}
|
||||
setLocalLearned(nextLearned)
|
||||
await onSave({
|
||||
name_raw: name.trim(),
|
||||
portions: parseFloat(String(portions).replace(',', '.')) || 1,
|
||||
ingredients: ingredients.map(({ source_name_raw, quantity_amount, source_unit, grams_per_unit }) => ({
|
||||
source_name_raw,
|
||||
quantity_amount,
|
||||
source_unit,
|
||||
grams_per_unit,
|
||||
})),
|
||||
})
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const showResults = q.trim().length >= 2
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.45)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 21000,
|
||||
padding: 16,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="recipe-dialog-title"
|
||||
style={{
|
||||
width: '100%', maxWidth: 560, maxHeight: 'min(92vh, 800px)',
|
||||
background: 'var(--surface)', borderRadius: 16,
|
||||
boxShadow: '0 8px 32px rgba(0,0,0,0.18)',
|
||||
display: 'flex', flexDirection: 'column',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '14px 16px', borderBottom: '1px solid var(--border)' }}>
|
||||
<h2 id="recipe-dialog-title" className="card-title" style={{ margin: 0, fontSize: 16 }}>{title || 'Liste'}</h2>
|
||||
<button type="button" className="btn btn-secondary" disabled={saving} onClick={onClose}>Schließen</button>
|
||||
</div>
|
||||
|
||||
<div style={{ overflowY: 'auto', padding: '12px 16px 16px', flex: 1 }}>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', lineHeight: 1.5, margin: '0 0 12px' }}>
|
||||
Roh-Kombination ohne Kochen (z. B. Müsli). Zutaten suchen, Menge und Einheit angeben. Gramm ist die Standardeinheit — EL, TL, Prise usw. werden umgerechnet, sobald der Faktor bekannt ist. Gekochte Gerichte bleiben in Tandoor.
|
||||
</p>
|
||||
{error && <div style={{ color: 'var(--danger)', fontSize: 13, marginBottom: 10 }}>{error}</div>}
|
||||
|
||||
<label className="form-label">Name der Liste</label>
|
||||
<input
|
||||
ref={nameRef}
|
||||
className="form-input"
|
||||
style={{ width: '100%', textAlign: 'left', marginBottom: 12 }}
|
||||
placeholder="z. B. Overnight Oats"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
<label className="form-label">Portionen</label>
|
||||
<input
|
||||
className="form-input"
|
||||
type="number"
|
||||
min="0.1"
|
||||
step="0.1"
|
||||
style={{ width: 96, textAlign: 'left', marginBottom: 16 }}
|
||||
value={portions}
|
||||
onChange={(e) => setPortions(e.target.value)}
|
||||
/>
|
||||
|
||||
<p style={{ fontSize: 13, fontWeight: 600, margin: '0 0 8px' }}>Zutat suchen</p>
|
||||
<input
|
||||
className="form-input"
|
||||
style={{ width: '100%', textAlign: 'left' }}
|
||||
placeholder="Name, z. B. Haferflocken oder Joghurt 10%"
|
||||
value={q}
|
||||
onChange={(e) => onSearch(e.target.value)}
|
||||
onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); addFreeText() } }}
|
||||
/>
|
||||
{showResults && (
|
||||
<div style={{ marginTop: 8, border: '1px solid var(--border)', borderRadius: 10, background: 'var(--surface2)' }}>
|
||||
{mappedHits.length > 0 && (
|
||||
<div style={{ padding: '8px 10px 4px', fontSize: 11, color: 'var(--text3)' }}>Bereits zugeordnet</div>
|
||||
)}
|
||||
{mappedHits.map((m) => (
|
||||
<button
|
||||
key={m.id || m.source_name_raw}
|
||||
type="button"
|
||||
className="btn btn-secondary btn-full"
|
||||
style={{ margin: '0 8px 8px', justifyContent: 'flex-start', textAlign: 'left', height: 'auto', padding: '8px 10px' }}
|
||||
onClick={() => addMapped(m)}
|
||||
>
|
||||
<span>
|
||||
<strong style={{ display: 'block' }}>{m.source_name_raw}</strong>
|
||||
<span style={{ fontSize: 12, color: 'var(--text3)' }}>→ {m.food_name_de}{m.bls_code ? ` · ${m.bls_code}` : ''}</span>
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
{searching && <p style={{ fontSize: 12, color: 'var(--text2)', padding: '6px 10px' }}>Katalog…</p>}
|
||||
{catalogOnly.length > 0 && (
|
||||
<div style={{ padding: '8px 10px 4px', fontSize: 11, color: 'var(--text3)' }}>Katalog</div>
|
||||
)}
|
||||
{catalogOnly.map((h) => (
|
||||
<button
|
||||
key={h.id}
|
||||
type="button"
|
||||
className="btn btn-secondary btn-full"
|
||||
style={{ margin: '0 8px 8px', justifyContent: 'flex-start', textAlign: 'left', height: 'auto', padding: '8px 10px' }}
|
||||
onClick={() => addCatalog(h)}
|
||||
>
|
||||
<span>
|
||||
<strong style={{ display: 'block' }}>{h.name_de}</strong>
|
||||
<span style={{ fontSize: 12, color: 'var(--text3)' }}>
|
||||
{h.bls_code ? `BLS ${h.bls_code}` : 'ohne Code'}
|
||||
{h.catalog_kind !== 'official_bls' ? ' · manuell' : ''}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
<button type="button" className="btn btn-secondary btn-full" style={{ margin: '0 8px 8px' }} onClick={addFreeText}>
|
||||
„{q.trim()}“ als offene Zutat übernehmen
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<p style={{ fontSize: 13, fontWeight: 600, margin: '16px 0 8px' }}>Zutaten ({ings.length})</p>
|
||||
{ings.length === 0 && (
|
||||
<p style={{ fontSize: 13, color: 'var(--text3)', margin: 0 }}>Noch keine Zutaten — oben suchen und übernehmen.</p>
|
||||
)}
|
||||
{ings.map((ing, i) => {
|
||||
const mapped = mappingFor(ing.source_name_raw, localLearned) || (ing.foodId ? { food_name_de: ing.mappedLabel } : null)
|
||||
const meta = unitMeta(units, ing.unit)
|
||||
const approx = gramsHint(ing, units)
|
||||
const needsFactor = Boolean(meta?.needs_unit_map) && !approx
|
||||
const isMass = ['g', 'ml', 'kg', 'l'].includes(ing.unit)
|
||||
return (
|
||||
<div key={`${ing.source_name_raw}-${i}`} style={{ borderTop: '1px solid var(--border)', padding: '10px 0' }}>
|
||||
<div style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
|
||||
<input
|
||||
className="form-input"
|
||||
style={{ textAlign: 'left', flex: 1 }}
|
||||
value={ing.source_name_raw}
|
||||
onChange={(e) => setIngs((list) => list.map((x, j) => j === i ? { ...x, source_name_raw: e.target.value, foodId: null, mappedLabel: '' } : x))}
|
||||
/>
|
||||
<button type="button" className="btn btn-secondary" style={{ padding: '6px 10px' }} onClick={() => setIngs((list) => list.filter((_, j) => j !== i))} aria-label="Zutat entfernen">×</button>
|
||||
</div>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 6, marginTop: 6 }}>
|
||||
<input
|
||||
ref={(el) => { qtyRefs.current[i] = el }}
|
||||
className="form-input"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.1"
|
||||
style={{ textAlign: 'left' }}
|
||||
placeholder="Menge"
|
||||
value={ing.amount}
|
||||
onChange={(e) => setIngs((list) => list.map((x, j) => j === i ? { ...x, amount: e.target.value } : x))}
|
||||
/>
|
||||
<select
|
||||
className="form-input"
|
||||
style={{ textAlign: 'left' }}
|
||||
value={ing.unit}
|
||||
onChange={(e) => setIngs((list) => list.map((x, j) => j === i ? { ...x, unit: e.target.value } : x))}
|
||||
>
|
||||
{units.map((u) => (
|
||||
<option key={u.id} value={u.id}>{u.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{!isMass && (
|
||||
<label style={{ display: 'block', fontSize: 12, color: 'var(--text2)', marginTop: 6 }}>
|
||||
1 {meta?.label || ing.unit} ={' '}
|
||||
<input
|
||||
className="form-input"
|
||||
type="number"
|
||||
min="0.01"
|
||||
step="0.1"
|
||||
style={{ width: 80, display: 'inline-block', textAlign: 'left' }}
|
||||
placeholder={meta?.default_g != null ? String(meta.default_g) : 'g'}
|
||||
value={ing.gramsPerUnit}
|
||||
onChange={(e) => setIngs((list) => list.map((x, j) => j === i ? { ...x, gramsPerUnit: e.target.value } : x))}
|
||||
/>
|
||||
{' '}g
|
||||
</label>
|
||||
)}
|
||||
<div style={{ fontSize: 11, color: mapped ? 'var(--accent-dark)' : 'var(--text3)', marginTop: 4 }}>
|
||||
{approx != null ? `≈ ${String(approx).replace('.', ',')} g` : (needsFactor ? 'Gramm pro Einheit fehlt — später umrechenbar' : '')}
|
||||
{mapped ? ` · zugeordnet: ${mapped.food_name_de || ing.mappedLabel}` : ' · noch offen — nach dem Speichern in der Liste zuordnen'}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 8, padding: '12px 16px', borderTop: '1px solid var(--border)' }}>
|
||||
<button type="button" className="btn btn-secondary" disabled={saving || disabled} onClick={onClose}>Abbrechen</button>
|
||||
<button type="button" className="btn btn-primary" style={{ flex: 1 }} disabled={saving || disabled} onClick={save}>
|
||||
{saving ? 'Speichere…' : (submitLabel || 'Liste speichern')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,118 +1,20 @@
|
||||
import { useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
function emptyIng() {
|
||||
return { source_name_raw: '', quantity_g: '' }
|
||||
}
|
||||
|
||||
function mappingHint(name, learned) {
|
||||
const n = (name || '').trim().toLowerCase()
|
||||
if (!n) return null
|
||||
return (learned || []).find((m) => {
|
||||
const raw = (m.source_name_raw || '').toLowerCase()
|
||||
const norm = (m.source_name_normalized || '').toLowerCase()
|
||||
return raw === n || norm === n || raw.includes(n) || n.includes(norm)
|
||||
}) || null
|
||||
}
|
||||
|
||||
export function RecipeForm({ defaultName, defaultPortions, defaultIngredients, learned, disabled, submitLabel, onSave, onCancel }) {
|
||||
const [name, setName] = useState(defaultName || '')
|
||||
const [portions, setPortions] = useState(defaultPortions != null ? String(defaultPortions) : '1')
|
||||
const [ings, setIngs] = useState(
|
||||
(defaultIngredients || []).length
|
||||
? defaultIngredients.map((i) => ({ source_name_raw: i.source_name_raw || '', quantity_g: i.quantity_g ?? '' }))
|
||||
: [emptyIng()]
|
||||
)
|
||||
const [error, setError] = useState(null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
const save = async () => {
|
||||
const ingredients = ings
|
||||
.map((i) => ({
|
||||
source_name_raw: (i.source_name_raw || '').trim(),
|
||||
quantity_g: i.quantity_g === '' ? null : parseFloat(String(i.quantity_g).replace(',', '.')),
|
||||
}))
|
||||
.filter((i) => i.source_name_raw)
|
||||
if (!name.trim()) {
|
||||
setError('Rezeptname fehlt')
|
||||
return
|
||||
}
|
||||
if (!ingredients.length) {
|
||||
setError('Mindestens eine Zutat angeben')
|
||||
return
|
||||
}
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
try {
|
||||
await onSave({
|
||||
name_raw: name.trim(),
|
||||
portions: parseFloat(String(portions).replace(',', '.')) || 1,
|
||||
ingredients,
|
||||
})
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ marginTop: 8, padding: 10, background: 'var(--surface2)', borderRadius: 8 }}>
|
||||
<p style={{ fontSize: 12, margin: '0 0 8px', color: 'var(--text2)' }}>
|
||||
Zutaten, die schon zugeordnet sind, werden übernommen. Offene erscheinen danach in der Liste zum Zuordnen.
|
||||
</p>
|
||||
{error && <div style={{ color: 'var(--danger)', fontSize: 13, marginBottom: 8 }}>{error}</div>}
|
||||
<input className="form-input" style={{ width: '100%', textAlign: 'left', marginBottom: 8 }} placeholder="Rezeptname" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
<label style={{ fontSize: 12, color: 'var(--text2)' }}>
|
||||
Portionen
|
||||
<input className="form-input" type="number" min="0.1" step="0.1" style={{ width: 80, textAlign: 'left', marginLeft: 8 }} value={portions} onChange={(e) => setPortions(e.target.value)} />
|
||||
</label>
|
||||
<p style={{ fontSize: 12, margin: '10px 0 6px', color: 'var(--text2)' }}>Zutaten (Name + Gramm)</p>
|
||||
{ings.map((ing, i) => {
|
||||
const mapped = mappingHint(ing.source_name_raw, learned)
|
||||
return (
|
||||
<div key={i} style={{ marginBottom: 8 }}>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 80px', gap: 6 }}>
|
||||
<input className="form-input" style={{ textAlign: 'left' }} placeholder="z. B. Haferflocken" value={ing.source_name_raw} onChange={(e) => setIngs((list) => list.map((x, j) => j === i ? { ...x, source_name_raw: e.target.value } : x))} />
|
||||
<input className="form-input" type="number" min="0" step="0.1" style={{ textAlign: 'left' }} placeholder="g" value={ing.quantity_g} onChange={(e) => setIngs((list) => list.map((x, j) => j === i ? { ...x, quantity_g: e.target.value } : x))} />
|
||||
</div>
|
||||
{ing.source_name_raw.trim() && (
|
||||
<div style={{ fontSize: 11, color: mapped ? 'var(--accent-dark)' : 'var(--text3)', marginTop: 2 }}>
|
||||
{mapped ? `zugeordnet: ${mapped.food_name_de || mapped.source_name_raw}` : 'noch offen — nach dem Speichern in der Liste zuordnen'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 12 }} onClick={() => setIngs((list) => [...list, emptyIng()])}>Zutat hinzufügen</button>
|
||||
<div style={{ display: 'flex', gap: 8, marginTop: 10 }}>
|
||||
{onCancel && (
|
||||
<button type="button" className="btn btn-secondary" disabled={saving} onClick={onCancel}>Zurück</button>
|
||||
)}
|
||||
<button type="button" className="btn btn-primary" style={{ flex: 1 }} disabled={disabled || saving} onClick={save}>
|
||||
{saving ? 'Speichere…' : (submitLabel || 'Rezept speichern')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
import FoodRecipeDialog from './FoodRecipeDialog'
|
||||
|
||||
export default function FoodRecipeEditor({ recipes, learned, onChanged }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [editing, setEditing] = useState(null)
|
||||
const [draft, setDraft] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const startNew = () => {
|
||||
setEditing('new')
|
||||
setDraft({ name: '', portions: '1' })
|
||||
setError(null)
|
||||
setOpen(true)
|
||||
}
|
||||
|
||||
const startEdit = (r) => {
|
||||
setEditing(r)
|
||||
setDraft(r)
|
||||
setError(null)
|
||||
setOpen(true)
|
||||
}
|
||||
@@ -121,12 +23,11 @@ export default function FoodRecipeEditor({ recipes, learned, onChanged }) {
|
||||
if (editing === 'new') await api.createNutritionRecipe(body)
|
||||
else await api.updateNutritionRecipe(editing.id, body)
|
||||
setEditing(null)
|
||||
setDraft(null)
|
||||
onChanged?.()
|
||||
}
|
||||
|
||||
const remove = async (id) => {
|
||||
if (!confirm('Rezept wirklich löschen?')) return
|
||||
if (!confirm('Liste wirklich löschen?')) return
|
||||
try {
|
||||
await api.deleteNutritionRecipe(id)
|
||||
if (editing && editing !== 'new' && editing.id === id) setEditing(null)
|
||||
@@ -139,7 +40,7 @@ export default function FoodRecipeEditor({ recipes, learned, onChanged }) {
|
||||
return (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8 }}>
|
||||
<h3 style={{ fontSize: 14, margin: 0 }}>Eigene Rezepte / Listen ({recipes.length})</h3>
|
||||
<h3 style={{ fontSize: 14, margin: 0 }}>Eigene Listen / Kombinationen ({recipes.length})</h3>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 12 }} onClick={() => { setOpen((v) => !v); if (open) setEditing(null) }}>
|
||||
{open ? 'Einklappen' : 'Anzeigen'}
|
||||
</button>
|
||||
@@ -147,7 +48,7 @@ export default function FoodRecipeEditor({ recipes, learned, onChanged }) {
|
||||
{open && (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
{error && <div style={{ color: 'var(--danger)', fontSize: 13, marginBottom: 8 }}>{error}</div>}
|
||||
<button type="button" className="btn btn-secondary btn-full" onClick={startNew}>Rezept anlegen</button>
|
||||
<button type="button" className="btn btn-secondary btn-full" onClick={startNew}>Liste anlegen</button>
|
||||
{recipes.map((r) => (
|
||||
<div key={r.id} style={{ borderTop: '1px solid var(--border)', padding: '8px 0', marginTop: 8 }}>
|
||||
<div style={{ fontWeight: 600 }}>{r.name_raw}</div>
|
||||
@@ -161,23 +62,30 @@ export default function FoodRecipeEditor({ recipes, learned, onChanged }) {
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{editing === 'new' && (
|
||||
<RecipeForm learned={learned} submitLabel="Rezept anlegen" onSave={save} onCancel={() => setEditing(null)} />
|
||||
)}
|
||||
{editing && editing !== 'new' && (
|
||||
<RecipeForm
|
||||
key={editing.id}
|
||||
defaultName={draft?.name_raw}
|
||||
defaultPortions={draft?.portions}
|
||||
defaultIngredients={draft?.ingredients}
|
||||
learned={learned}
|
||||
submitLabel="Rezept speichern"
|
||||
onSave={save}
|
||||
onCancel={() => setEditing(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{editing === 'new' && (
|
||||
<FoodRecipeDialog
|
||||
title="Liste anlegen"
|
||||
learned={learned}
|
||||
submitLabel="Liste anlegen"
|
||||
onSave={save}
|
||||
onClose={() => setEditing(null)}
|
||||
/>
|
||||
)}
|
||||
{editing && editing !== 'new' && (
|
||||
<FoodRecipeDialog
|
||||
key={editing.id}
|
||||
title="Liste bearbeiten"
|
||||
defaultName={editing.name_raw}
|
||||
defaultPortions={editing.portions}
|
||||
defaultIngredients={editing.ingredients}
|
||||
learned={learned}
|
||||
submitLabel="Liste speichern"
|
||||
onSave={save}
|
||||
onClose={() => setEditing(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
import FoodNutrientFields, { foodCreatePayload } from './FoodNutrientFields'
|
||||
import { RecipeForm } from './FoodRecipeEditor'
|
||||
|
||||
const COUNT_UNITS = new Set(['stück', 'scheibe', 'portion', 'becher', 'tasse'])
|
||||
const UNIT_LABEL = {
|
||||
@@ -26,7 +25,7 @@ function detectUnit(...texts) {
|
||||
return null
|
||||
}
|
||||
|
||||
export default function FoodSearchModal({ title, initialQuery, quantityHint, allowRecipe, learned, onSelect, onCreateRecipe, onClose }) {
|
||||
export default function FoodSearchModal({ title, initialQuery, quantityHint, allowRecipe, onSelect, onWantRecipe, onClose }) {
|
||||
const [q, setQ] = useState(initialQuery || '')
|
||||
const [hits, setHits] = useState([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
@@ -210,30 +209,21 @@ export default function FoodSearchModal({ title, initialQuery, quantityHint, all
|
||||
{!showCreate ? (
|
||||
<button type="button" className="btn btn-secondary btn-full" onClick={() => {
|
||||
setShowCreate(true)
|
||||
setCreateKind(allowRecipe && onCreateRecipe ? null : 'food')
|
||||
setCreateKind(allowRecipe && onWantRecipe ? null : 'food')
|
||||
setManual((s) => ({ ...s, name_de: s.name_de || q || initialQuery || '' }))
|
||||
}}>
|
||||
{allowRecipe && onCreateRecipe ? 'Lebensmittel oder Rezept anlegen' : 'Eigenes Lebensmittel anlegen'}
|
||||
{allowRecipe && onWantRecipe ? 'Lebensmittel oder Liste anlegen' : 'Eigenes Lebensmittel anlegen'}
|
||||
</button>
|
||||
) : !createKind ? (
|
||||
<div>
|
||||
<p style={{ fontSize: 13, fontWeight: 600, marginBottom: 8 }}>Was möchtest du anlegen?</p>
|
||||
<p style={{ fontSize: 12, color: 'var(--text2)', margin: '0 0 8px' }}>Lebensmittel = ein Katalogeintrag. Rezept = mehrere Zutaten; offene Zutaten erscheinen danach in der Liste.</p>
|
||||
<p style={{ fontSize: 12, color: 'var(--text2)', margin: '0 0 8px' }}>Lebensmittel = ein Katalogeintrag. Liste = Roh-Kombination (z. B. Müsli) mit Zutatensuche.</p>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
|
||||
<button type="button" className="btn btn-primary" onClick={() => setCreateKind('food')}>Lebensmittel</button>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => setCreateKind('recipe')}>Rezept</button>
|
||||
<button type="button" className="btn btn-secondary" onClick={onWantRecipe}>Liste</button>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => { setShowCreate(false); setCreateKind(null) }}>Zurück</button>
|
||||
</div>
|
||||
</div>
|
||||
) : createKind === 'recipe' ? (
|
||||
<RecipeForm
|
||||
defaultName={manual.name_de || q || initialQuery || ''}
|
||||
learned={learned}
|
||||
disabled={creating}
|
||||
submitLabel="Rezept anlegen und zuordnen"
|
||||
onCancel={() => setCreateKind(null)}
|
||||
onSave={onCreateRecipe}
|
||||
/>
|
||||
) : (
|
||||
<div>
|
||||
<p style={{ fontSize: 13, fontWeight: 600, marginBottom: 8 }}>Eigener Eintrag</p>
|
||||
@@ -253,7 +243,7 @@ export default function FoodSearchModal({ title, initialQuery, quantityHint, all
|
||||
setServingG={setServingG}
|
||||
/>
|
||||
<div style={{ display: 'flex', gap: 8, marginTop: 10 }}>
|
||||
{allowRecipe && onCreateRecipe && (
|
||||
{allowRecipe && onWantRecipe && (
|
||||
<button type="button" className="btn btn-secondary" disabled={creating} onClick={() => setCreateKind(null)}>Zurück</button>
|
||||
)}
|
||||
<button
|
||||
|
||||
@@ -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 && (
|
||||
|
||||
@@ -279,6 +279,7 @@ export const api = {
|
||||
putNutritionDayMark: (date, d) => req(`/nutrition/days/${date}/mark`, jput(d)),
|
||||
deleteNutritionDayMark: (date) => req(`/nutrition/days/${date}/mark`, {method:'DELETE'}),
|
||||
resolveNutritionConflicts: (decisions) => req('/nutrition/import-conflicts/resolve', json({decisions})),
|
||||
listFoodUnits: () => req('/bls/units'),
|
||||
searchBlsFoods: (q, limit=20, signal) => req(`/bls/foods?q=${encodeURIComponent(q||'')}&limit=${limit}`, signal ? { signal } : {}),
|
||||
suggestFoodsBatch: (names, limit=3) => req('/bls/foods/suggest-batch', json({ names, limit })),
|
||||
createUserFood: (d) => req('/bls/foods/manual', json(d)),
|
||||
|
||||
Reference in new issue
Block a user