From 1e9a1aebd23fc3da35fa18fa9a8089a65ff11dfe Mon Sep 17 00:00:00 2001 From: "Carter J. Bastian" Date: Tue, 7 Mar 2017 16:31:42 -0500 Subject: [PATCH] Add infrastructure for updating connections in state --- app/components/Diagram.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/components/Diagram.js b/app/components/Diagram.js index 4850f78..ed9738a 100644 --- a/app/components/Diagram.js +++ b/app/components/Diagram.js @@ -31,6 +31,39 @@ export default class Diagram extends Component { this.handleClick = this.handleClick.bind(this); }; + createConnection(component, e) { + // If not currently connection, start connecting + if (this.state.setConnectionPoint == null || + !this.state.isConnection) { + this.setState({ + circles: this.state.circles, + squares: this.state.squares, + setConnectionPoint: component.props.id, // The connection point last clicked + isConnecting: true, // The currently connection point + connectionPoints: this.state.connectionPoints, + connections: this.state.connections, + }); + } else { // End the connection by adding a connection point + // Get the current list of connections and add it to the state + let updatedConnections = this.state.connections.slice(); + + updatedConnections.push({ + start: this.state.setConnectionPoint, + end: component.props.id, + }); + + this.setState({ + circles: this.state.circles, + squares: this.state.squares, + setConnectionPoint: null, // The connection point last clicked + isConnecting: false, // The currently connection point + connectionPoints: this.state.connectionPoints, + connections: updatedConnections, + }); + + } + }; + handleClick(e) { // On a click, add a block to the diagram on the click location e.preventDefault();