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()