Skip to content

Commit c15a2f1

Browse files
Merge pull request #62 from ChristianEdwardPadilla/development
cleanup
2 parents f0375c2 + 89c77b1 commit c15a2f1

12 files changed

+488
-759
lines changed

src/actions/components.js

Lines changed: 67 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,21 @@ import {
2626
ADD_PROP,
2727
DELETE_ALL_DATA,
2828
CHANGE_IMAGE_PATH,
29-
UPDATE_HTML_ATTR
30-
} from "../actionTypes/index";
29+
UPDATE_HTML_ATTR,
30+
} from '../actionTypes/index';
3131

32-
import { loadState } from "../localStorage";
32+
import { loadState } from '../localStorage';
3333

34-
import createFiles from "../utils/createFiles.util";
35-
import createApplicationUtil from "../utils/createApplication.util";
34+
import createFiles from '../utils/createFiles.util';
35+
import createApplicationUtil from '../utils/createApplication.util';
3636

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

4846
// export const updateChildren = ({ parentIds, childIndex, childId }) => ({
@@ -63,47 +61,36 @@ export const loadInitData = () => dispatch => {
6361
// },
6462
// });
6563

66-
export const addComponent = ({ title }) => dispatch => {
64+
export const addComponent = ({ title }) => (dispatch) => {
6765
dispatch({ type: ADD_COMPONENT, payload: { title } });
6866
};
6967

70-
export const addChild = ({ title, childType, HTMLInfo }) => dispatch => {
68+
export const addChild = ({ title, childType, HTMLInfo }) => (dispatch) => {
7169
dispatch({ type: ADD_CHILD, payload: { title, childType, HTMLInfo } });
7270
};
7371

74-
export const deleteChild = ({}) => dispatch => {
72+
export const deleteChild = ({}) => (dispatch) => {
7573
// with no payload, it will delete focusd child
7674
dispatch({ type: DELETE_CHILD, payload: {} });
7775
};
7876

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

10592
// change focus to APp
106-
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title: "App" } });
93+
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title: 'App' } });
10794
// after taking care of the children delete the component
10895
dispatch({ type: DELETE_COMPONENT, payload: { componentId } });
10996
};
@@ -139,143 +126,129 @@ export const deleteComponent = ({
139126
// dispatch({ type: SET_SELECTABLE_PARENTS });
140127
// };
141128

142-
export const changeFocusComponent = ({ title }) => dispatch => {
129+
export const changeFocusComponent = ({ title }) => (dispatch) => {
143130
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
144131
};
145132

146133
// make sure childId is being sent in
147-
export const changeFocusChild = ({ title, childId }) => dispatch => {
134+
export const changeFocusChild = ({ title, childId }) => (dispatch) => {
148135
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
149136
};
150137

151-
export const changeComponentFocusChild = ({
152-
componentId,
153-
childId
154-
}) => dispatch => {
138+
export const changeComponentFocusChild = ({ componentId, childId }) => (dispatch) => {
155139
dispatch({
156140
type: CHANGE_COMPONENT_FOCUS_CHILD,
157-
payload: { componentId, childId }
141+
payload: { componentId, childId },
158142
});
159143
};
160144

161145
export const exportFiles = ({
162-
components,
163-
path,
164-
appName,
165-
exportAppBool
166-
}) => dispatch => {
146+
components, path, appName, exportAppBool,
147+
}) => (dispatch) => {
167148
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
168149
dispatch({
169-
type: EXPORT_FILES
150+
type: EXPORT_FILES,
170151
});
171152

172153
createFiles(components, path, appName, exportAppBool)
173-
.then(dir =>
174-
dispatch({
175-
type: EXPORT_FILES_SUCCESS,
176-
payload: { status: true, dir: dir[0] }
177-
})
178-
)
179-
.catch(err =>
180-
dispatch({
181-
type: EXPORT_FILES_ERROR,
182-
payload: { status: true, err }
183-
})
184-
);
154+
.then(dir => dispatch({
155+
type: EXPORT_FILES_SUCCESS,
156+
payload: { status: true, dir: dir[0] },
157+
}))
158+
.catch(err => dispatch({
159+
type: EXPORT_FILES_ERROR,
160+
payload: { status: true, err },
161+
}));
185162
};
186163

187164
export const handleClose = () => ({
188165
type: HANDLE_CLOSE,
189-
payload: false
166+
payload: false,
190167
});
191168

192-
export const handleTransform = (
193-
componentId,
194-
childId,
195-
{ x, y, width, height }
196-
) => ({
169+
export const handleTransform = (componentId, childId, {
170+
x, y, width, height,
171+
}) => ({
197172
type: HANDLE_TRANSFORM,
198173
payload: {
199174
componentId,
200175
childId,
201176
x,
202177
y,
203178
width,
204-
height
205-
}
179+
height,
180+
},
206181
});
207182

208183
export const createApplication = ({
209184
path,
210185
components = [],
211186
genOption,
212-
appName = "reactype_app",
213-
exportAppBool
214-
}) => dispatch => {
187+
appName = 'reactype_app',
188+
exportAppBool,
189+
}) => (dispatch) => {
215190
if (genOption === 0) {
216191
exportAppBool = false;
217192
dispatch(
218193
exportFiles({
219194
appName,
220195
path,
221196
components,
222-
exportAppBool
223-
})
197+
exportAppBool,
198+
}),
224199
);
225200
} else if (genOption) {
226201
exportAppBool = true;
227202
dispatch({
228-
type: CREATE_APPLICATION
203+
type: CREATE_APPLICATION,
229204
});
230205
createApplicationUtil({
231206
path,
232207
appName,
233208
genOption,
234-
exportAppBool
209+
exportAppBool,
235210
})
236211
.then(() => {
237212
dispatch({
238-
type: CREATE_APPLICATION_SUCCESS
213+
type: CREATE_APPLICATION_SUCCESS,
239214
});
240215
dispatch(
241216
exportFiles({
242217
appName,
243218
path,
244219
components,
245-
exportAppBool
246-
})
220+
exportAppBool,
221+
}),
247222
);
248223
})
249-
.catch(err =>
250-
dispatch({
251-
type: CREATE_APPLICATION_ERROR,
252-
payload: { status: true, err }
253-
})
254-
);
224+
.catch(err => dispatch({
225+
type: CREATE_APPLICATION_ERROR,
226+
payload: { status: true, err },
227+
}));
255228
}
256229
};
257230

258231
export const openExpansionPanel = component => ({
259232
type: OPEN_EXPANSION_PANEL,
260-
payload: { component }
233+
payload: { component },
261234
});
262235

263236
// export const deleteAllData = () => ({
264237
// type: DELETE_ALL_DATA,
265238
// });
266239

267-
export const deleteProp = propId => dispatch => {
240+
export const deleteProp = propId => (dispatch) => {
268241
dispatch({ type: DELETE_PROP, payload: propId });
269242
};
270243

271244
export const addProp = prop => ({
272245
type: ADD_PROP,
273-
payload: { ...prop }
246+
payload: { ...prop },
274247
});
275248

276-
export const updateHtmlAttr = ({ attr, value }) => dispatch => {
249+
export const updateHtmlAttr = ({ attr, value }) => (dispatch) => {
277250
dispatch({
278251
type: UPDATE_HTML_ATTR,
279-
payload: { attr, value }
252+
payload: { attr, value },
280253
});
281254
};

src/components/BottomPanel.jsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
import React, { Component } from "react";
2-
import { connect } from "react-redux";
3-
import {
4-
handleClose,
5-
deleteCompProp,
6-
addCompProp
7-
} from "../actions/components";
8-
import RightTabs from "./RightTabs.jsx";
9-
import { some } from "bluebird-lst";
1+
import React, { Component } from 'react';
2+
import { connect } from 'react-redux';
3+
import { some } from 'bluebird-lst';
4+
import { handleClose, deleteCompProp, addCompProp } from '../actions/components';
5+
import RightTabs from './RightTabs.jsx';
106

11-
const IPC = require("electron").ipcRenderer;
7+
const IPC = require('electron').ipcRenderer;
128

139
const mapDispatchToProps = dispatch => ({
1410
handleNotificationClose: () => dispatch(handleClose()),
1511
deleteProp: ({ id, index }) => dispatch(deleteCompProp({ id, index })),
16-
addProp: prop => dispatch(addCompProp(prop))
12+
addProp: prop => dispatch(addCompProp(prop)),
1713
});
1814

1915
const mapStateToProps = store => ({
2016
// successOpen: store.workspace.successOpen,
2117
// errorOpen: store.workspace.errorOpen,
2218
// appDir: store.workspace.appDir,
2319
focusChild: store.workspace.focusChild,
24-
components: store.workspace.components
20+
components: store.workspace.components,
2521
});
2622

2723
class BottomPanel extends Component {
@@ -31,7 +27,7 @@ class BottomPanel extends Component {
3127
// };
3228

3329
viewAppDir = () => {
34-
IPC.send("view_app_dir", this.props.appDir);
30+
IPC.send('view_app_dir', this.props.appDir);
3531
};
3632

3733
render() {
@@ -44,14 +40,12 @@ class BottomPanel extends Component {
4440
focusComponent,
4541
deleteProp,
4642
addProp,
47-
focusChild
43+
focusChild,
4844
// rightColumnOpen
4945
} = this.props;
5046

51-
console.log(components);
52-
5347
return (
54-
<div className="bottom-panel" style={{ width: "100%" }}>
48+
<div className="bottom-panel" style={{ width: '100%' }}>
5549
<RightTabs
5650
components={components}
5751
focusComponent={focusComponent}
@@ -74,5 +68,5 @@ class BottomPanel extends Component {
7468

7569
export default connect(
7670
mapStateToProps,
77-
mapDispatchToProps
71+
mapDispatchToProps,
7872
)(BottomPanel);

0 commit comments

Comments
 (0)