source: imaps-frontend/src/components/Modals/Hooks/useConnections.jsx@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import {useState} from "react";
2
3export default function useConnections(map,shapeInfo,setShapeInfo){
4 const [connections,setConnections] = useState([])
5
6 const addConnection = () => {
7 if (!shapeInfo.selectedPin || connections.includes(shapeInfo.selectedPin)) return;
8
9 setConnections((prevConn) => {
10 const updatedConnections = [...prevConn, shapeInfo.selectedPin];
11
12
13 setShapeInfo((prevShapeInfo) => ({
14 ...prevShapeInfo,
15 ["selectedPin"]: "",
16 ["selectedPins"]: updatedConnections,
17 }));
18
19 console.log(shapeInfo.name,shapeInfo.selectedPin,"TEST")
20
21 map.drawConnection(shapeInfo.name,shapeInfo.selectedPin);
22 return updatedConnections;
23 });
24 };
25
26 const removeConnection = (connToRemove) => {
27 setConnections((prevConn) => {
28 const updatedPins = prevConn.filter((pin) => pin !== connToRemove);
29 setShapeInfo((prevFormData) => ({
30 ...prevFormData,
31 selectedPins: updatedPins,
32 }));
33 return updatedPins;
34 });
35 map.removeConnection(shapeInfo.name, connToRemove);
36 };
37
38
39 return {
40 connectionState: {connections,setConnections},
41 handlers: {addConnection,removeConnection}
42
43 }
44}
Note: See TracBrowser for help on using the repository browser.