@@ -26,21 +26,23 @@ import {
26
26
ADD_PROP ,
27
27
DELETE_ALL_DATA ,
28
28
CHANGE_IMAGE_PATH ,
29
- UPDATE_HTML_ATTR ,
30
- } from ' ../actionTypes/index' ;
29
+ UPDATE_HTML_ATTR
30
+ } from " ../actionTypes/index" ;
31
31
32
- import { loadState } from ' ../localStorage' ;
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
- export const loadInitData = ( ) => ( dispatch ) => {
38
- loadState ( ) . then ( data => dispatch ( {
39
- type : LOAD_INIT_DATA ,
40
- payload : {
41
- data : data ? data . workspace : { } ,
42
- } ,
43
- } ) ) ;
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
+ ) ;
44
46
} ;
45
47
46
48
// export const updateChildren = ({ parentIds, childIndex, childId }) => ({
@@ -61,39 +63,47 @@ export const loadInitData = () => (dispatch) => {
61
63
// },
62
64
// });
63
65
64
- export const addComponent = ( { title } ) => ( dispatch ) => {
66
+ export const addComponent = ( { title } ) => dispatch => {
65
67
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
66
68
} ;
67
69
68
- export const addChild = ( { title, childType, HTMLInfo } ) => ( dispatch ) => {
70
+ export const addChild = ( { title, childType, HTMLInfo } ) => dispatch => {
69
71
dispatch ( { type : ADD_CHILD , payload : { title, childType, HTMLInfo } } ) ;
70
72
} ;
71
73
72
- export const deleteChild = ( { } ) => ( dispatch ) => {
74
+ export const deleteChild = ( { } ) => dispatch => {
73
75
// with no payload, it will delete focusd child
74
76
dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
75
77
} ;
76
78
77
- export const deleteComponent = ( { componentId, stateComponents } ) => ( dispatch ) => {
78
- console . log ( 'Hello from component.js delete component.componentId= ' , componentId ) ;
79
+ export const deleteComponent = ( {
80
+ componentId,
81
+ stateComponents
82
+ } ) => dispatch => {
83
+ console . log (
84
+ "Hello from component.js delete component.componentId= " ,
85
+ componentId
86
+ ) ;
79
87
80
88
// find all places where the "to be delted" is a child and do what u gotta do
81
- stateComponents . forEach ( ( parent ) => {
82
- parent . childrenArray . filter ( child => child . childComponentId == componentId ) . forEach ( ( child ) => {
83
- // console.log(`Should delete ${child.childId} from component id:${parent.id} ${parent.title}`)
84
- dispatch ( {
85
- type : DELETE_CHILD ,
86
- payload : {
87
- parentId : parent . id ,
88
- childId : child . childId ,
89
- calledFromDeleteComponent : true ,
90
- } ,
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
+ } ) ;
91
102
} ) ;
92
- } ) ;
93
103
} ) ;
94
104
95
105
// change focus to APp
96
- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : ' App' } } ) ;
106
+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : " App" } } ) ;
97
107
// after taking care of the children delete the component
98
108
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
99
109
} ;
@@ -129,129 +139,143 @@ export const deleteComponent = ({ componentId, stateComponents }) => (dispatch)
129
139
// dispatch({ type: SET_SELECTABLE_PARENTS });
130
140
// };
131
141
132
- export const changeFocusComponent = ( { title } ) => ( dispatch ) => {
142
+ export const changeFocusComponent = ( { title } ) => dispatch => {
133
143
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
134
144
} ;
135
145
136
146
// make sure childId is being sent in
137
- export const changeFocusChild = ( { title, childId } ) => ( dispatch ) => {
147
+ export const changeFocusChild = ( { title, childId } ) => dispatch => {
138
148
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { title, childId } } ) ;
139
149
} ;
140
150
141
- export const changeComponentFocusChild = ( { componentId, childId } ) => ( dispatch ) => {
151
+ export const changeComponentFocusChild = ( {
152
+ componentId,
153
+ childId
154
+ } ) => dispatch => {
142
155
dispatch ( {
143
156
type : CHANGE_COMPONENT_FOCUS_CHILD ,
144
- payload : { componentId, childId } ,
157
+ payload : { componentId, childId }
145
158
} ) ;
146
159
} ;
147
160
148
161
export const exportFiles = ( {
149
- components, path, appName, exportAppBool,
150
- } ) => ( dispatch ) => {
162
+ components,
163
+ path,
164
+ appName,
165
+ exportAppBool
166
+ } ) => dispatch => {
151
167
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
152
168
dispatch ( {
153
- type : EXPORT_FILES ,
169
+ type : EXPORT_FILES
154
170
} ) ;
155
171
156
172
createFiles ( components , path , appName , exportAppBool )
157
- . then ( dir => dispatch ( {
158
- type : EXPORT_FILES_SUCCESS ,
159
- payload : { status : true , dir : dir [ 0 ] } ,
160
- } ) )
161
- . catch ( err => dispatch ( {
162
- type : EXPORT_FILES_ERROR ,
163
- payload : { status : true , err } ,
164
- } ) ) ;
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
+ ) ;
165
185
} ;
166
186
167
187
export const handleClose = ( ) => ( {
168
188
type : HANDLE_CLOSE ,
169
- payload : false ,
189
+ payload : false
170
190
} ) ;
171
191
172
- export const handleTransform = ( componentId , childId , {
173
- x, y, width, height,
174
- } ) => ( {
192
+ export const handleTransform = (
193
+ componentId ,
194
+ childId ,
195
+ { x, y, width, height }
196
+ ) => ( {
175
197
type : HANDLE_TRANSFORM ,
176
198
payload : {
177
199
componentId,
178
200
childId,
179
201
x,
180
202
y,
181
203
width,
182
- height,
183
- } ,
204
+ height
205
+ }
184
206
} ) ;
185
207
186
208
export const createApplication = ( {
187
209
path,
188
210
components = [ ] ,
189
211
genOption,
190
- appName = ' reactype_app' ,
191
- exportAppBool,
192
- } ) => ( dispatch ) => {
212
+ appName = " reactype_app" ,
213
+ exportAppBool
214
+ } ) => dispatch => {
193
215
if ( genOption === 0 ) {
194
216
exportAppBool = false ;
195
217
dispatch (
196
218
exportFiles ( {
197
219
appName,
198
220
path,
199
221
components,
200
- exportAppBool,
201
- } ) ,
222
+ exportAppBool
223
+ } )
202
224
) ;
203
225
} else if ( genOption ) {
204
226
exportAppBool = true ;
205
227
dispatch ( {
206
- type : CREATE_APPLICATION ,
228
+ type : CREATE_APPLICATION
207
229
} ) ;
208
230
createApplicationUtil ( {
209
231
path,
210
232
appName,
211
233
genOption,
212
- exportAppBool,
234
+ exportAppBool
213
235
} )
214
236
. then ( ( ) => {
215
237
dispatch ( {
216
- type : CREATE_APPLICATION_SUCCESS ,
238
+ type : CREATE_APPLICATION_SUCCESS
217
239
} ) ;
218
240
dispatch (
219
241
exportFiles ( {
220
242
appName,
221
243
path,
222
244
components,
223
- exportAppBool,
224
- } ) ,
245
+ exportAppBool
246
+ } )
225
247
) ;
226
248
} )
227
- . catch ( err => dispatch ( {
228
- type : CREATE_APPLICATION_ERROR ,
229
- payload : { status : true , err } ,
230
- } ) ) ;
249
+ . catch ( err =>
250
+ dispatch ( {
251
+ type : CREATE_APPLICATION_ERROR ,
252
+ payload : { status : true , err }
253
+ } )
254
+ ) ;
231
255
}
232
256
} ;
233
257
234
258
export const openExpansionPanel = component => ( {
235
259
type : OPEN_EXPANSION_PANEL ,
236
- payload : { component } ,
260
+ payload : { component }
237
261
} ) ;
238
262
239
263
// export const deleteAllData = () => ({
240
264
// type: DELETE_ALL_DATA,
241
265
// });
242
266
243
- export const deleteProp = propId => ( dispatch ) => {
267
+ export const deleteProp = propId => dispatch => {
244
268
dispatch ( { type : DELETE_PROP , payload : propId } ) ;
245
269
} ;
246
270
247
271
export const addProp = prop => ( {
248
272
type : ADD_PROP ,
249
- payload : { ...prop } ,
273
+ payload : { ...prop }
250
274
} ) ;
251
275
252
- export const updateHtmlAttr = ( { attr, value } ) => ( dispatch ) => {
276
+ export const updateHtmlAttr = ( { attr, value } ) => dispatch => {
253
277
dispatch ( {
254
278
type : UPDATE_HTML_ATTR ,
255
- payload : { attr, value } ,
279
+ payload : { attr, value }
256
280
} ) ;
257
281
} ;
0 commit comments