7
7
DELETE_COMPONENT ,
8
8
CHANGE_FOCUS_COMPONENT ,
9
9
CHANGE_FOCUS_CHILD ,
10
+ CHANGE_COMPONENT_FOCUS_CHILD ,
10
11
UPDATE_CHILDREN ,
11
12
REASSIGN_PARENT ,
12
13
SET_SELECTABLE_PARENTS ,
@@ -25,113 +26,118 @@ import {
25
26
DELETE_PROP ,
26
27
ADD_PROP ,
27
28
DELETE_ALL_DATA ,
28
- CHANGE_IMAGE_PATH
29
- } from " ../actionTypes/index" ;
29
+ CHANGE_IMAGE_PATH ,
30
+ } from ' ../actionTypes/index' ;
30
31
31
- import { loadState } from " ../localStorage" ;
32
+ import { loadState } from ' ../localStorage' ;
32
33
33
34
// import createFiles from '../utils/createFiles.util';
34
35
// import createApplicationUtil from '../utils/createApplication.util';
35
36
36
- export const loadInitData = ( ) => dispatch => {
37
- loadState ( ) . then ( data =>
38
- dispatch ( {
39
- type : LOAD_INIT_DATA ,
40
- payload : {
41
- data : data ? data . workspace : { }
42
- }
43
- } )
44
- ) ;
37
+ export const loadInitData = ( ) => ( dispatch ) => {
38
+ loadState ( ) . then ( data => dispatch ( {
39
+ type : LOAD_INIT_DATA ,
40
+ payload : {
41
+ data : data ? data . workspace : { } ,
42
+ } ,
43
+ } ) ) ;
45
44
} ;
46
45
47
46
export const updateChildren = ( { parentIds, childIndex, childId } ) => ( {
48
47
type : UPDATE_CHILDREN ,
49
48
payload : {
50
49
parentIds,
51
50
childIndex,
52
- childId
53
- }
51
+ childId,
52
+ } ,
54
53
} ) ;
55
54
56
55
export const parentReassignment = ( { index, id, parentIds } ) => ( {
57
56
type : REASSIGN_PARENT ,
58
57
payload : {
59
58
index,
60
59
id,
61
- parentIds
62
- }
60
+ parentIds,
61
+ } ,
63
62
} ) ;
64
63
65
- export const addComponent = ( { title } ) => dispatch => {
64
+ export const addComponent = ( { title } ) => ( dispatch ) => {
66
65
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
67
66
} ;
68
67
69
- export const addChild = ( { title } ) => dispatch => {
68
+ export const addChild = ( { title } ) => ( dispatch ) => {
70
69
dispatch ( { type : ADD_CHILD , payload : { title } } ) ;
71
70
} ;
72
71
73
- export const deleteChild = ( { } ) => dispatch => { // with no payload, it will delete focusd child
74
- dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
72
+ export const deleteChild = ( { } ) => ( dispatch ) => {
73
+ // with no payload, it will delete focusd child
74
+ dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
75
75
} ;
76
76
77
- export const deleteComponent = ( { componentId , stateComponents} ) => dispatch => {
78
- console . log ( 'Hello from component.js delete component.componentId= ' , componentId )
79
-
80
- // 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 ( { type : DELETE_CHILD , payload : { parentId : parent . id , childId : child . childId , calledFromDeleteComponent : true } } ) ;
85
- } )
86
- } )
87
-
88
- // change focus to APp
89
- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : 'App' } } ) ;
90
- // after taking care of the children delete the component
91
- dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
77
+ export const deleteComponent = ( { componentId, stateComponents } ) => ( dispatch ) => {
78
+ console . log ( 'Hello from component.js delete component.componentId= ' , componentId ) ;
79
+
80
+ // 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 } ,
87
+ } ) ;
88
+ } ) ;
89
+ } ) ;
92
90
91
+ // change focus to APp
92
+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : 'App' } } ) ;
93
+ // after taking care of the children delete the component
94
+ dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
93
95
} ;
94
96
95
97
export const updateComponent = ( {
96
98
id,
97
99
index,
98
100
newParentId = null ,
99
101
color = null ,
100
- stateful = null
101
- } ) => dispatch => {
102
+ stateful = null ,
103
+ } ) => ( dispatch ) => {
102
104
dispatch ( {
103
105
type : UPDATE_COMPONENT ,
104
106
payload : {
105
107
id,
106
108
index,
107
109
newParentId,
108
110
color,
109
- stateful
110
- }
111
+ stateful,
112
+ } ,
111
113
} ) ;
112
114
113
115
if ( newParentId ) {
114
116
dispatch (
115
117
updateChildren ( {
116
118
parentIds : [ newParentId ] ,
117
119
childId : id ,
118
- childIndex : index
119
- } )
120
+ childIndex : index ,
121
+ } ) ,
120
122
) ;
121
123
}
122
124
123
125
dispatch ( { type : SET_SELECTABLE_PARENTS } ) ;
124
126
} ;
125
127
126
- export const changeFocusComponent = ( { title } ) => dispatch => {
128
+ export const changeFocusComponent = ( { title } ) => ( dispatch ) => {
127
129
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
128
130
} ;
129
131
130
132
// make sure childId is being sent in
131
- export const changeFocusChild = ( { title, childId } ) => dispatch => {
133
+ export const changeFocusChild = ( { title, childId } ) => ( dispatch ) => {
132
134
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { title, childId } } ) ;
133
135
} ;
134
136
137
+ export const changeComponentFocusChild = ( { componentId, childId } ) => ( dispatch ) => {
138
+ dispatch ( { type : CHANGE_COMPONENT_FOCUS_CHILD , payload : { componentId, childId } } ) ;
139
+ } ;
140
+
135
141
// export const exportFiles = ({ components, path }) => (dispatch) => {
136
142
// dispatch({
137
143
// type: EXPORT_FILES,
@@ -150,23 +156,21 @@ export const changeFocusChild = ({ title, childId }) => dispatch => {
150
156
151
157
export const handleClose = ( ) => ( {
152
158
type : HANDLE_CLOSE ,
153
- payload : false
159
+ payload : false ,
154
160
} ) ;
155
161
156
- export const handleTransform = (
157
- componentId ,
158
- childId ,
159
- { x, y, width, height }
160
- ) => ( {
162
+ export const handleTransform = ( componentId , childId , {
163
+ x, y, width, height,
164
+ } ) => ( {
161
165
type : HANDLE_TRANSFORM ,
162
166
payload : {
163
167
componentId,
164
168
childId,
165
169
x,
166
170
y,
167
171
width,
168
- height
169
- }
172
+ height,
173
+ } ,
170
174
} ) ;
171
175
172
176
// export const createApplication = ({
@@ -196,7 +200,7 @@ export const handleTransform = (
196
200
197
201
export const toggleDragging = status => ( {
198
202
type : TOGGLE_DRAGGING ,
199
- payload : status
203
+ payload : status ,
200
204
} ) ;
201
205
202
206
// export const moveToBottom = componentId => ({
@@ -211,7 +215,7 @@ export const toggleDragging = status => ({
211
215
212
216
export const openExpansionPanel = component => ( {
213
217
type : OPEN_EXPANSION_PANEL ,
214
- payload : { component }
218
+ payload : { component } ,
215
219
} ) ;
216
220
217
221
// export const deleteAllData = () => ({
0 commit comments