From 14fd8e0b1ee24c9985ba1023f3664dcdaf48ea21 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Tue, 24 Mar 2026 11:22:15 +0100 Subject: [PATCH] Fix page-split: fetch sub-sessions from API instead of React state 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 --- .../app/(admin)/ai/ocr-pipeline/page.tsx | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/admin-lehrer/app/(admin)/ai/ocr-pipeline/page.tsx b/admin-lehrer/app/(admin)/ai/ocr-pipeline/page.tsx index b02f409..6fb4489 100644 --- a/admin-lehrer/app/(admin)/ai/ocr-pipeline/page.tsx +++ b/admin-lehrer/app/(admin)/ai/ocr-pipeline/page.tsx @@ -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()