Skip to content

Commit 50f97c9

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
adding functionality to add html comps
1 parent 5f3b025 commit 50f97c9

File tree

8 files changed

+572
-446
lines changed

8 files changed

+572
-446
lines changed

src/actions/components.js

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,74 +25,84 @@ import {
2525
DELETE_PROP,
2626
ADD_PROP,
2727
DELETE_ALL_DATA,
28-
CHANGE_IMAGE_PATH,
29-
} from '../actionTypes/index';
28+
CHANGE_IMAGE_PATH
29+
} from "../actionTypes/index";
3030

31-
import { loadState } from '../localStorage';
31+
import { loadState } from "../localStorage";
3232

3333
// import createFiles from '../utils/createFiles.util';
3434
// import createApplicationUtil from '../utils/createApplication.util';
3535

36-
export const loadInitData = () => (dispatch) => {
37-
loadState().then(data => dispatch({
38-
type: LOAD_INIT_DATA,
39-
payload: {
40-
data: data ? data.workspace : {},
41-
},
42-
}));
36+
export const loadInitData = () => dispatch => {
37+
loadState().then(data =>
38+
dispatch({
39+
type: LOAD_INIT_DATA,
40+
payload: {
41+
data: data ? data.workspace : {}
42+
}
43+
})
44+
);
4345
};
4446

4547
export const updateChildren = ({ parentIds, childIndex, childId }) => ({
4648
type: UPDATE_CHILDREN,
4749
payload: {
4850
parentIds,
4951
childIndex,
50-
childId,
51-
},
52+
childId
53+
}
5254
});
5355

5456
export const parentReassignment = ({ index, id, parentIds }) => ({
5557
type: REASSIGN_PARENT,
5658
payload: {
5759
index,
5860
id,
59-
parentIds,
60-
},
61+
parentIds
62+
}
6163
});
6264

63-
export const addComponent = ({ title }) => (dispatch) => {
65+
export const addComponent = ({ title }) => dispatch => {
6466
dispatch({ type: ADD_COMPONENT, payload: { title } });
6567
};
6668

67-
export const addChild = ({ title }) => (dispatch) => {
69+
export const addChild = ({ title }) => dispatch => {
6870
dispatch({ type: ADD_CHILD, payload: { title } });
6971
};
7072

71-
export const deleteChild = ({}) => (dispatch) => {
73+
export const deleteChild = ({}) => dispatch => {
7274
// with no payload, it will delete focusd child
7375
dispatch({ type: DELETE_CHILD, payload: {} });
7476
};
7577

76-
export const deleteComponent = ({ componentId, stateComponents }) => (dispatch) => {
77-
console.log('Hello from component.js delete component.componentId= ', componentId);
78+
export const deleteComponent = ({
79+
componentId,
80+
stateComponents
81+
}) => dispatch => {
82+
console.log(
83+
"Hello from component.js delete component.componentId= ",
84+
componentId
85+
);
7886

7987
// find all places where the "to be delted" is a child and do what u gotta do
80-
stateComponents.forEach((parent) => {
81-
parent.childrenArray.filter(child => child.childComponentId == componentId).forEach((child) => {
82-
// console.log(`Should delete ${child.childId} from component id:${parent.id} ${parent.title}`)
83-
dispatch({
84-
type: DELETE_CHILD,
85-
payload: {
86-
parentId: parent.id,
87-
childId: child.childId,
88-
calledFromDeleteComponent: true,
89-
},
88+
stateComponents.forEach(parent => {
89+
parent.childrenArray
90+
.filter(child => child.childComponentId == componentId)
91+
.forEach(child => {
92+
// console.log(`Should delete ${child.childId} from component id:${parent.id} ${parent.title}`)
93+
dispatch({
94+
type: DELETE_CHILD,
95+
payload: {
96+
parentId: parent.id,
97+
childId: child.childId,
98+
calledFromDeleteComponent: true
99+
}
100+
});
90101
});
91-
});
92102
});
93103

94104
// change focus to APp
95-
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title: 'App' } });
105+
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title: "App" } });
96106
// after taking care of the children delete the component
97107
dispatch({ type: DELETE_COMPONENT, payload: { componentId } });
98108
};
@@ -102,45 +112,48 @@ export const updateComponent = ({
102112
index,
103113
newParentId = null,
104114
color = null,
105-
stateful = null,
106-
}) => (dispatch) => {
115+
stateful = null
116+
}) => dispatch => {
107117
dispatch({
108118
type: UPDATE_COMPONENT,
109119
payload: {
110120
id,
111121
index,
112122
newParentId,
113123
color,
114-
stateful,
115-
},
124+
stateful
125+
}
116126
});
117127

118128
if (newParentId) {
119129
dispatch(
120130
updateChildren({
121131
parentIds: [newParentId],
122132
childId: id,
123-
childIndex: index,
124-
}),
133+
childIndex: index
134+
})
125135
);
126136
}
127137

128138
dispatch({ type: SET_SELECTABLE_PARENTS });
129139
};
130140

131-
export const changeFocusComponent = ({ title }) => (dispatch) => {
141+
export const changeFocusComponent = ({ title }) => dispatch => {
132142
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
133143
};
134144

135145
// make sure childId is being sent in
136-
export const changeFocusChild = ({ title, childId }) => (dispatch) => {
146+
export const changeFocusChild = ({ title, childId }) => dispatch => {
137147
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
138148
};
139149

140-
export const changeComponentFocusChild = ({ componentId, childId }) => (dispatch) => {
150+
export const changeComponentFocusChild = ({
151+
componentId,
152+
childId
153+
}) => dispatch => {
141154
dispatch({
142155
type: CHANGE_COMPONENT_FOCUS_CHILD,
143-
payload: { componentId, childId },
156+
payload: { componentId, childId }
144157
});
145158
};
146159

@@ -162,21 +175,23 @@ export const changeComponentFocusChild = ({ componentId, childId }) => (dispatch
162175

163176
export const handleClose = () => ({
164177
type: HANDLE_CLOSE,
165-
payload: false,
178+
payload: false
166179
});
167180

168-
export const handleTransform = (componentId, childId, {
169-
x, y, width, height,
170-
}) => ({
181+
export const handleTransform = (
182+
componentId,
183+
childId,
184+
{ x, y, width, height }
185+
) => ({
171186
type: HANDLE_TRANSFORM,
172187
payload: {
173188
componentId,
174189
childId,
175190
x,
176191
y,
177192
width,
178-
height,
179-
},
193+
height
194+
}
180195
});
181196

182197
// export const createApplication = ({
@@ -206,20 +221,18 @@ export const handleTransform = (componentId, childId, {
206221

207222
export const openExpansionPanel = component => ({
208223
type: OPEN_EXPANSION_PANEL,
209-
payload: { component },
224+
payload: { component }
210225
});
211226

212227
// export const deleteAllData = () => ({
213228
// type: DELETE_ALL_DATA,
214229
// });
215230

216-
217-
218-
export const deleteProp = ( propId ) => (dispatch) => {
219-
; dispatch({ type: DELETE_PROP, payload: propId });
231+
export const deleteProp = propId => dispatch => {
232+
dispatch({ type: DELETE_PROP, payload: propId });
220233
};
221234

222235
export const addProp = prop => ({
223236
type: ADD_PROP,
224-
payload: { ...prop },
237+
payload: { ...prop }
225238
});

src/components/HTMLComponentPanel.jsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ import Grid from "@material-ui/core/Grid";
1616
import Paper from "@material-ui/core/Paper";
1717

1818
class HTMLComponentPanel extends Component {
19+
state = {
20+
HtmlComponentName: ""
21+
};
22+
23+
handleChange = event => {
24+
this.setState({
25+
HtmlComponentName: event.target.value
26+
});
27+
};
28+
29+
handleCreateComponent = componentType => {
30+
let compNameAndType = this.state.componentName + componentType;
31+
addChild(compNameAndType);
32+
};
33+
1934
render() {
35+
const { addChild } = this.props;
2036
return (
2137
<Paper className={"htmlPanelz"}>
2238
<TextField
@@ -25,16 +41,9 @@ class HTMLComponentPanel extends Component {
2541
placeholder="Name of Component"
2642
margin="normal"
2743
autoFocus
28-
// onChange={this.handleChange}
29-
// onKeyPress={ev => {
30-
// if (ev.key === "Enter") {
31-
// // Do code here
32-
// this.handleAddComponent();
33-
// ev.preventDefault();
34-
// }
35-
// }}
36-
// value={componentName}
37-
// name="componentName"
44+
onChange={this.handleChange}
45+
// value={HtmlComponentName}
46+
// name="HtmlComponentName"
3847
// className={classes.light}
3948
// InputProps={{
4049
// className: classes.input
@@ -45,7 +54,15 @@ class HTMLComponentPanel extends Component {
4554
/>
4655
<Grid container spacing={24} alignItems="baseline" align="stretch">
4756
<Grid item xs={4}>
48-
<IconButton aria-label="Image">
57+
<IconButton
58+
aria-label="Image"
59+
onClick={() => {
60+
console.log(addChild);
61+
// addChild({ title: "ImageX" });
62+
// has to be the title of the focus component
63+
// need to add another parameter for the type of the
64+
}}
65+
>
4966
<ImageIcon />
5067
</IconButton>
5168
</Grid>

0 commit comments

Comments
 (0)