|
1 | | -import React, { useState } from "react"; |
| 1 | +import React, { useState, useEffect } from "react"; |
2 | 2 |
|
3 | 3 | // Bootstrap |
4 | 4 | import Container from "react-bootstrap/Container"; |
@@ -54,6 +54,40 @@ const CreateShape = (props) => { |
54 | 54 | ...initialState, |
55 | 55 | }); |
56 | 56 |
|
| 57 | + // Checks if edit is true and will provide different initial values |
| 58 | + useEffect(() => { |
| 59 | + |
| 60 | + if (props.edit) { |
| 61 | + |
| 62 | + let formula = props.shape.formula; |
| 63 | + let slicedFormula = formula.slice(formula.indexOf("(") + 1, formula.indexOf(")")); |
| 64 | + let newVerticeCoordinates = slicedFormula.split(", "); |
| 65 | + |
| 66 | + newVerticeCoordinates = newVerticeCoordinates.map((value) => { |
| 67 | + let coordinates = value.split(" "); |
| 68 | + return { |
| 69 | + "x": coordinates[0], |
| 70 | + "y": coordinates[1], |
| 71 | + } |
| 72 | + }); |
| 73 | + |
| 74 | + setShapeInformation({ |
| 75 | + ...shapeInformation, |
| 76 | + "name": props.shape.name, |
| 77 | + "formula": props.shape.formula, |
| 78 | + "vertices": props.shape.vertices, |
| 79 | + "private": true, |
| 80 | + "edges": props.shape.edges, |
| 81 | + "notes": props.shape.notes, |
| 82 | + "clipPathType": props.shape.type, |
| 83 | + "showShadow": true, |
| 84 | + "backgroundColor": props.shape.backgroundColor, |
| 85 | + "verticeCoordinates" : newVerticeCoordinates |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + }, [props.show]); |
| 90 | + |
57 | 91 | // Changes shapeInformation when something in ShapeForm or ShapePreview is altered |
58 | 92 | const handleChange = (event, data, number) => { |
59 | 93 |
|
|
0 commit comments