From 31839d1c70e9e42814fc4f8874361453f8a1b41d Mon Sep 17 00:00:00 2001 From: "santasri.pachhal" Date: Wed, 29 Jul 2026 18:58:24 +0530 Subject: [PATCH] fix(ticket): stabilize detection preview index during loading --- .../components/TicketClassDetectionPreview.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/(modules)/ticket/[ticketId]/components/TicketClassDetectionPreview.tsx b/src/app/(modules)/ticket/[ticketId]/components/TicketClassDetectionPreview.tsx index 7cbc004..79d09fd 100644 --- a/src/app/(modules)/ticket/[ticketId]/components/TicketClassDetectionPreview.tsx +++ b/src/app/(modules)/ticket/[ticketId]/components/TicketClassDetectionPreview.tsx @@ -121,6 +121,7 @@ export function TicketClassDetectionPreview({ ); const detectionResult = detectionsQuery.data; const activeDetection = detectionResult?.items[0]; + const confirmedDetectionCount = detectionResult?.total; const detectionCount = detectionResult?.total ?? (assignmentId ? 0 : (totalCount ?? 0)); const activeVisual = getDefectVisual( @@ -136,15 +137,20 @@ export function TicketClassDetectionPreview({ ); useEffect(() => { - if (detectionCount === 0 && currentIndex !== 0) { + if (confirmedDetectionCount === undefined) return; + + if (confirmedDetectionCount === 0 && currentIndex !== 0) { setCurrentIndex(0); return; } - if (detectionCount > 0 && currentIndex > detectionCount - 1) { - setCurrentIndex(detectionCount - 1); + if ( + confirmedDetectionCount > 0 && + currentIndex > confirmedDetectionCount - 1 + ) { + setCurrentIndex(confirmedDetectionCount - 1); } - }, [currentIndex, detectionCount]); + }, [confirmedDetectionCount, currentIndex]); const isNavigationDisabled = detectionCount === 0 || detectionsQuery.isLoading;