feat: Zuordnen ohne Freeze und zuerst die letzten Wochen
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:
1 parent
c1873a47b1
commit
132a364a3a
17 files changed
+745
-163
No files matched your search
@@ -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 () => {
|
||||
|
||||
Reference in new issue
Block a user