mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 14:45:24 +02:00
fix: resolve ReferenceError in DimensionsView by moving useEffect after variable declaration
This commit is contained in:
@@ -66,42 +66,6 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat
|
|||||||
const hoveredIndexRef = React.useRef<number | null>(null);
|
const hoveredIndexRef = React.useRef<number | null>(null);
|
||||||
const activeClusterKeyRef = React.useRef<string | 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 groups = useMemo(() => {
|
||||||
const groupMap = new Map<string, { row: ExcelRow; index: number }[]>();
|
const groupMap = new Map<string, { row: ExcelRow; index: number }[]>();
|
||||||
@@ -252,6 +216,43 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat
|
|||||||
return clusters;
|
return clusters;
|
||||||
}, [groups]);
|
}, [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 toggleGroup = (key: string) => {
|
||||||
const next = new Set(expandedGroups);
|
const next = new Set(expandedGroups);
|
||||||
if (next.has(key)) {
|
if (next.has(key)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user