export const processNodeChanges = (changes: any, mainGroups: any) => { let newData; changes.forEach((change: any) => { if (change.type === 'position' && change.position) { const nodeId = change.id; if (nodeId === 'g0') { newData = { container_id: mainGroups[0].id, container_x: change.position.x, container_y: change.position.y, isOpen: true }; } else if (nodeId === 'g1') { newData = { container_id: mainGroups[1].id, container_x: change.position.x, container_y: change.position.y, isOpen: true }; } } }); return newData; }; const getLastChanges = (changes: any[]) => { const latestChanges: { [key: number]: any } = {}; changes.forEach((change) => { latestChanges[change.container_id] = change; }); return Object.values(latestChanges); }; export const autosavePosition = (changeArray: any[], socket: any,) => { if (changeArray.length > 0) { const lastChanges = getLastChanges(changeArray); lastChanges.forEach((change) => { if (socket && socket.readyState === WebSocket.OPEN && change) { socket.send(JSON.stringify(change)) console.log('JSON отправлен:', JSON.stringify(change)); console.log('Отправленные данные:', change); } else { console.log('WebSocket не открыт или нет данных для отправки'); } }); } } export const resetPosition = (socket: any, setNullPos: (value: boolean) => void, nodes: any[], setNodes: (nodes: any[]) => void) => { const nullPositions = [ { container_id: 1, container_x: 0, container_y: 0, isOpen: true }, { container_id: 2, container_x: 500, container_y: 0, isOpen: true }, ] nullPositions.forEach(pos => { if (socket && socket.readyState === WebSocket.OPEN) { socket.send(JSON.stringify(pos)) console.log('JSON отправлен:', JSON.stringify(pos)) console.log('Отправленные данные:', pos) } else { console.log('WebSocket не открыт или нет данных для отправки') } }) const updatedNodes = nodes.map(node => { if(node.id=="g0"){ return { ...node, position: { x: 0, y: 0 }, positionAbsolute: { x: 0, y: 0 } }; } if(node.id=="g1"){ return { ...node, position: { x: 500, y: 0 }, positionAbsolute: { x: 500, y: 0 } }; } return node; }); setNodes(updatedNodes); setNullPos(false); }