Skip to content

Commit ee70ca4

Browse files
committed
added html element file, logic when adding child. fixed delete comonent and small logic change for new child size.
1 parent fa731e6 commit ee70ca4

File tree

4 files changed

+97
-37
lines changed

4 files changed

+97
-37
lines changed

src/components/HTMLComponentPanel.jsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import LinkIcon from "@material-ui/icons/Link";
1111
import ListIcon from "@material-ui/icons/List";
1212
import ParagraphIcon from "@material-ui/icons/LocalParking";
1313
import theme from "../components/theme";
14-
14+
import Typography from '@material-ui/core/Typography';
1515
import Grid from "@material-ui/core/Grid";
1616
import Paper from "@material-ui/core/Paper";
17+
// import {HTMLelements,getSize} from "../utils/htmlElements.util";
18+
1719

1820
class HTMLComponentPanel extends Component {
1921
state = {
@@ -34,23 +36,26 @@ class HTMLComponentPanel extends Component {
3436
const { addChild } = this.props;
3537
return (
3638
<Paper className={"htmlPanelz"}>
37-
<TextField
39+
<Typography variant="title" component="h3">
40+
Add HTML elements
41+
</Typography>
42+
{/* <TextField
3843
id="title-input"
3944
label="Add HTML component"
4045
placeholder="Name of Component"
4146
margin="normal"
4247
autoFocus
4348
onChange={this.handleChange}
44-
// value={HtmlComponentName}
45-
// name="HtmlComponentName"
46-
// className={classes.light}
47-
// InputProps={{
48-
// className: classes.input
49-
// }}
50-
// InputLabelProps={{
51-
// className: classes.input
52-
// }}
53-
/>
49+
value={HtmlComponentName}
50+
name="HtmlComponentName"
51+
className={classes.light}
52+
InputProps={{
53+
className: classes.input
54+
}}
55+
InputLabelProps={{
56+
className: classes.input
57+
}}
58+
/> */}
5459
<Grid container spacing={24} alignItems="baseline" align="stretch">
5560
<Grid item xs={4}>
5661
<IconButton

src/containers/MainContainer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
changeFocusChild,
1414
changeComponentFocusChild,
1515
deleteChild,
16+
deleteComponent,
1617
createApplication,
1718
changeImagePath,
1819
} from '../actions/components';

src/utils/componentReducer.util.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//import setSelectableParents from "./setSelectableParents.util";
22
import getSelectable from "./getSelectable.util";
33
import getColor from "./colors.util";
4+
import {HTMLelements,getSize} from "../utils/htmlElements.util";
45

56
const initialComponentState = {
67
id: null,
@@ -51,7 +52,7 @@ export const addComponent = (state, { title }) => {
5152
width: 600,
5253
height: 400
5354
},
54-
draggable: true,
55+
//draggable: true,
5556
color: componentColor,
5657
childType: "COMP"
5758
};
@@ -95,8 +96,7 @@ export const addComponent = (state, { title }) => {
9596
// get the focus component (aka the component were adding the child to)
9697

9798
export const addChild = (state, { title, childType = "", HTMLInfo = {} }) => {
98-
console.log(HTMLInfo);
99-
99+
100100
let strippedTitle = title;
101101

102102
if (!childType) {
@@ -126,34 +126,30 @@ export const addChild = (state, { title, childType = "", HTMLInfo = {} }) => {
126126
console.log("inside if statement");
127127
}
128128

129-
// } else if (childType !== "COMP") {
130-
131-
// console.log("inside else statement");
132-
// parentComponent = {
133-
// id: "888",
134-
// position: {
135-
// x: 25,
136-
// y: 25,
137-
// width: 600,
138-
// height: 400
139-
// },
140-
// color: "#000000"
141-
// };
142-
// }
129+
let htmlElemPosition;
130+
if(childType == 'HTML') {
131+
htmlElemPosition = getSize(htmlElement)
132+
// if above function doesnt reutn anything, it means html element is not in our database
133+
if (!htmlElemPosition.width) {
134+
console.log(`Did not add html child: ${htmlElement} the GetSize function indicated that it isnt in our DB`)
135+
return;
136+
}
137+
console.log(`htmlElemPosition: ${JSON.stringify(htmlElemPosition)}`)
138+
}
143139

144140
const newPosition =
145141
childType === "COMP"
146142
? {
147-
x: parentComponent.position.x + view.nextChildId * 5, // new children are offset by 5px, x and y
148-
y: parentComponent.position.y + view.nextChildId * 5,
149-
width: parentComponent.position.width * 0.9, // new children have an initial position of their parentComponent (maybe don't need 90%)
143+
x: view.position.x + view.nextChildId * 5, // new children are offset by 5px, x and y
144+
y: view.position.y + view.nextChildId * 5,
145+
width: parentComponent.position.width * 0.9, // new children have an initial position of their CLASS (maybe don't need 90%)
150146
height: parentComponent.position.height * 0.9
151147
}
152148
: {
153-
x: 25 + view.nextChildId * 5,
154-
y: 25 + view.nextChildId * 5,
155-
width: 600 * 0.9,
156-
height: 400 * 0.9
149+
x: view.position.x + view.nextChildId * 5,
150+
y: view.position.y + view.nextChildId * 5,
151+
width: htmlElemPosition.width,
152+
height: htmlElemPosition.height
157153
};
158154

159155
const newChild = {
@@ -162,7 +158,7 @@ export const addChild = (state, { title, childType = "", HTMLInfo = {} }) => {
162158
childComponentId: childType == "COMP" ? parentComponent.id : null, // only relevant fot children of type COMPONENT
163159
componentName: strippedTitle,
164160
position: newPosition,
165-
draggable: true,
161+
// draggable: true,
166162
color: null, // parentComponent.color, // only relevant fot children of type COMPONENT
167163
htmlElement: htmlElement, // only relevant fot children of type HTML
168164
HTMLInfo: HTMLInfo

src/utils/htmlElements.util.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
// our "database" of HTML elements that the user can chose from
3+
const HTMLelements = {
4+
Image: {
5+
width: 300,
6+
height: 300,
7+
attributes:['ClassName','id','Text','Src']
8+
} ,
9+
Button: {
10+
width: 75,
11+
height: 28,
12+
attribute:['ClassName','id','Text']
13+
},
14+
Form: {
15+
width: 400,
16+
height: 400,
17+
attribute:['ClassName','id','Text']
18+
},
19+
Paragraph: {
20+
width: 250,
21+
height: 75,
22+
attribute:['ClassName','id','Text']
23+
},
24+
List: {
25+
width: 100,
26+
height: 100,
27+
attribute:['ClassName','id','Text']
28+
},
29+
Link: {
30+
width: 50,
31+
height: 50,
32+
attribute:['ClassName','id','Text']
33+
}
34+
}
35+
36+
const attributes = {
37+
"Classname" : {type: "freeText"} ,
38+
"Id" : {type:"freeText"} ,
39+
"TextJustify": {type: "select", values: "Left,Right,Center"}
40+
}
41+
42+
43+
function getSize(htmlElement){
44+
45+
const localHTMLelements = HTMLelements;
46+
47+
if(!htmlElement in localHTMLelements) {
48+
window.alert(`htmlElement error: "${htmlElement} is not found in our database"`) ;
49+
return;
50+
}
51+
52+
return {
53+
width: HTMLelements[htmlElement].width || 300 ,
54+
height: HTMLelements[htmlElement].height || 300 ,
55+
}
56+
}
57+
58+
export {HTMLelements,getSize} ;

0 commit comments

Comments
 (0)