@@ -19,7 +19,6 @@ import {
19
19
CREATE_APPLICATION ,
20
20
CREATE_APPLICATION_SUCCESS ,
21
21
CREATE_APPLICATION_ERROR ,
22
- TOGGLE_DRAGGING ,
23
22
MOVE_TO_BOTTOM ,
24
23
MOVE_TO_TOP ,
25
24
OPEN_EXPANSION_PANEL ,
@@ -29,10 +28,11 @@ import {
29
28
CHANGE_IMAGE_PATH ,
30
29
} from '../actionTypes/index' ;
31
30
31
+
32
32
import { loadState } from '../localStorage' ;
33
33
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'
36
36
37
37
export const loadInitData = ( ) => dispatch => {
38
38
loadState ( ) . then ( data =>
@@ -45,23 +45,23 @@ export const loadInitData = () => dispatch => {
45
45
) ;
46
46
} ;
47
47
48
- export const updateChildren = ( { parentIds, childIndex, childId } ) => ( {
49
- type : UPDATE_CHILDREN ,
50
- payload : {
51
- parentIds,
52
- childIndex,
53
- childId,
54
- } ,
55
- } ) ;
48
+ // export const updateChildren = ({ parentIds, childIndex, childId }) => ({
49
+ // type: UPDATE_CHILDREN,
50
+ // payload: {
51
+ // parentIds,
52
+ // childIndex,
53
+ // childId,
54
+ // },
55
+ // });
56
56
57
- export const parentReassignment = ( { index, id, parentIds } ) => ( {
58
- type : REASSIGN_PARENT ,
59
- payload : {
60
- index,
61
- id,
62
- parentIds,
63
- } ,
64
- } ) ;
57
+ // export const parentReassignment = ({ index, id, parentIds }) => ({
58
+ // type: REASSIGN_PARENT,
59
+ // payload: {
60
+ // index,
61
+ // id,
62
+ // parentIds,
63
+ // },
64
+ // });
65
65
66
66
export const addComponent = ( { title } ) => dispatch => {
67
67
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
@@ -80,19 +80,15 @@ export const deleteComponent = ({ componentId, stateComponents }) => dispatch =>
80
80
console . log ( 'Hello from component.js delete component.componentId= ' , componentId ) ;
81
81
82
82
// find all places where the "to be delted" is a child and do what u gotta do
83
- stateComponents . forEach ( parent => {
84
- parent . childrenArray
85
- . filter ( child => child . childComponentId == componentId )
86
- . forEach ( child => {
87
- // console.log(`Should delete ${child.childId} from component id:${parent.id} ${parent.title}`)
88
- dispatch ( {
89
- type : DELETE_CHILD ,
90
- payload : {
91
- parentId : parent . id ,
92
- childId : child . childId ,
93
- calledFromDeleteComponent : true ,
94
- } ,
95
- } ) ;
83
+ stateComponents . forEach ( ( parent ) => {
84
+ parent . childrenArray . filter ( child => child . childComponentId == componentId ) . forEach ( ( child ) => {
85
+ dispatch ( {
86
+ type : DELETE_CHILD ,
87
+ payload : {
88
+ parentId : parent . id ,
89
+ childId : child . childId ,
90
+ calledFromDeleteComponent : true ,
91
+ } ,
96
92
} ) ;
97
93
} ) ;
98
94
@@ -102,30 +98,36 @@ export const deleteComponent = ({ componentId, stateComponents }) => dispatch =>
102
98
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
103
99
} ;
104
100
105
- export const updateComponent = ( { id, index, newParentId = null , color = null , stateful = null } ) => dispatch => {
106
- dispatch ( {
107
- type : UPDATE_COMPONENT ,
108
- payload : {
109
- id,
110
- index,
111
- newParentId,
112
- color,
113
- stateful,
114
- } ,
115
- } ) ;
101
+ // export const updateComponent = ({
102
+ // id,
103
+ // index,
104
+ // newParentId = null,
105
+ // color = null,
106
+ // stateful = null,
107
+ // }) => (dispatch) => {
108
+ // dispatch({
109
+ // type: UPDATE_COMPONENT,
110
+ // payload: {
111
+ // id,
112
+ // index,
113
+ // newParentId,
114
+ // color,
115
+ // stateful,
116
+ // },
117
+ // });
116
118
117
- if ( newParentId ) {
118
- dispatch (
119
- updateChildren ( {
120
- parentIds : [ newParentId ] ,
121
- childId : id ,
122
- childIndex : index ,
123
- } ) ,
124
- ) ;
125
- }
119
+ // if (newParentId) {
120
+ // dispatch(
121
+ // updateChildren({
122
+ // parentIds: [newParentId],
123
+ // childId: id,
124
+ // childIndex: index,
125
+ // }),
126
+ // );
127
+ // }
126
128
127
- dispatch ( { type : SET_SELECTABLE_PARENTS } ) ;
128
- } ;
129
+ // dispatch({ type: SET_SELECTABLE_PARENTS });
130
+ // };
129
131
130
132
export const changeFocusComponent = ( { title } ) => dispatch => {
131
133
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
@@ -143,21 +145,21 @@ export const changeComponentFocusChild = ({ componentId, childId }) => dispatch
143
145
} ) ;
144
146
} ;
145
147
146
- // export const exportFiles = ({ components, path }) => (dispatch) => {
147
- // dispatch({
148
- // type: EXPORT_FILES,
149
- // });
148
+ export const exportFiles = ( { components, path } ) => ( dispatch ) => {
149
+ dispatch ( {
150
+ type : EXPORT_FILES ,
151
+ } ) ;
150
152
151
- // createFiles(components, path)
152
- // .then(dir => dispatch({
153
- // type: EXPORT_FILES_SUCCESS,
154
- // payload: { status: true, dir: dir[0] },
155
- // }))
156
- // .catch(err => dispatch({
157
- // type: EXPORT_FILES_ERROR,
158
- // payload: { status: true, err },
159
- // }));
160
- // };
153
+ createFiles ( components , path )
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
+ } ) ) ;
162
+ } ;
161
163
162
164
export const handleClose = ( ) => ( {
163
165
type : HANDLE_CLOSE ,
@@ -176,45 +178,30 @@ export const handleTransform = (componentId, childId, { x, y, width, height }) =
176
178
} ,
177
179
} ) ;
178
180
179
- // export const createApplication = ({
180
- // path, components = [], genOption, appName = 'proto_app', repoUrl,
181
- // }) => (dispatch) => {
182
- // if (genOption === 0) {
183
- // dispatch(exportFiles({ path, components }));
184
- // } else if (genOption) {
185
- // dispatch({
186
- // type: CREATE_APPLICATION,
187
- // });
188
- // createApplicationUtil({
189
- // path, appName, genOption, repoUrl,
190
- // })
191
- // .then(() => {
192
- // dispatch({
193
- // type: CREATE_APPLICATION_SUCCESS,
194
- // });
195
- // dispatch(exportFiles({ path: `${path}/${appName}`, components }));
196
- // })
197
- // .catch(err => dispatch({
198
- // type: CREATE_APPLICATION_ERROR,
199
- // payload: { status: true, err },
200
- // }));
201
- // }
202
- // };
203
-
204
- export const toggleDragging = status => ( {
205
- type : TOGGLE_DRAGGING ,
206
- payload : status ,
207
- } ) ;
208
-
209
- // export const moveToBottom = componentId => ({
210
- // type: MOVE_TO_BOTTOM,
211
- // payload: componentId,
212
- // });
213
-
214
- // export const moveToTop = componentId => ({
215
- // type: MOVE_TO_TOP,
216
- // payload: componentId,
217
- // });
181
+ export const createApplication = ( {
182
+ path, components = [ ] , genOption, appName = 'proto_app' , repoUrl,
183
+ } ) => ( dispatch ) => {
184
+ if ( genOption === 0 ) {
185
+ dispatch ( exportFiles ( { path, components } ) ) ;
186
+ } else if ( genOption ) {
187
+ dispatch ( {
188
+ type : CREATE_APPLICATION ,
189
+ } ) ;
190
+ createApplicationUtil ( {
191
+ path, appName, genOption, repoUrl,
192
+ } )
193
+ . then ( ( ) => {
194
+ dispatch ( {
195
+ type : CREATE_APPLICATION_SUCCESS ,
196
+ } ) ;
197
+ dispatch ( exportFiles ( { path : `${ path } /${ appName } ` , components } ) ) ;
198
+ } )
199
+ . catch ( err => dispatch ( {
200
+ type : CREATE_APPLICATION_ERROR ,
201
+ payload : { status : true , err } ,
202
+ } ) ) ;
203
+ }
204
+ } ;
218
205
219
206
export const openExpansionPanel = component => ( {
220
207
type : OPEN_EXPANSION_PANEL ,
@@ -225,15 +212,9 @@ export const openExpansionPanel = component => ({
225
212
// type: DELETE_ALL_DATA,
226
213
// });
227
214
228
- // export const changeImagePath = path => ({
229
- // type: CHANGE_IMAGE_PATH,
230
- // payload: path,
231
- // });
232
-
233
- export const deleteProp = ( { id, index } ) => ( {
234
- type : DELETE_PROP ,
235
- payload : { id, index } ,
236
- } ) ;
215
+ export const deleteProp = propId => dispatch => {
216
+ dispatch ( { type : DELETE_PROP , payload : propId } ) ;
217
+ } ;
237
218
238
219
export const addProp = prop => ( {
239
220
type : ADD_PROP ,
0 commit comments