diff --git a/frontend/src/routes/documents/[id]/+page.svelte b/frontend/src/routes/documents/[id]/+page.svelte index 498e8601..dbcddf78 100644 --- a/frontend/src/routes/documents/[id]/+page.svelte +++ b/frontend/src/routes/documents/[id]/+page.svelte @@ -6,6 +6,7 @@ import DocumentViewer from '$lib/components/DocumentViewer.svelte'; import TranscriptionEditView from '$lib/components/TranscriptionEditView.svelte'; import TranscriptionReadView from '$lib/components/TranscriptionReadView.svelte'; import TranscriptionPanelHeader from '$lib/components/TranscriptionPanelHeader.svelte'; +import OcrProgress from '$lib/components/OcrProgress.svelte'; import type { TranscriptionBlockData } from '$lib/types'; let { data } = $props(); @@ -57,6 +58,7 @@ let activeAnnotationId = $state(null); let highlightBlockId = $state(null); let flashAnnotationId = $state(null); let pdfStripExpanded = $state(false); +let ocrJobId = $state(null); const prefersReducedMotion = $derived( typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches @@ -135,14 +137,21 @@ async function triggerOcr(scriptType: string) { body: JSON.stringify({ scriptType }) }); if (res.ok) { - await loadTranscriptionBlocks(); - annotationReloadKey++; + const data = await res.json(); + ocrJobId = data.jobId; } } catch (e) { console.error('Failed to trigger OCR:', e); } } +async function handleOcrDone() { + ocrJobId = null; + await loadTranscriptionBlocks(); + annotationReloadKey++; + panelMode = transcriptionBlocks.length > 0 ? 'read' : 'edit'; +} + async function createBlockFromDraw(rect: { x: number; y: number; @@ -223,12 +232,28 @@ function handleParagraphClick(annotationId: string) { ); } -// Load blocks when transcribe mode is entered and set default panel mode +async function checkOcrStatus() { + if (!doc?.id) return; + try { + const res = await fetch(`/api/documents/${doc.id}/ocr-status`); + if (res.ok) { + const status = await res.json(); + if (status.status === 'PENDING' || status.status === 'RUNNING') { + ocrJobId = status.jobId; + } + } + } catch { + // OCR status check is best-effort + } +} + +// Load blocks and check OCR status when transcribe mode is entered $effect(() => { if (transcribeMode) { loadTranscriptionBlocks().then(() => { panelMode = transcriptionBlocks.length > 0 ? 'read' : 'edit'; }); + checkOcrStatus(); } }); @@ -328,7 +353,11 @@ onMount(() => { onClose={() => (transcribeMode = false)} />
- {#if panelMode === 'read'} + {#if ocrJobId} +
+ +
+ {:else if panelMode === 'read'}