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