Skip to content

Commit 831cda9

Browse files
committed
feat: edit shape modal now loads up with shape values
1 parent f5eaa0e commit 831cda9

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

components/core/CreateShape.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useState, useEffect } from "react";
22

33
// Bootstrap
44
import Container from "react-bootstrap/Container";
@@ -54,6 +54,40 @@ const CreateShape = (props) => {
5454
...initialState,
5555
});
5656

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+
5791
// Changes shapeInformation when something in ShapeForm or ShapePreview is altered
5892
const handleChange = (event, data, number) => {
5993

components/utils/ShapeList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ const ShapeList = (
388388
{ shapeToEdit && <CreateShape
389389
show= {showEditModal}
390390
handleClose={ closeEditModal }
391-
shapeInformation= { shapeToEdit }
391+
shape= { shapeToEdit }
392392
edit={true} />
393393
}
394394

0 commit comments

Comments
 (0)