feat: Eigene und zentrale Lebensmittel bearbeiten, mit Sichtbarkeit im Mapping
Nutzer können persönliche Foods anlegen und ändern; der Admin legt zentrale Einträge für alle an. Suche und Namens-Mapping berücksichtigen persönlich, zentral und BLS. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d35087ad84
commit
8b1e1da5d8
30 files changed
+1195
-120
No files matched your search
@@ -3,6 +3,8 @@ import { api } from '../utils/api'
|
||||
import FoodSearchModal from './FoodSearchModal'
|
||||
import FoodNutrientFields, { foodCreatePayload } from './FoodNutrientFields'
|
||||
import FoodRecipeDialog from './FoodRecipeDialog'
|
||||
import FoodEditDialog from './FoodEditDialog'
|
||||
import { foodVisibilitySuffix } from '../utils/foodVisibility'
|
||||
|
||||
const PERIODS = [
|
||||
{ days: 14, label: '14 Tage' },
|
||||
@@ -127,7 +129,7 @@ function InlineCreate({ defaultName, disabled, allowRecipe, onCreateFood, onWant
|
||||
)
|
||||
}
|
||||
|
||||
export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, onCreatedList }) {
|
||||
export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, onCreatedList, onOpenMyFoods }) {
|
||||
const [unmapped, setUnmapped] = useState([])
|
||||
const [learned, setLearned] = useState([])
|
||||
const [recipes, setRecipes] = useState([])
|
||||
@@ -144,6 +146,7 @@ export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, o
|
||||
const [q, setQ] = useState('')
|
||||
const [visible, setVisible] = useState(80)
|
||||
const [showLearned, setShowLearned] = useState(false)
|
||||
const [editFoodId, setEditFoodId] = useState(null)
|
||||
const [importing, setImporting] = useState(false)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const listRef = useRef(null)
|
||||
@@ -371,6 +374,7 @@ export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, o
|
||||
<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) }} />
|
||||
<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" onClick={() => onOpenMyFoods?.()}>Meine Lebensmittel</button>
|
||||
<button type="button" className="btn btn-secondary" disabled={importing} onClick={() => listRef.current?.click()}>
|
||||
{importing ? 'Importiere Listen…' : 'FDDB-Listen importieren'}
|
||||
</button>
|
||||
@@ -448,7 +452,9 @@ export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, o
|
||||
<div style={{ marginTop: 8, display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center' }}>
|
||||
<span style={{ fontSize: 13 }}>
|
||||
→ <strong>{best.name_de}</strong>
|
||||
<span style={{ color: 'var(--text3)' }}>{best.bls_code ? ` · ${best.bls_code}` : ' · manuell'}</span>
|
||||
<span style={{ color: 'var(--text3)' }}>
|
||||
{best.bls_code ? ` · ${best.bls_code}` : foodVisibilitySuffix(best.catalog_kind, best.visibility)}
|
||||
</span>
|
||||
</span>
|
||||
<button type="button" className="btn btn-primary" disabled={busyRow} onClick={() => assign(u, best.id, {}, best)}>
|
||||
Bestätigen
|
||||
@@ -457,7 +463,7 @@ export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, o
|
||||
)}
|
||||
{suggestions.slice(1).map((s) => (
|
||||
<div key={s.id} style={{ marginTop: 6, display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center' }}>
|
||||
<span style={{ fontSize: 12, color: 'var(--text2)' }}>oder {s.name_de}{s.bls_code ? ` · ${s.bls_code}` : ''}</span>
|
||||
<span style={{ fontSize: 12, color: 'var(--text2)' }}>oder {s.name_de}{s.bls_code ? ` · ${s.bls_code}` : foodVisibilitySuffix(s.catalog_kind, s.visibility)}</span>
|
||||
<button type="button" className="btn btn-secondary" disabled={busyRow} onClick={() => assign(u, s.id, {}, s)}>Übernehmen</button>
|
||||
</div>
|
||||
))}
|
||||
@@ -510,15 +516,20 @@ export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, o
|
||||
</button>
|
||||
</h3>
|
||||
{showLearned && learned.map((m) => (
|
||||
<div key={m.id} style={{ display: 'flex', justifyContent: 'space-between', gap: 8, padding: '8px 0', borderTop: '1px solid var(--border)' }}>
|
||||
<div key={m.id} style={{ display: 'flex', justifyContent: 'space-between', gap: 8, padding: '8px 0', borderTop: '1px solid var(--border)', alignItems: 'center' }}>
|
||||
<div>
|
||||
<div style={{ fontWeight: 500 }}>{m.source_name_raw}</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)' }}>
|
||||
→ {m.food_name_de}{m.bls_code ? ` · ${m.bls_code}` : ''}
|
||||
{m.catalog_kind !== 'official_bls' ? ' (manuell)' : ''}
|
||||
{foodVisibilitySuffix(m.catalog_kind, m.visibility)}
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => remove(m.id)}>Löschen</button>
|
||||
<div style={{ display: 'flex', gap: 8, flexShrink: 0 }}>
|
||||
{m.catalog_kind === 'manual_user' && m.food_id && (
|
||||
<button type="button" className="btn btn-secondary" onClick={() => setEditFoodId(m.food_id)}>Bearbeiten</button>
|
||||
)}
|
||||
<button type="button" className="btn btn-secondary" onClick={() => remove(m.id)}>Löschen</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -558,6 +569,19 @@ export default function NutritionFoodMap({ onChanged, onMapped, onManageLists, o
|
||||
{recipeFor && (
|
||||
<RecipePickModal recipes={recipes} sourceName={recipeFor.source_name_raw} onClose={() => setRecipeFor(null)} onPick={(id) => applyRecipe(recipeFor.source_name_raw, id)} />
|
||||
)}
|
||||
{editFoodId && (
|
||||
<FoodEditDialog
|
||||
foodId={editFoodId}
|
||||
onClose={() => setEditFoodId(null)}
|
||||
onSaved={(res) => {
|
||||
load()
|
||||
onChanged?.()
|
||||
const n = res?.rebuild_pending
|
||||
if (n) setNotice(`Lebensmittel gespeichert. Tageswerte für ${n} Tag${n === 1 ? '' : 'e'} werden nachgerechnet.`)
|
||||
else setNotice('Lebensmittel gespeichert.')
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user