@@ -70,21 +70,14 @@ const CreateShape = (props) => {
7070 return ;
7171 }
7272
73- if ( name === 'private' ) {
74- setShapeInformation ( {
75- ...shapeInformation ,
76- "private" : ! shapeInformation . private ,
77-
78- } ) ;
79- return ;
80- }
81-
73+ // If formula value is changed, alter formula value and verticeCoordinates value depending on clipPathType
8274 if ( name === "formula" ) {
75+
8376 const edgeVerticeNumber = shapeInformation . clipPathType === "polygon" && value !== "" ? value . split ( "," ) . length : 0 ;
8477
8578 // If user deletes all, set formula to the Clip-Path type with an empty set of parentheses
8679 if ( value === "" ) {
87- handleFormulaChange ( shapeInformation . clipPathType + "()" , edgeVerticeNumber ) ;
80+ handleFormulaChange ( shapeInformation . clipPathType + "()" , edgeVerticeNumber ) ;
8881 } else if ( value . includes ( "polygon" ) ) {
8982 handleFormulaChange ( value , edgeVerticeNumber , "polygon" ) ;
9083 } else if ( value . includes ( "circle" ) ) {
@@ -95,9 +88,11 @@ const CreateShape = (props) => {
9588 handleFormulaChange ( value , edgeVerticeNumber ) ;
9689 }
9790 return ;
91+
9892 }
9993
100- if ( name === "clipPathType" ) { // If Clip-Path Type is changed, change the value of the clipPathType
94+ // If Clip-Path Type is changed, change the value of the clipPathType
95+ if ( name === "clipPathType" ) {
10196
10297 if ( value === "polygon" ) {
10398 setShapeInformation ( {
@@ -138,7 +133,8 @@ const CreateShape = (props) => {
138133 return ;
139134 }
140135
141- if ( name === "mousemove" ) { // If DraggableVertice is moved, adjust verticeCoordinates and formula
136+ // If DraggableVertice is moved, adjust verticeCoordinates and formula
137+ if ( name === "mousemove" ) {
142138
143139 const newVerticeCoordinates = addNewVerticeCoordinates ( data . x , data . y , number ) ;
144140 const newFormula = generateNewFormula ( newVerticeCoordinates ) ;
@@ -151,7 +147,8 @@ const CreateShape = (props) => {
151147 return ;
152148 }
153149
154- if ( name === "click" && event . target . id === "shapeShadow" && shapeInformation . clipPathType === "polygon" ) { // If background of preview is clicked, add a verticeCoordinate value at its location and adjust formula
150+ // If background of preview is clicked and the clipPathType is a polygon, add a verticeCoordinate value at its location and adjust formula
151+ if ( name === "click" && event . target . id === "shapeShadow" && shapeInformation . clipPathType === "polygon" ) {
155152
156153 const newVerticeCoordinates = addNewVerticeCoordinates ( event . nativeEvent . offsetX , event . nativeEvent . offsetY , shapeInformation . verticeCoordinates . length ) ;
157154 const newFormula = generateNewFormula ( newVerticeCoordinates ) ;
@@ -165,8 +162,9 @@ const CreateShape = (props) => {
165162 } ) ;
166163 return ;
167164 }
168-
169- if ( event . target . id . includes ( "deleteButton" ) && number !== undefined ) { // If delete button is pressed, remove the corresponding verticeCoordinate and adjust formula
165+
166+ // If delete button is pressed and passes a number that corresponds to the vertice, remove the corresponding verticeCoordinate and adjust formula
167+ if ( event . target . id . includes ( "deleteButton" ) && number !== undefined ) {
170168
171169 let newVerticeCoordinates = [ ] ;
172170
@@ -188,12 +186,16 @@ const CreateShape = (props) => {
188186 return ;
189187 }
190188
189+ // Handles all other ShapeForm and ShapePreview Changes
191190 setShapeInformation ( {
192191 ...shapeInformation ,
193192 [ name ] : value ,
194193 } ) ;
195- }
194+ }
196195
196+ // Called when there is a change in the textbox for formula in the form
197+ // Adjusts verticeCoordinates, vertices, and edges accordingly
198+ // Ensures that the parentheses remain
197199 function handleFormulaChange ( formula , edgeVerticeNumber , clipPathType ) {
198200 let newVerticeCoordinates = [ ] ;
199201
@@ -221,7 +223,7 @@ const CreateShape = (props) => {
221223 } ) ;
222224 }
223225
224-
226+ // Returns an array that has a new verticeCoordinate
225227 function addNewVerticeCoordinates ( x , y , number ) {
226228 const xPercentage = Math . round ( ( x / 280.0 ) * 100.0 ) ;
227229 const yPercentage = Math . round ( ( y / 280.0 ) * 100.0 ) ;
@@ -235,6 +237,7 @@ const CreateShape = (props) => {
235237 return newVerticeCoordinates ;
236238 }
237239
240+ // Returns a generated formula string from a verticeCoordinate array
238241 function generateNewFormula ( newVerticeCoordinates ) {
239242 let newFormula = shapeInformation . clipPathType + "(" ;
240243
@@ -248,6 +251,7 @@ const CreateShape = (props) => {
248251 return newFormula ;
249252 }
250253
254+ // Form Validation
251255 const [ validated , setValidated ] = useState ( false ) ;
252256
253257 const handleSubmit = async ( event ) => {
0 commit comments