@@ -26,70 +26,84 @@ import {
26
26
DELETE_PROP ,
27
27
ADD_PROP ,
28
28
DELETE_ALL_DATA ,
29
- CHANGE_IMAGE_PATH ,
30
- } from ' ../actionTypes/index' ;
29
+ CHANGE_IMAGE_PATH
30
+ } from " ../actionTypes/index" ;
31
31
32
- import { loadState } from ' ../localStorage' ;
32
+ import { loadState } from " ../localStorage" ;
33
33
34
34
// import createFiles from '../utils/createFiles.util';
35
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 } ) => ( {
47
49
type : UPDATE_CHILDREN ,
48
50
payload : {
49
51
parentIds,
50
52
childIndex,
51
- childId,
52
- } ,
53
+ childId
54
+ }
53
55
} ) ;
54
56
55
57
export const parentReassignment = ( { index, id, parentIds } ) => ( {
56
58
type : REASSIGN_PARENT ,
57
59
payload : {
58
60
index,
59
61
id,
60
- parentIds,
61
- } ,
62
+ parentIds
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 } ) => ( dispatch ) => {
70
+ export const addChild = ( { title } ) => dispatch => {
69
71
dispatch ( { type : ADD_CHILD , payload : { title } } ) ;
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 : { parentId : parent . id , childId : child . childId , calledFromDeleteComponent : true } ,
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
+ } ) ;
87
102
} ) ;
88
- } ) ;
89
103
} ) ;
90
104
91
105
// change focus to APp
92
- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : ' App' } } ) ;
106
+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : " App" } } ) ;
93
107
// after taking care of the children delete the component
94
108
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
95
109
} ;
@@ -99,43 +113,49 @@ export const updateComponent = ({
99
113
index,
100
114
newParentId = null ,
101
115
color = null ,
102
- stateful = null ,
103
- } ) => ( dispatch ) => {
116
+ stateful = null
117
+ } ) => dispatch => {
104
118
dispatch ( {
105
119
type : UPDATE_COMPONENT ,
106
120
payload : {
107
121
id,
108
122
index,
109
123
newParentId,
110
124
color,
111
- stateful,
112
- } ,
125
+ stateful
126
+ }
113
127
} ) ;
114
128
115
129
if ( newParentId ) {
116
130
dispatch (
117
131
updateChildren ( {
118
132
parentIds : [ newParentId ] ,
119
133
childId : id ,
120
- childIndex : index ,
121
- } ) ,
134
+ childIndex : index
135
+ } )
122
136
) ;
123
137
}
124
138
125
139
dispatch ( { type : SET_SELECTABLE_PARENTS } ) ;
126
140
} ;
127
141
128
- export const changeFocusComponent = ( { title } ) => ( dispatch ) => {
142
+ export const changeFocusComponent = ( { title } ) => dispatch => {
129
143
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
130
144
} ;
131
145
132
146
// make sure childId is being sent in
133
- export const changeFocusChild = ( { title, childId } ) => ( dispatch ) => {
147
+ export const changeFocusChild = ( { title, childId } ) => dispatch => {
134
148
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { title, childId } } ) ;
135
149
} ;
136
150
137
- export const changeComponentFocusChild = ( { componentId, childId } ) => ( dispatch ) => {
138
- dispatch ( { type : CHANGE_COMPONENT_FOCUS_CHILD , payload : { componentId, childId } } ) ;
151
+ export const changeComponentFocusChild = ( {
152
+ componentId,
153
+ childId
154
+ } ) => dispatch => {
155
+ dispatch ( {
156
+ type : CHANGE_COMPONENT_FOCUS_CHILD ,
157
+ payload : { componentId, childId }
158
+ } ) ;
139
159
} ;
140
160
141
161
// export const exportFiles = ({ components, path }) => (dispatch) => {
@@ -156,21 +176,23 @@ export const changeComponentFocusChild = ({ componentId, childId }) => (dispatch
156
176
157
177
export const handleClose = ( ) => ( {
158
178
type : HANDLE_CLOSE ,
159
- payload : false ,
179
+ payload : false
160
180
} ) ;
161
181
162
- export const handleTransform = ( componentId , childId , {
163
- x, y, width, height,
164
- } ) => ( {
182
+ export const handleTransform = (
183
+ componentId ,
184
+ childId ,
185
+ { x, y, width, height }
186
+ ) => ( {
165
187
type : HANDLE_TRANSFORM ,
166
188
payload : {
167
189
componentId,
168
190
childId,
169
191
x,
170
192
y,
171
193
width,
172
- height,
173
- } ,
194
+ height
195
+ }
174
196
} ) ;
175
197
176
198
// export const createApplication = ({
@@ -200,7 +222,7 @@ export const handleTransform = (componentId, childId, {
200
222
201
223
export const toggleDragging = status => ( {
202
224
type : TOGGLE_DRAGGING ,
203
- payload : status ,
225
+ payload : status
204
226
} ) ;
205
227
206
228
// export const moveToBottom = componentId => ({
@@ -215,7 +237,7 @@ export const toggleDragging = status => ({
215
237
216
238
export const openExpansionPanel = component => ( {
217
239
type : OPEN_EXPANSION_PANEL ,
218
- payload : { component } ,
240
+ payload : { component }
219
241
} ) ;
220
242
221
243
// export const deleteAllData = () => ({
@@ -227,12 +249,12 @@ export const openExpansionPanel = component => ({
227
249
// payload: path,
228
250
// });
229
251
230
- // export const deleteCompProp = ({ id, index }) => ({
231
- // type: DELETE_PROP,
232
- // payload: { id, index },
233
- // });
252
+ export const deleteProp = ( { id, index } ) => ( {
253
+ type : DELETE_PROP ,
254
+ payload : { id, index }
255
+ } ) ;
234
256
235
- // export const addCompProp = prop => ({
236
- // type: ADD_PROP,
237
- // payload: { ...prop },
238
- // });
257
+ export const addProp = prop => ( {
258
+ type : ADD_PROP ,
259
+ payload : { ...prop }
260
+ } ) ;
0 commit comments