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