fix: Offene Lebensmittel nach Listen-Import wieder anzeigen
Deploy Development / deploy (push) Successful in 1m1s
Build Test / pytest-backend (push) Failing after 2s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 27s

Unmapped ohne Kreuzjoin, Listen-GET kurz, Rebuild im Hintergrund.
Tandoor-Zugang (URL/Token) in den Einstellungen mit ausliefern.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-09-13 10:36:08 +02:00
1 parent fa542e0fb9
commit d6838abda7
23 files changed
+786 -114

No files matched your search

+11 -4
View File
@@ -13,10 +13,17 @@ export default function FoodRecipeEditor({ recipes, learned, onChanged }) {
setOpen(true)
}
const startEdit = (r) => {
setEditing(r)
const startEdit = async (r) => {
setError(null)
setOpen(true)
try {
const full = (r.ingredients && r.ingredients.length) || r.ingredient_count === 0
? r
: await api.getNutritionRecipe(r.id)
setEditing(full)
setOpen(true)
} catch (e) {
setError(e.message)
}
}
const save = async (body) => {
@@ -53,7 +60,7 @@ export default function FoodRecipeEditor({ recipes, learned, onChanged }) {
<div key={r.id} style={{ borderTop: '1px solid var(--border)', padding: '8px 0', marginTop: 8 }}>
<div style={{ fontWeight: 600 }}>{r.name_raw}</div>
<div style={{ fontSize: 12, color: 'var(--text3)' }}>
{(r.ingredients || []).length} Zutaten · {r.portions || 1} Portionen
{r.ingredient_count ?? (r.ingredients || []).length} Zutaten · {r.portions || 1} Portionen
{r.source === 'manual' ? ' · selbst angelegt' : ''}
</div>
<div style={{ display: 'flex', gap: 8, marginTop: 6 }}>
+9 -8
View File
@@ -65,7 +65,7 @@ function RecipePickModal({ recipes, sourceName, onPick, onClose }) {
<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>
<strong style={{ display: 'block' }}>{r.name_raw}</strong>
<span style={{ fontSize: 12, color: 'var(--text3)' }}>{(r.ingredients || []).length} Zutaten</span>
<span style={{ fontSize: 12, color: 'var(--text3)' }}>{r.ingredient_count ?? (r.ingredients || []).length} Zutaten</span>
</span>
</button>
))}
@@ -149,16 +149,16 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
const load = async () => {
const gen = ++loadGen.current
try {
const [u, m, r, counts] = await Promise.all([
api.listUnmappedFoods(sinceDays),
const [u, m, r] = await Promise.all([
api.listUnmappedFoods(sinceDays, true),
api.listMyFoodMappings(),
api.listNutritionRecipes().catch(() => []),
api.listUnmappedFoodCount(sinceDays).catch(() => null),
api.listNutritionRecipes(true).catch(() => []),
])
if (gen !== loadGen.current) return
askedSuggest.current = new Set()
setUnmapped(Array.isArray(u) ? u : [])
setTotalOpen(Number(counts?.total) || (Array.isArray(u) ? u.length : 0))
const items = Array.isArray(u) ? u : (u?.items || [])
setUnmapped(items)
setTotalOpen(Number(u?.total) || items.length)
setLearned(m)
setRecipes(Array.isArray(r) ? r : [])
} catch (e) {
@@ -340,7 +340,8 @@ export default function NutritionFoodMap({ onChanged, onMapped }) {
const res = await api.importFddbLists(file)
await load()
onChanged?.()
setNotice(`${res.recipes} Listen importiert, ${res.items_linked || 0} Tagebuchzeilen verknüpft.`)
const pending = res.rebuild_pending ? ' Tageswerte werden im Hintergrund nachgerechnet.' : ''
setNotice(`${res.recipes} Listen importiert, ${res.items_linked || 0} Tagebuchzeilen verknüpft.${pending}`)
} catch (e) {
setError(e.message)
} finally {
+140
View File
@@ -0,0 +1,140 @@
import { useEffect, useState } from 'react'
import { api } from '../utils/api'
export default function TandoorSettings() {
const [baseUrl, setBaseUrl] = useState('')
const [token, setToken] = useState('')
const [tokenSet, setTokenSet] = useState(false)
const [tokenHint, setTokenHint] = useState(null)
const [lastOk, setLastOk] = useState(null)
const [lastError, setLastError] = useState(null)
const [busy, setBusy] = useState(false)
const [msg, setMsg] = useState(null)
const load = async () => {
const s = await api.getTandoorSettings()
setBaseUrl(s.base_url || '')
setTokenSet(Boolean(s.token_set))
setTokenHint(s.token_hint || null)
setLastOk(s.last_ok_at || null)
setLastError(s.last_error || null)
setToken('')
}
useEffect(() => {
load().catch((e) => setMsg({ type: 'err', text: e.message }))
}, [])
const save = async () => {
setBusy(true)
setMsg(null)
try {
const s = await api.putTandoorSettings({
base_url: baseUrl,
token: token.trim() || undefined,
})
setToken('')
setTokenSet(Boolean(s.token_set))
setTokenHint(s.token_hint || null)
setLastError(s.last_error || null)
setMsg({ type: 'ok', text: 'Gespeichert. Das Token bleibt nur auf dem Server.' })
} catch (e) {
setMsg({ type: 'err', text: e.message })
} finally {
setBusy(false)
}
}
const test = async () => {
setBusy(true)
setMsg(null)
try {
const res = await api.testTandoorConnection({
base_url: baseUrl || undefined,
token: token.trim() || undefined,
})
const who = res.user ? ` als ${res.user}` : ''
setMsg({ type: 'ok', text: `Verbindung ok${who}.` })
setLastError(null)
setLastOk(new Date().toISOString())
} catch (e) {
setMsg({ type: 'err', text: e.message })
} finally {
setBusy(false)
}
}
const clear = async () => {
if (!confirm('Tandoor-Zugang wirklich entfernen?')) return
setBusy(true)
setMsg(null)
try {
await api.putTandoorSettings({ base_url: '', clear_token: true })
setBaseUrl('')
setToken('')
setTokenSet(false)
setTokenHint(null)
setLastOk(null)
setLastError(null)
setMsg({ type: 'ok', text: 'Zugang entfernt.' })
} catch (e) {
setMsg({ type: 'err', text: e.message })
} finally {
setBusy(false)
}
}
return (
<div className="card section-gap">
<div className="card-title">Tandoor (Familienrezepte)</div>
<p style={{ fontSize: 13, color: 'var(--text2)', marginBottom: 14, lineHeight: 1.6 }}>
Persönlicher Zugang zu eurem Tandoor — nicht systemweit. Gerichte bleiben dort; Mitai rechnet später Nährwerte.
Token unter Tandoor → Einstellungen → API-Tokens anlegen.
</p>
<div className="settings-page__field">
<label className="settings-page__field-label" htmlFor="tandoor-url">Adresse</label>
<input
id="tandoor-url"
className="form-input"
type="url"
placeholder="https://tandoor.stommer.de"
value={baseUrl}
onChange={(e) => setBaseUrl(e.target.value)}
autoComplete="off"
/>
</div>
<div className="settings-page__field">
<label className="settings-page__field-label" htmlFor="tandoor-token">API-Token</label>
<input
id="tandoor-token"
className="form-input"
type="password"
placeholder={tokenSet ? `Gespeichert (${tokenHint || '…'}) — leer lassen zum Behalten` : 'Token einfügen'}
value={token}
onChange={(e) => setToken(e.target.value)}
autoComplete="new-password"
/>
</div>
{lastOk && (
<p style={{ fontSize: 12, color: 'var(--accent-dark)', margin: '0 0 8px' }}>
Zuletzt erfolgreich: {String(lastOk).slice(0, 16).replace('T', ' ')}
</p>
)}
{lastError && !msg && (
<p style={{ fontSize: 12, color: 'var(--danger)', margin: '0 0 8px' }}>Letzter Fehler: {lastError}</p>
)}
{msg && (
<div style={{ fontSize: 13, color: msg.type === 'err' ? 'var(--danger)' : 'var(--accent-dark)', marginBottom: 10 }}>
{msg.text}
</div>
)}
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
<button type="button" className="btn btn-primary" disabled={busy} onClick={save}>Speichern</button>
<button type="button" className="btn btn-secondary" disabled={busy} onClick={test}>Verbindung testen</button>
{tokenSet && (
<button type="button" className="btn btn-secondary" disabled={busy} onClick={clear}>Zugang entfernen</button>
)}
</div>
</div>
)
}
+3
View File
@@ -6,6 +6,7 @@ import { useAuth } from '../context/AuthContext'
import { Avatar } from './ProfileSelect'
import { api } from '../utils/api'
import FeatureUsageOverview from '../components/FeatureUsageOverview'
import TandoorSettings from '../components/TandoorSettings'
import UsageBadge from '../components/UsageBadge'
const COLORS = ['#1D9E75','#378ADD','#D85A30','#EF9F27','#7F77DD','#D4537E','#639922','#888780']
@@ -428,6 +429,8 @@ export default function SettingsPage() {
</button>
</div>
<TandoorSettings />
<div className="card section-gap">
<div className="card-title" style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<LayoutDashboard size={15} color="var(--accent)" /> Startseite (Übersicht)
+6 -2
View File
@@ -108,6 +108,9 @@ export const api = {
deleteProfile: (id) => req(`/profiles/${id}`, {method:'DELETE'}),
getProfile: () => req('/profile'),
updateActiveProfile:(d)=> req('/profile', jput(d)),
getTandoorSettings: () => req('/tandoor/settings'),
putTandoorSettings: (d) => req('/tandoor/settings', jput(d)),
testTandoorConnection: (d) => req('/tandoor/test', json(d || {})),
// App-Bereich: konfigurierbares Dashboard (Layout JSON) + Widget-Katalog
getAppWidgetsCatalog: () => req('/app/widgets/catalog'),
@@ -240,9 +243,10 @@ export const api = {
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
},
listNutritionItems: (date) => req(date ? `/nutrition/items?date=${date}` : '/nutrition/items'),
listUnmappedFoods: (sinceDays=0) => req(`/nutrition/unmapped?since_days=${sinceDays || 0}`),
listUnmappedFoods: (sinceDays=0, meta=false) => req(`/nutrition/unmapped?since_days=${sinceDays || 0}${meta ? '&meta=true' : ''}`),
listUnmappedFoodCount: (sinceDays=28) => req(`/nutrition/unmapped?count_only=true&since_days=${sinceDays || 0}`),
listNutritionRecipes: () => req('/nutrition/recipes'),
listNutritionRecipes: (brief=false) => req(`/nutrition/recipes${brief ? '?brief=true' : ''}`),
getNutritionRecipe: (id) => req(`/nutrition/recipes/${id}`),
createNutritionRecipe: (d) => req('/nutrition/recipes', json(d)),
updateNutritionRecipe: (id, d) => req(`/nutrition/recipes/${id}`, jput(d)),
deleteNutritionRecipe: (id) => req(`/nutrition/recipes/${id}`, {method:'DELETE'}),