Fix page-split: fetch sub-sessions from API instead of React state
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 37s
CI / test-go-edu-search (push) Successful in 27s
CI / test-python-klausur (push) Failing after 2m1s
CI / test-python-agent-core (push) Successful in 15s
CI / test-nodejs-website (push) Successful in 17s

handleOrientationComplete was checking subSessions from React state,
but due to batching the state was still empty when the user clicked
"Seiten verarbeiten". Now fetches session data directly from the API
to reliably detect sub-sessions and auto-open the first one.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-24 11:22:15 +01:00
parent 247b79674d
commit 14fd8e0b1e

View File

@@ -250,15 +250,31 @@ export default function OcrPipelinePage() {
setCurrentStep(nextStep)
}
const handleOrientationComplete = (sid: string) => {
const handleOrientationComplete = async (sid: string) => {
setSessionId(sid)
// Reload session list to show the new session
loadSessions()
// If page-split created sub-sessions, open the first one
if (subSessions.length > 0) {
openSession(subSessions[0].id, true)
return
// Check for page-split sub-sessions directly from API
// (React state may not be committed yet due to batching)
try {
const res = await fetch(`${KLAUSUR_API}/api/v1/ocr-pipeline/sessions/${sid}`)
if (res.ok) {
const data = await res.json()
if (data.sub_sessions?.length > 0) {
const subs: SubSession[] = data.sub_sessions.map((s: SubSession) => ({
id: s.id,
name: s.name,
box_index: s.box_index,
current_step: s.current_step,
}))
setSubSessions(subs)
setParentSessionId(sid)
openSession(subs[0].id, true)
return
}
}
} catch (e) {
console.error('Failed to check for sub-sessions:', e)
}
handleNext()