Skip to content

Commit f13ed8d

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
add component and add child is broken down into two within redux files. focus component is also fixed
1 parent b967fc1 commit f13ed8d

File tree

3 files changed

+50
-21
lines changed

3 files changed

+50
-21
lines changed

src/actions/components.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import {
2727

2828
import { loadState } from '../localStorage';
2929

30-
import createFiles from '../utils/createFiles.util';
31-
import createApplicationUtil from '../utils/createApplication.util';
30+
// import createFiles from '../utils/createFiles.util';
31+
// import createApplicationUtil from '../utils/createApplication.util';
3232

3333
export const loadInitData = () => (dispatch) => {
3434
loadState()
@@ -60,11 +60,11 @@ export const parentReassignment = (({ index, id, parentIds }) => ({
6060

6161
export const addComponent = ({ title }) => (dispatch) => {
6262
dispatch({ type: ADD_COMPONENT, payload: { title } });
63-
dispatch({ type: SET_SELECTABLE_PARENTS });
63+
// dispatch({ type: SET_SELECTABLE_PARENTS });
6464
};
6565

6666
export const addChild = ({ title }) => (dispatch) => {
67-
dispatch({ type: ADD_CHILD, payload: { title } });
67+
dispatch({ type: ADD_CHILD, payload: { title, view } });
6868
// dispatch({ type: SET_SELECTABLE_PARENTS });
6969
};
7070

@@ -167,10 +167,10 @@ export const toggleDragging = status => ({
167167
// payload: componentId,
168168
// });
169169

170-
// export const openExpansionPanel = component => ({
171-
// type: OPEN_EXPANSION_PANEL,
172-
// payload: { component },
173-
// });
170+
export const openExpansionPanel = component => ({
171+
type: OPEN_EXPANSION_PANEL,
172+
payload: { component },
173+
});
174174

175175
// export const deleteAllData = () => ({
176176
// type: DELETE_ALL_DATA,

src/containers/LeftContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const mapDispatchToProps = dispatch => ({
2525
// }) => dispatch(actions.deleteComponent({ index, id, parentIds })),
2626
// moveToBottom: componentId => dispatch(actions.moveToBottom(componentId)),
2727
// moveToTop: componentId => dispatch(actions.moveToTop(componentId)),
28-
// openExpansionPanel: component => dispatch(actions.openExpansionPanel(component)),
28+
openExpansionPanel: component => dispatch(actions.openExpansionPanel(component)),
2929
// deleteAllData: () => dispatch(actions.deleteAllData()),
3030
});
3131

src/utils/componentReducer.util.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,23 @@ const initialComponentState = {
1919
width: 50,
2020
height: 50,
2121
},
22+
23+
childrenArray: [],
24+
nextChildId: 1,
25+
focusChild: null,
2226
};
2327

28+
const initialChildState = {
29+
childId: null,
30+
componentName: null,
31+
position: {
32+
x: 110,
33+
y: 120,
34+
width: 50,
35+
height: 50,
36+
}
37+
}
38+
2439
export const addComponent = (state, { title }) => {
2540
const strippedTitle = title
2641
.replace(/[a-z]+/gi,
@@ -50,32 +65,46 @@ export const addComponent = (state, { title }) => {
5065
};
5166
};
5267

68+
// get title (aka the class associated with the new child)
69+
// get the focus component (aka the component were adding the child to)
70+
5371
export const addChild = (state, { title }) => {
5472
const strippedTitle = title
5573
.replace(/[a-z]+/gi,
5674
word => word[0].toUpperCase() + word.slice(1))
5775
.replace(/[-_\s0-9\W]+/gi, '');
58-
const newComponent = {
59-
...initialComponentState,
60-
title: strippedTitle,
61-
id: state.nextId.toString(),
62-
color: getColor(),
76+
77+
const newChild = {
78+
childId: state.components.nextChildId.toString(),
79+
componentName: strippedTitle,
80+
position: {
81+
x: 110,
82+
y: 120,
83+
width: 50,
84+
height: 50,
85+
}
86+
};
87+
88+
let view = state.focusComponent;
89+
90+
const compsChildrenArr = [
91+
...state.components.view.childrenArray,
92+
newChild
93+
]
94+
95+
const component = {
96+
...state.components.view,
97+
childrenArray: compsChildrenArr,
6398
};
6499

65100
const components = [
66101
...state.components,
67-
newComponent,
102+
component,
68103
];
69104

70-
const totalComponents = state.totalComponents + 1;
71-
const nextId = state.nextId + 1;
72-
73105
return {
74106
...state,
75-
totalComponents,
76-
nextId,
77107
components,
78-
focusComponent: newComponent,
79108
};
80109
};
81110

0 commit comments

Comments
 (0)