1
1
import {
2
- ComponentInt , ComponentsInt , PropInt , ChildInt ,
3
- } from '../utils/Interfaces.ts' ;
2
+ ComponentInt ,
3
+ ComponentsInt ,
4
+ PropInt ,
5
+ ChildInt
6
+ } from '../utils/Interfaces' ;
4
7
5
8
import {
6
9
LOAD_INIT_DATA ,
@@ -24,49 +27,53 @@ import {
24
27
ADD_PROP ,
25
28
DELETE_ALL_DATA ,
26
29
UPDATE_HTML_ATTR ,
27
- UPDATE_CHILDREN_SORT ,
30
+ UPDATE_CHILDREN_SORT
28
31
} from '../actionTypes/index.js' ;
29
32
30
33
import { loadState } from '../localStorage' ;
31
- import createFiles from '../utils/createFiles.util.ts ' ;
32
- import createApplicationUtil from '../utils/createApplication.util.ts ' ;
34
+ import createFiles from '../utils/createFiles.util' ;
35
+ import createApplicationUtil from '../utils/createApplication.util' ;
33
36
34
37
export const loadInitData = ( ) => ( dispatch : any ) => {
35
- loadState ( ) . then ( ( data : any ) => dispatch ( {
36
- type : LOAD_INIT_DATA ,
37
- payload : {
38
- data : data ? data . workspace : { } ,
39
- } ,
40
- } ) ) ;
38
+ loadState ( ) . then ( ( data : any ) =>
39
+ dispatch ( {
40
+ type : LOAD_INIT_DATA ,
41
+ payload : {
42
+ data : data ? data . workspace : { }
43
+ }
44
+ } )
45
+ ) ;
41
46
} ;
42
47
43
- export const addComponent = ( { title } : { title : string } ) => ( dispatch : any ) => {
48
+ export const addComponent = ( { title } : { title : string } ) => (
49
+ dispatch : any
50
+ ) => {
44
51
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
45
52
} ;
46
53
47
54
export const addChild = ( {
48
55
title,
49
56
childType,
50
- HTMLInfo,
57
+ HTMLInfo
51
58
} : {
52
- title : string ;
53
- childType : string ;
54
- HTMLInfo : object ;
59
+ title : string ;
60
+ childType : string ;
61
+ HTMLInfo : object ;
55
62
} ) => ( dispatch : any ) => {
56
63
dispatch ( { type : ADD_CHILD , payload : { title, childType, HTMLInfo } } ) ;
57
64
} ;
58
65
59
66
export const deleteChild = ( { } ) => ( dispatch : any ) => {
60
- // with no payload, it will delete focusd child
67
+ // with no payload, it will delete focused child
61
68
dispatch ( { type : DELETE_CHILD , payload : { } } ) ;
62
69
} ;
63
70
64
71
export const deleteComponent = ( {
65
72
componentId,
66
- stateComponents,
73
+ stateComponents
67
74
} : {
68
- componentId : number ;
69
- stateComponents : ComponentsInt ;
75
+ componentId : number ;
76
+ stateComponents : ComponentsInt ;
70
77
} ) => ( dispatch : any ) => {
71
78
// find all places where the "to be deleted" is a child and do what u gotta do
72
79
stateComponents . forEach ( ( parent : ComponentInt ) => {
@@ -78,8 +85,8 @@ stateComponents: ComponentsInt;
78
85
payload : {
79
86
parentId : parent . id ,
80
87
childId : child . childId ,
81
- calledFromDeleteComponent : true ,
82
- } ,
88
+ calledFromDeleteComponent : true
89
+ }
83
90
} ) ;
84
91
} ) ;
85
92
} ) ;
@@ -90,66 +97,77 @@ stateComponents: ComponentsInt;
90
97
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
91
98
} ;
92
99
93
- export const changeFocusComponent = ( { title } : { title : string } ) => ( dispatch : any ) => {
100
+ export const changeFocusComponent = ( { title } : { title : string } ) => (
101
+ dispatch : any
102
+ ) => {
94
103
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
95
104
} ;
96
105
97
106
// make sure childId is being sent in
98
- export const changeFocusChild = ( { childId } : { childId : number } ) => ( dispatch : any ) => {
107
+ export const changeFocusChild = ( { childId } : { childId : number } ) => (
108
+ dispatch : any
109
+ ) => {
99
110
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { childId } } ) ;
100
111
} ;
101
112
102
113
export const changeComponentFocusChild = ( {
103
114
componentId,
104
- childId,
115
+ childId
105
116
} : {
106
- componentId : number ;
107
- childId : number ;
117
+ componentId : number ;
118
+ childId : number ;
108
119
} ) => ( dispatch : any ) => {
109
120
dispatch ( {
110
121
type : CHANGE_COMPONENT_FOCUS_CHILD ,
111
- payload : { componentId, childId } ,
122
+ payload : { componentId, childId }
112
123
} ) ;
113
124
} ;
114
125
115
126
export const exportFiles = ( {
116
127
components,
117
128
path,
118
129
appName,
119
- exportAppBool,
130
+ exportAppBool
120
131
} : {
121
- components : ComponentsInt ;
122
- path : string ;
123
- appName : string ;
124
- exportAppBool : boolean ;
132
+ components : ComponentsInt ;
133
+ path : string ;
134
+ appName : string ;
135
+ exportAppBool : boolean ;
125
136
} ) => ( dispatch : any ) => {
126
137
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
127
138
dispatch ( {
128
- type : EXPORT_FILES ,
139
+ type : EXPORT_FILES
129
140
} ) ;
130
141
131
142
createFiles ( components , path , appName , exportAppBool )
132
- . then ( dir => dispatch ( {
133
- type : EXPORT_FILES_SUCCESS ,
134
- payload : { status : true , dir : dir [ 0 ] } ,
135
- } ) )
136
- . catch ( err => dispatch ( {
137
- type : EXPORT_FILES_ERROR ,
138
- payload : { status : true , err } ,
139
- } ) ) ;
143
+ . then ( ( dir ) =>
144
+ dispatch ( {
145
+ type : EXPORT_FILES_SUCCESS ,
146
+ payload : { status : true , dir : dir [ 0 ] }
147
+ } )
148
+ )
149
+ . catch ( ( err ) =>
150
+ dispatch ( {
151
+ type : EXPORT_FILES_ERROR ,
152
+ payload : { status : true , err }
153
+ } )
154
+ ) ;
140
155
} ;
141
156
142
157
export const handleClose = ( ) => ( {
143
158
type : HANDLE_CLOSE ,
144
- payload : false ,
159
+ payload : false
145
160
} ) ;
146
161
147
162
export const handleTransform = (
148
163
componentId : number ,
149
164
childId : number ,
150
165
{
151
- x, y, width, height,
152
- } : { x : number ; y : number ; width : number ; height : number } ,
166
+ x,
167
+ y,
168
+ width,
169
+ height
170
+ } : { x : number ; y : number ; width : number ; height : number }
153
171
) => ( {
154
172
type : HANDLE_TRANSFORM ,
155
173
payload : {
@@ -158,22 +176,22 @@ export const handleTransform = (
158
176
x,
159
177
y,
160
178
width,
161
- height,
162
- } ,
179
+ height
180
+ }
163
181
} ) ;
164
182
165
183
export const createApplication = ( {
166
184
path,
167
185
components = [ ] ,
168
186
genOption,
169
187
appName = 'reactype_app' ,
170
- exportAppBool,
188
+ exportAppBool
171
189
} : {
172
- path : string ;
173
- components : ComponentsInt ;
174
- genOption : number ;
175
- appName : string ;
176
- exportAppBool : boolean ;
190
+ path : string ;
191
+ components : ComponentsInt ;
192
+ genOption : number ;
193
+ appName : string ;
194
+ exportAppBool : boolean ;
177
195
} ) => ( dispatch : any ) => {
178
196
if ( genOption === 0 ) {
179
197
exportAppBool = false ;
@@ -182,47 +200,49 @@ exportAppBool: boolean;
182
200
appName,
183
201
path,
184
202
components,
185
- exportAppBool,
186
- } ) ,
203
+ exportAppBool
204
+ } )
187
205
) ;
188
206
} else if ( genOption ) {
189
207
exportAppBool = true ;
190
208
dispatch ( {
191
- type : CREATE_APPLICATION ,
209
+ type : CREATE_APPLICATION
192
210
} ) ;
193
211
createApplicationUtil ( {
194
212
path,
195
213
appName,
196
- genOption,
214
+ genOption
197
215
// exportAppBool
198
216
} )
199
217
. then ( ( ) => {
200
218
dispatch ( {
201
- type : CREATE_APPLICATION_SUCCESS ,
219
+ type : CREATE_APPLICATION_SUCCESS
202
220
} ) ;
203
221
dispatch (
204
222
exportFiles ( {
205
223
appName,
206
224
path,
207
225
components,
208
- exportAppBool,
209
- } ) ,
226
+ exportAppBool
227
+ } )
210
228
) ;
211
229
} )
212
- . catch ( err => dispatch ( {
213
- type : CREATE_APPLICATION_ERROR ,
214
- payload : { status : true , err } ,
215
- } ) ) ;
230
+ . catch ( ( err ) =>
231
+ dispatch ( {
232
+ type : CREATE_APPLICATION_ERROR ,
233
+ payload : { status : true , err }
234
+ } )
235
+ ) ;
216
236
}
217
237
} ;
218
238
219
239
export const openExpansionPanel = ( component : ComponentInt ) => ( {
220
240
type : OPEN_EXPANSION_PANEL ,
221
- payload : { component } ,
241
+ payload : { component }
222
242
} ) ;
223
243
224
244
export const deleteAllData = ( ) => ( {
225
- type : DELETE_ALL_DATA ,
245
+ type : DELETE_ALL_DATA
226
246
} ) ;
227
247
228
248
export const deleteProp = ( propId : number ) => ( dispatch : any ) => {
@@ -231,23 +251,29 @@ export const deleteProp = (propId: number) => (dispatch: any) => {
231
251
232
252
export const addProp = ( prop : PropInt ) => ( {
233
253
type : ADD_PROP ,
234
- payload : { ...prop } ,
254
+ payload : { ...prop }
235
255
} ) ;
236
256
237
- export const updateHtmlAttr = ( { attr, value } : { attr : string ; value : string } ) => (
238
- dispatch : any ,
239
- ) => {
257
+ export const updateHtmlAttr = ( {
258
+ attr,
259
+ value
260
+ } : {
261
+ attr : string ;
262
+ value : string ;
263
+ } ) => ( dispatch : any ) => {
240
264
dispatch ( {
241
265
type : UPDATE_HTML_ATTR ,
242
- payload : { attr, value } ,
266
+ payload : { attr, value }
243
267
} ) ;
244
268
} ;
245
269
246
- export const updateChildrenSort = ( { newSortValues } : { newSortValues : any } ) => (
247
- dispatch : any ,
248
- ) => {
270
+ export const updateChildrenSort = ( {
271
+ newSortValues
272
+ } : {
273
+ newSortValues : any ;
274
+ } ) => ( dispatch : any ) => {
249
275
dispatch ( {
250
276
type : UPDATE_CHILDREN_SORT ,
251
- payload : { newSortValues } ,
277
+ payload : { newSortValues }
252
278
} ) ;
253
279
} ;
0 commit comments