From d530738b127b7f79bebd800afb7e4e5263c9cc6c Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Tue, 10 Mar 2026 11:35:59 +0100 Subject: [PATCH] fix: useMemo vor early returns verschieben (React Hooks Regel) Co-Authored-By: Claude Opus 4.6 --- .../components/ocr-pipeline/StepLlmReview.tsx | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx b/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx index 6b370c1..62bac4f 100644 --- a/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx +++ b/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx @@ -347,6 +347,28 @@ export function StepLlmReview({ sessionId, onNext }: StepLlmReviewProps) { ? `${KLAUSUR_API}/api/v1/ocr-pipeline/sessions/${sessionId}/image/cropped` : '' + // Snap all cells in the same column to consistent x/w positions + // Uses the median x and width per col_index so columns align vertically + const colPositions = useMemo(() => { + const byCol = new Map() + for (const cell of cells) { + if (!cell.bbox_pct) continue + const entry = byCol.get(cell.col_index) || { xs: [], ws: [] } + entry.xs.push(cell.bbox_pct.x) + entry.ws.push(cell.bbox_pct.w) + byCol.set(cell.col_index, entry) + } + const result = new Map() + for (const [colIdx, { xs, ws }] of byCol) { + xs.sort((a, b) => a - b) + ws.sort((a, b) => a - b) + const medianX = xs[Math.floor(xs.length / 2)] + const medianW = ws[Math.floor(ws.length / 2)] + result.set(colIdx, { x: medianX, w: medianW }) + } + return result + }, [cells]) + if (!sessionId) { return
Bitte zuerst eine Session auswaehlen.
} @@ -402,28 +424,6 @@ export function StepLlmReview({ sessionId, onNext }: StepLlmReviewProps) { // Active entry for highlighting on image const activeEntry = vocabEntries.find((_: WordEntry, i: number) => activeRowIndices.has(i)) - // Snap all cells in the same column to consistent x/w positions - // Uses the median x and max width per col_index so columns align vertically - const colPositions = useMemo(() => { - const byCol = new Map() - for (const cell of cells) { - if (!cell.bbox_pct) continue - const entry = byCol.get(cell.col_index) || { xs: [], ws: [] } - entry.xs.push(cell.bbox_pct.x) - entry.ws.push(cell.bbox_pct.w) - byCol.set(cell.col_index, entry) - } - const result = new Map() - for (const [colIdx, { xs, ws }] of byCol) { - xs.sort((a, b) => a - b) - ws.sort((a, b) => a - b) - const medianX = xs[Math.floor(xs.length / 2)] - const medianW = ws[Math.floor(ws.length / 2)] - result.set(colIdx, { x: medianX, w: medianW }) - } - return result - }, [cells]) - const pct = progress ? Math.round((progress.current / progress.total) * 100) : 0 /** Handle inline edit of a cell in the overlay */