fix: resolve ReferenceError in DimensionsView by moving useEffect after variable declaration

This commit is contained in:
Christian Vidal Wolf
2026-04-16 12:03:39 +02:00
parent cbfd5f573d
commit f358b61229
+37 -36
View File
@@ -66,42 +66,6 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat
const hoveredIndexRef = React.useRef<number | null>(null);
const activeClusterKeyRef = React.useRef<string | null>(null);
React.useEffect(() => {
const handleGlobalMouseUp = () => {
if (isDraggingRef.current && activeClusterKeyRef.current) {
const clusterKey = activeClusterKeyRef.current;
const start = dragStartRef.current;
const end = hoveredIndexRef.current;
if (start !== null && end !== null) {
const cluster = nearDuplicateClusters.find(c => c.groups[0].key === clusterKey);
if (cluster) {
const allClusterRows = cluster.groups.flatMap(g => g.rows);
const s = Math.min(start, end);
const e = Math.max(start, end);
const indicesToSelect = allClusterRows.slice(s, e + 1).map(r => r.index);
setClusterSelections(prev => {
const next = new Set(prev[clusterKey] ?? []);
indicesToSelect.forEach(idx => next.add(idx));
return { ...prev, [clusterKey]: next };
});
}
}
}
isDraggingRef.current = false;
dragStartRef.current = null;
hoveredIndexRef.current = null;
activeClusterKeyRef.current = null;
setIsDragging(false);
setDragStart(null);
setHoveredIndex(null);
setActiveClusterKey(null);
};
window.addEventListener('mouseup', handleGlobalMouseUp);
return () => window.removeEventListener('mouseup', handleGlobalMouseUp);
}, [nearDuplicateClusters]);
const groups = useMemo(() => {
const groupMap = new Map<string, { row: ExcelRow; index: number }[]>();
@@ -252,6 +216,43 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat
return clusters;
}, [groups]);
React.useEffect(() => {
const handleGlobalMouseUp = () => {
if (isDraggingRef.current && activeClusterKeyRef.current) {
const clusterKey = activeClusterKeyRef.current;
const start = dragStartRef.current;
const end = hoveredIndexRef.current;
if (start !== null && end !== null) {
const cluster = nearDuplicateClusters.find(c => c.groups[0].key === clusterKey);
if (cluster) {
const allClusterRows = cluster.groups.flatMap(g => g.rows);
const s = Math.min(start, end);
const e = Math.max(start, end);
const indicesToSelect = allClusterRows.slice(s, e + 1).map(r => r.index);
setClusterSelections(prev => {
const next = new Set(prev[clusterKey] ?? []);
indicesToSelect.forEach(idx => next.add(idx));
return { ...prev, [clusterKey]: next };
});
}
}
}
isDraggingRef.current = false;
dragStartRef.current = null;
hoveredIndexRef.current = null;
activeClusterKeyRef.current = null;
setIsDragging(false);
setDragStart(null);
setHoveredIndex(null);
setActiveClusterKey(null);
};
window.addEventListener('mouseup', handleGlobalMouseUp);
return () => window.removeEventListener('mouseup', handleGlobalMouseUp);
}, [nearDuplicateClusters]);
const toggleGroup = (key: string) => {
const next = new Set(expandedGroups);
if (next.has(key)) {