Skip to content

Commit f0e6f97

Browse files
committed
bug: fixed issue where adding new coordinates crashes app
1 parent 31269b5 commit f0e6f97

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

components/core/CreateShape.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ const CreateShape = (props) => {
253253
let xValue = "";
254254
let yValue = "";
255255

256+
// If the formula includes both percentage and px
257+
// Figure out which one comes first and use that index of find it
256258
if (values.includes("%") && values.includes("px")) {
257259

258260
let indexOfPX = values.indexOf("px");
@@ -301,16 +303,25 @@ const CreateShape = (props) => {
301303
let xValue;
302304
let yValue;
303305

304-
if (shapeInformation.verticeCoordinates[number].x.includes("%")) {
306+
// If there is a new coordinate
307+
if (shapeInformation.verticeCoordinates.length === number) {
305308
xValue = Math.round((x / 280.0) * 100.0) + "%";
306-
} else if (shapeInformation.verticeCoordinates[number].x.includes("px")) {
307-
xValue = Math.round(x) + "px";
308-
}
309-
310-
if (shapeInformation.verticeCoordinates[number].y.includes("%")) {
311309
yValue = Math.round((y / 280.0) * 100.0) + "%";
312-
} else if (shapeInformation.verticeCoordinates[number].y.includes("px")) {
313-
yValue = Math.round(y) + "px";
310+
} else {
311+
312+
// Determines whether previous x coordinate was in percentage or px and adjusts value to maintain same unit of measurement
313+
if (shapeInformation.verticeCoordinates[number].x.includes("%")) {
314+
xValue = Math.round((x / 280.0) * 100.0) + "%";
315+
} else if (shapeInformation.verticeCoordinates[number].x.includes("px")) {
316+
xValue = Math.round(x) + "px";
317+
}
318+
319+
// Determines whether previous y coordinate was in percentage or px and adjusts value to maintain same unit of measurement
320+
if (shapeInformation.verticeCoordinates[number].y.includes("%")) {
321+
yValue = Math.round((y / 280.0) * 100.0) + "%";
322+
} else if (shapeInformation.verticeCoordinates[number].y.includes("px")) {
323+
yValue = Math.round(y) + "px";
324+
}
314325
}
315326

316327
let newVerticeCoordinates = shapeInformation.verticeCoordinates;

0 commit comments

Comments
 (0)