Skip to content

Commit e6995a6

Browse files
committed
feat: implemented save button. still needs to be connected to database
1 parent 92e9f64 commit e6995a6

2 files changed

Lines changed: 93 additions & 81 deletions

File tree

components/core/CreateShape.js

Lines changed: 86 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -125,95 +125,95 @@ const CreateShape = (props) => {
125125
}
126126

127127
function addNewVerticeCoordinates(x ,y, number) {
128-
const xPercentage = Math.round((x / 280.0) * 100.0);
129-
const yPercentage = Math.round((y / 280.0) * 100.0);
128+
const xPercentage = Math.round((x / 280.0) * 100.0);
129+
const yPercentage = Math.round((y / 280.0) * 100.0);
130130

131-
let newVerticeCoordinates = shapeInformation.verticeCoordinates;
132-
newVerticeCoordinates[number] = {
133-
"x": xPercentage + "%",
134-
"y": yPercentage + "%"
135-
}
131+
let newVerticeCoordinates = shapeInformation.verticeCoordinates;
132+
newVerticeCoordinates[number] = {
133+
"x": xPercentage + "%",
134+
"y": yPercentage + "%"
135+
}
136136

137-
return newVerticeCoordinates;
137+
return newVerticeCoordinates;
138138
}
139139

140140
function generateNewFormula(newVerticeCoordinates) {
141-
let newFormula = shapeInformation.clipPathType + "(";
141+
let newFormula = shapeInformation.clipPathType + "(";
142142

143-
for (let i = 0; i < newVerticeCoordinates.length; i++) {
144-
let newX = newVerticeCoordinates[i].x;
145-
let newY = newVerticeCoordinates[i].y;
143+
for (let i = 0; i < newVerticeCoordinates.length; i++) {
144+
let newX = newVerticeCoordinates[i].x;
145+
let newY = newVerticeCoordinates[i].y;
146146

147-
i === newVerticeCoordinates.length - 1 ? newFormula = newFormula + newX + " " + newY + ")" : newFormula = newFormula + newX + " " + newY + ", ";
148-
}
147+
i === newVerticeCoordinates.length - 1 ? newFormula = newFormula + newX + " " + newY + ")" : newFormula = newFormula + newX + " " + newY + ", ";
148+
}
149149

150-
return newFormula;
150+
return newFormula;
151151
}
152152

153153
function handleFormulaChange(formula, edgeVerticeNumber, clipPathType) {
154-
let newVerticeCoordinates = [];
155-
156-
if (clipPathType === "polygon") {
157-
let formulaNumbers = formula.slice(formula.indexOf("(") + 1, formula.indexOf(")"));
158-
formulaNumbers = formulaNumbers.split(", ");
159-
newVerticeCoordinates = formulaNumbers.map(x => {
160-
let percentageArray = x.split(" ");
161-
return {
162-
"x": percentageArray[0],
163-
"y": percentageArray[1],
164-
}
165-
});
166-
}
167-
168-
setShapeInformation(prevState => {
169-
return {
170-
...prevState,
171-
"formula": formula.includes("(") && formula.includes(")") ? formula : prevState.formula,
172-
"clipPathType": clipPathType === null ? prevState.clipPathType : clipPathType,
173-
"vertices": edgeVerticeNumber,
174-
"edges": edgeVerticeNumber,
175-
"verticeCoordinates": newVerticeCoordinates,
154+
let newVerticeCoordinates = [];
155+
156+
if (clipPathType === "polygon") {
157+
let formulaNumbers = formula.slice(formula.indexOf("(") + 1, formula.indexOf(")"));
158+
formulaNumbers = formulaNumbers.split(", ");
159+
newVerticeCoordinates = formulaNumbers.map(x => {
160+
let percentageArray = x.split(" ");
161+
return {
162+
"x": percentageArray[0],
163+
"y": percentageArray[1],
164+
}
165+
});
176166
}
177-
});
178-
}
179167

180-
function handleClipPathChange(clipPathType) {
181-
if (clipPathType === "polygon") {
182-
setShapeInformation({
183-
...shapeInformation,
184-
"name": "Tilted Square",
185-
"type": "tiltedSquare",
186-
"formula": "polygon(10% 10%, 90% 10%, 90% 90%, 10% 80%)",
168+
setShapeInformation(prevState => {
169+
return {
170+
...prevState,
171+
"formula": formula.includes("(") && formula.includes(")") ? formula : prevState.formula,
172+
"clipPathType": clipPathType === null ? prevState.clipPathType : clipPathType,
173+
"vertices": edgeVerticeNumber,
174+
"edges": edgeVerticeNumber,
175+
"verticeCoordinates": newVerticeCoordinates,
176+
}
187177
});
188-
}
178+
}
189179

190-
if (clipPathType === "circle") {
191-
setShapeInformation({
192-
...shapeInformation,
193-
"name": "Circle",
194-
"type": "circle",
195-
"formula": "circle(50% at 50% 50%)",
196-
});
197-
}
180+
function handleClipPathChange(clipPathType) {
181+
if (clipPathType === "polygon") {
182+
setShapeInformation({
183+
...shapeInformation,
184+
"name": "Tilted Square",
185+
"type": "tiltedSquare",
186+
"formula": "polygon(10% 10%, 90% 10%, 90% 90%, 10% 80%)",
187+
});
188+
}
198189

199-
if (clipPathType === "ellipse") {
200-
setShapeInformation({
201-
...shapeInformation,
202-
"name": "Ellipse",
203-
"type": "ellipse",
204-
"formula": "ellipse(25% 40% at 50% 50%)",
205-
});
206-
}
190+
if (clipPathType === "circle") {
191+
setShapeInformation({
192+
...shapeInformation,
193+
"name": "Circle",
194+
"type": "circle",
195+
"formula": "circle(50% at 50% 50%)",
196+
});
197+
}
207198

208-
setShapeInformation(prevState => {
209-
return {
210-
...prevState,
211-
"clipPathType": clipPathType,
212-
"edges": clipPathType === "polygon" ? 4 : 0,
213-
"vertices": clipPathType === "polygon" ? 4 : 0,
214-
"notes": "",
199+
if (clipPathType === "ellipse") {
200+
setShapeInformation({
201+
...shapeInformation,
202+
"name": "Ellipse",
203+
"type": "ellipse",
204+
"formula": "ellipse(25% 40% at 50% 50%)",
205+
});
215206
}
216-
})
207+
208+
setShapeInformation(prevState => {
209+
return {
210+
...prevState,
211+
"clipPathType": clipPathType,
212+
"edges": clipPathType === "polygon" ? 4 : 0,
213+
"vertices": clipPathType === "polygon" ? 4 : 0,
214+
"notes": "",
215+
}
216+
})
217217
}
218218

219219
const [validated, setValidated] = useState(false);
@@ -236,25 +236,36 @@ const CreateShape = (props) => {
236236
onHide={props.handleClose}
237237
backdrop="static"
238238
>
239-
<Modal.Header>
239+
<Modal.Header closeButton>
240240
<Modal.Title>Create Shape</Modal.Title>
241241
</Modal.Header>
242242
<Modal.Body>
243243
<Container fluid>
244244
<Row lg={2} md={1} sm={1} xs={1}>
245245
<Col>
246-
<ShapeForm shapeInformation={shapeInformation} handleChange={handleFormChange} handleSubmit={handleSubmit} validated={validated} />
246+
<ShapeForm
247+
shapeInformation={shapeInformation}
248+
handleChange={handleFormChange}
249+
handleSubmit={handleSubmit}
250+
validated={validated}
251+
/>
247252
</Col>
248253
<Col>
249-
<ShapePreview shapeInformation={shapeInformation} handleChange={handlePreviewChange} />
254+
<ShapePreview
255+
shapeInformation={shapeInformation}
256+
handleChange={handlePreviewChange}
257+
/>
250258
</Col>
251259
</Row>
252260
</Container>
253261
</Modal.Body>
254262
<Modal.Footer>
255-
<Button onClick={() => props.handleClose()}>
263+
<Button onClick={() => props.handleClose()} variant="outline-info">
256264
Close
257265
</Button>
266+
<Button variant="secondary" type="submit" form="createShapeForm">
267+
Save
268+
</Button>
258269
</Modal.Footer>
259270
</Modal>
260271
</>

components/utils/ShapeForm.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const ColorPicker = styled.input`
1111

1212
const ShapeForm = (props) => {
1313
return (
14-
<Form noValidate validated={props.validated} onSubmit={props.handleSubmit} id="previewForm">
14+
<Form noValidate validated={props.validated} onSubmit={props.handleSubmit} id="createShapeForm">
1515
<Form.Group>
16-
<Form.Label>Shape Name:</Form.Label>
16+
<Form.Label>Name</Form.Label>
1717
<Form.Control
1818
type="text"
1919
name="name"
@@ -25,7 +25,7 @@ const ShapeForm = (props) => {
2525
</Form.Group>
2626

2727
<Form.Group>
28-
<Form.Label>Description:</Form.Label>
28+
<Form.Label>Description</Form.Label>
2929
<Form.Control
3030
as="textarea"
3131
name="notes"
@@ -36,17 +36,18 @@ const ShapeForm = (props) => {
3636
</Form.Group>
3737

3838
<Form.Group>
39-
<Form.Label>Shape Color:</Form.Label>
39+
<Form.Label>Color Picker</Form.Label>
4040
<ColorPicker
4141
type="color"
4242
name="backgroundColor"
4343
value={props.shapeInformation.backgroundColor}
4444
onChange={props.handleChange}
45+
className="form-control-color"
4546
/>
4647
</Form.Group>
4748

4849
<Form.Group>
49-
<Form.Label>Type of Clip Path:</Form.Label>
50+
<Form.Label>Type of Clip-Path</Form.Label>
5051
<Form.Control
5152
as="select"
5253
name="clipPathType"
@@ -60,7 +61,7 @@ const ShapeForm = (props) => {
6061
</Form.Group>
6162

6263
<Form.Group>
63-
<Form.Label>Clip-Path:</Form.Label>
64+
<Form.Label>Clip-Path</Form.Label>
6465
<Form.Control
6566
type="text"
6667
name="formula"

0 commit comments

Comments
 (0)