feat: Listen-Tab und sichtbare Zutatenlisten-Verwaltung
Listen anlegen, bearbeiten und importieren liegt unter Ernährung. Tagebuchzeilen werden auch mit Mengen-Prefix verknüpft. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3b46630a37
commit
b37005be01
12 files changed
+307
-73
No files matched your search
@@ -2,7 +2,6 @@ import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
import FoodSearchModal from './FoodSearchModal'
|
||||
import FoodNutrientFields, { foodCreatePayload } from './FoodNutrientFields'
|
||||
import FoodRecipeEditor from './FoodRecipeEditor'
|
||||
import FoodRecipeDialog from './FoodRecipeDialog'
|
||||
|
||||
const PERIODS = [
|
||||
@@ -28,7 +27,8 @@ function suggestQuery(raw) {
|
||||
}
|
||||
|
||||
function RecipePickModal({ recipes, sourceName, onPick, onClose }) {
|
||||
const [q, setQ] = useState(suggestQuery(sourceName))
|
||||
const [q, setQ] = useState('')
|
||||
const hint = suggestQuery(sourceName)
|
||||
const filtered = recipes.filter((r) => {
|
||||
const hay = `${r.name_raw || ''} ${r.name_normalized || ''}`.toLowerCase()
|
||||
return !q.trim() || hay.includes(q.trim().toLowerCase())
|
||||
@@ -53,14 +53,19 @@ 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 }}>Eigene Liste wählen</h2>
|
||||
<h2 className="card-title" style={{ margin: 0, fontSize: 16 }}>Liste verknüpfen</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="Listenname filtern" value={q} onChange={(e) => setQ(e.target.value)} />
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', lineHeight: 1.5, margin: '0 0 10px' }}>
|
||||
Diese Tagebuchzeile{hint ? ` („${hint}“)` : ''} einer bestehenden Zutatenliste zuordnen.
|
||||
Der Eintrag verschwindet danach hier; die Zutaten der Liste ordnest du einzeln zu.
|
||||
</p>
|
||||
<input className="form-input" style={{ width: '100%', textAlign: 'left' }} autoFocus placeholder="Alle Listen durchsuchen…" 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)' }}>Keine passende Liste.</p>}
|
||||
{recipes.length === 0 && <p style={{ fontSize: 13, color: 'var(--text3)' }}>Noch keine Listen. Unter „Listen“ anlegen oder FDDB importieren.</p>}
|
||||
{recipes.length > 0 && filtered.length === 0 && <p style={{ fontSize: 13, color: 'var(--text3)' }}>Keine Liste passt zum Filter.</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>
|
||||
@@ -122,7 +127,7 @@ function InlineCreate({ defaultName, disabled, allowRecipe, onCreateFood, onWant
|
||||
)
|
||||
}
|
||||
|
||||
export default function NutritionFoodMap({ onChanged, onMapped }) {
|
||||
export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, onCreatedList }) {
|
||||
const [unmapped, setUnmapped] = useState([])
|
||||
const [learned, setLearned] = useState([])
|
||||
const [recipes, setRecipes] = useState([])
|
||||
@@ -263,8 +268,10 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
|
||||
await api.applyNutritionRecipe(rec.id, row.source_name_raw)
|
||||
setCreateFor(null)
|
||||
setSearchFor(null)
|
||||
setNotice('Liste angelegt. Offene Zutaten erscheinen unten zum Zuordnen.')
|
||||
await load()
|
||||
setUnmapped((list) => list.filter((x) => x.source_name_normalized !== row.source_name_normalized))
|
||||
setNotice('Liste angelegt und mit der Tagebuchzeile verknüpft. Zutaten erscheinen unter Zuordnen, die Liste unter Listen.')
|
||||
onCreatedList?.(rec)
|
||||
if (!onCreatedList) await load()
|
||||
onMapped?.()
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
@@ -280,7 +287,8 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
|
||||
try {
|
||||
await api.applyNutritionRecipe(recipeId, sourceName)
|
||||
setRecipeFor(null)
|
||||
setNotice('Liste verknüpft. Offene Zutaten erscheinen unten zum Zuordnen.')
|
||||
setUnmapped((list) => list.filter((x) => x.source_name_raw !== sourceName && x.source_name_normalized !== sourceName))
|
||||
setNotice('Liste verknüpft. Offene Zutaten der Liste erscheinen hier zum Zuordnen.')
|
||||
await load()
|
||||
onMapped?.()
|
||||
} catch (e) {
|
||||
@@ -361,10 +369,15 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
|
||||
{notice && <div style={{ fontSize: 13, color: 'var(--accent-dark)', marginBottom: 10 }}>{notice}</div>}
|
||||
|
||||
<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 importieren'}
|
||||
</button>
|
||||
<FoodRecipeEditor recipes={recipes} learned={learned} onChanged={() => { load(); onChanged?.() }} />
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginBottom: 8 }}>
|
||||
<button type="button" className="btn btn-primary" onClick={() => onManageLists?.()}>Listen verwalten</button>
|
||||
<button type="button" className="btn btn-secondary" disabled={importing} onClick={() => listRef.current?.click()}>
|
||||
{importing ? 'Importiere Listen…' : 'FDDB-Listen importieren'}
|
||||
</button>
|
||||
</div>
|
||||
<p style={{ fontSize: 12, color: 'var(--text3)', margin: '0 0 12px' }}>
|
||||
{recipes.length ? `${recipes.length} Listen vorhanden.` : 'Noch keine Listen.'} Anlegen, bearbeiten und FDDB-Import unter Listen.
|
||||
</p>
|
||||
<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) }} />
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 8 }}>
|
||||
<button type="button" className="btn btn-secondary" disabled={busy} onClick={exportBundle}>Zuordnungen & Listen exportieren</button>
|
||||
@@ -414,9 +427,15 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
|
||||
<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' ? 'Listenzutat' : `${u.count}×`}
|
||||
{u.matching_recipe_id ? ` · Liste${u.matching_recipe_name ? `: ${u.matching_recipe_name}` : ''}` : ''}
|
||||
{u.variant_count > 1 ? ` · ${u.variant_count} Mengen` : ''}
|
||||
{u.last_date ? ` · zuletzt ${formatDay(u.last_date)}` : ''}
|
||||
</div>
|
||||
{u.kind !== 'recipe_ingredient' && u.matching_recipe_id && (
|
||||
<div style={{ fontSize: 12, color: 'var(--accent-dark)', marginTop: 4 }}>
|
||||
Entspricht einer Zutatenliste — verknüpfen, dann die Zutaten zuordnen.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{(u.ambiguous || suggestions.length > 1) && (
|
||||
<span style={{ fontSize: 11, padding: '2px 8px', borderRadius: 999, background: 'var(--surface2)', color: 'var(--danger)', whiteSpace: 'nowrap' }}>
|
||||
@@ -450,10 +469,13 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
|
||||
</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 Liste</button>
|
||||
<button type="button" className="btn btn-primary" disabled={busyRow} onClick={() => applyRecipe(u.source_name_raw, u.matching_recipe_id)}>Als Liste verknüpfen</button>
|
||||
)}
|
||||
{u.kind !== 'recipe_ingredient' && recipes.length > 0 && (
|
||||
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => setRecipeFor(u)}>Liste wählen</button>
|
||||
{u.kind !== 'recipe_ingredient' && u.matching_recipe_id && (
|
||||
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => onManageLists?.(u.matching_recipe_id)}>Liste öffnen</button>
|
||||
)}
|
||||
{u.kind !== 'recipe_ingredient' && (
|
||||
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => setRecipeFor(u)}>Andere Liste wählen</button>
|
||||
)}
|
||||
</div>
|
||||
{createFor === key && (
|
||||
|
||||
Reference in new issue
Block a user