fix(ticket): stabilize detection preview index during loading

This commit is contained in:
2026-07-29 18:58:24 +05:30
parent e8f2955acf
commit 31839d1c70

View File

@@ -121,6 +121,7 @@ export function TicketClassDetectionPreview({
); );
const detectionResult = detectionsQuery.data; const detectionResult = detectionsQuery.data;
const activeDetection = detectionResult?.items[0]; const activeDetection = detectionResult?.items[0];
const confirmedDetectionCount = detectionResult?.total;
const detectionCount = const detectionCount =
detectionResult?.total ?? (assignmentId ? 0 : (totalCount ?? 0)); detectionResult?.total ?? (assignmentId ? 0 : (totalCount ?? 0));
const activeVisual = getDefectVisual( const activeVisual = getDefectVisual(
@@ -136,15 +137,20 @@ export function TicketClassDetectionPreview({
); );
useEffect(() => { useEffect(() => {
if (detectionCount === 0 && currentIndex !== 0) { if (confirmedDetectionCount === undefined) return;
if (confirmedDetectionCount === 0 && currentIndex !== 0) {
setCurrentIndex(0); setCurrentIndex(0);
return; return;
} }
if (detectionCount > 0 && currentIndex > detectionCount - 1) { if (
setCurrentIndex(detectionCount - 1); confirmedDetectionCount > 0 &&
currentIndex > confirmedDetectionCount - 1
) {
setCurrentIndex(confirmedDetectionCount - 1);
} }
}, [currentIndex, detectionCount]); }, [confirmedDetectionCount, currentIndex]);
const isNavigationDisabled = const isNavigationDisabled =
detectionCount === 0 || detectionsQuery.isLoading; detectionCount === 0 || detectionsQuery.isLoading;