feat: Zuordnen ohne Freeze und zuerst die letzten Wochen
Deploy Development / deploy (push) Successful in 1m6s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 29s

Katalogsuche und Bestätigen blockieren die UI nicht mehr; offene Namen starten bei den aktuellen Tagebucheinträgen, alter Ballast bleibt unter Alle.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-09-12 16:14:24 +02:00
1 parent c1873a47b1
commit 132a364a3a
17 files changed
+745 -163

No files matched your search

+21 -3
View File
@@ -41,6 +41,8 @@ export default function FoodSearchModal({ title, initialQuery, quantityHint, onS
)
const inputRef = useRef(null)
const timer = useRef(null)
const abortRef = useRef(null)
const seqRef = useRef(0)
const extras = () => {
const g = parseFloat(String(gramsPerUnit).replace(',', '.'))
@@ -50,19 +52,28 @@ export default function FoodSearchModal({ title, initialQuery, quantityHint, onS
const runSearch = async (term) => {
const query = (term || '').trim()
abortRef.current?.abort()
if (query.length < 2) {
setHits([])
setLoading(false)
return
}
const seq = ++seqRef.current
const ac = new AbortController()
abortRef.current = ac
setLoading(true)
setError(null)
try {
setHits(await api.searchBlsFoods(query, 30))
const next = await api.searchBlsFoods(query, 20, ac.signal)
if (seq !== seqRef.current) return
setHits(next)
} catch (e) {
if (e.name === 'AbortError') return
if (seq !== seqRef.current) return
setError(e.message)
setHits([])
} finally {
setLoading(false)
if (seq === seqRef.current) setLoading(false)
}
}
@@ -75,13 +86,20 @@ export default function FoodSearchModal({ title, initialQuery, quantityHint, onS
return () => {
window.removeEventListener('keydown', onKey)
clearTimeout(timer.current)
abortRef.current?.abort()
}
}, [])
const onChange = (value) => {
setQ(value)
clearTimeout(timer.current)
timer.current = setTimeout(() => runSearch(value), 250)
if (value.trim().length < 2) {
abortRef.current?.abort()
setHits([])
setLoading(false)
return
}
timer.current = setTimeout(() => runSearch(value), 400)
}
const createManual = async () => {