1- import {
2- ComponentInt ,
3- ComponentsInt ,
4- PropInt
5- } from "../utils/interfaces" ;
1+ import { ComponentInt , ComponentsInt , PropInt } from '../utils/Interfaces.ts' ;
62
73import {
84 LOAD_INIT_DATA ,
@@ -26,38 +22,34 @@ import {
2622 ADD_PROP ,
2723 DELETE_ALL_DATA ,
2824 UPDATE_HTML_ATTR ,
29- UPDATE_CHILDREN_SORT
30- } from " ../actionTypes/index" ;
25+ UPDATE_CHILDREN_SORT ,
26+ } from ' ../actionTypes/index.js' ;
3127
32- import { loadState } from " ../localStorage" ;
33- import createFiles from " ../utils/createFiles.util" ;
34- import createApplicationUtil from " ../utils/createApplication.util" ;
28+ import { loadState } from ' ../localStorage' ;
29+ import createFiles from ' ../utils/createFiles.util.ts' ;
30+ import createApplicationUtil from ' ../utils/createApplication.util.ts' ;
3531
3632export const loadInitData = ( ) => ( dispatch : any ) => {
37- loadState ( ) . then ( ( data : any ) =>
38- dispatch ( {
39- type : LOAD_INIT_DATA ,
40- payload : {
41- data : data ? data . workspace : { }
42- }
43- } )
44- ) ;
33+ loadState ( ) . then ( ( data : any ) => dispatch ( {
34+ type : LOAD_INIT_DATA ,
35+ payload : {
36+ data : data ? data . workspace : { } ,
37+ } ,
38+ } ) ) ;
4539} ;
4640
47- export const addComponent = ( { title } : { title : string } ) => (
48- dispatch : any
49- ) => {
41+ export const addComponent = ( { title } : { title : string } ) => ( dispatch : any ) => {
5042 dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
5143} ;
5244
5345export const addChild = ( {
5446 title,
5547 childType,
56- HTMLInfo
48+ HTMLInfo,
5749} : {
58- title : string ;
59- childType : string ;
60- HTMLInfo : object ;
50+ title : string ;
51+ childType : string ;
52+ HTMLInfo : object ;
6153} ) => ( dispatch : any ) => {
6254 dispatch ( { type : ADD_CHILD , payload : { title, childType, HTMLInfo } } ) ;
6355} ;
@@ -69,104 +61,91 @@ export const deleteChild = ({}) => (dispatch: any) => {
6961
7062export const deleteComponent = ( {
7163 componentId,
72- stateComponents
64+ stateComponents,
7365} : {
74- componentId : number ;
75- stateComponents : ComponentsInt ;
66+ componentId : number ;
67+ stateComponents : ComponentsInt ;
7668} ) => ( dispatch : any ) => {
7769 // find all places where the "to be delted" is a child and do what u gotta do
78- stateComponents . forEach ( parent => {
79- parent . childrenArray
80- . filter ( child => child . childComponentId === componentId )
81- . forEach ( child => {
82- dispatch ( {
83- type : DELETE_CHILD ,
84- payload : {
85- parentId : parent . id ,
86- childId : child . childId ,
87- calledFromDeleteComponent : true
88- }
89- } ) ;
70+ stateComponents . forEach ( ( parent ) => {
71+ parent . childrenArray . filter ( child => child . childComponentId === componentId ) . forEach ( ( child ) => {
72+ dispatch ( {
73+ type : DELETE_CHILD ,
74+ payload : {
75+ parentId : parent . id ,
76+ childId : child . childId ,
77+ calledFromDeleteComponent : true ,
78+ } ,
9079 } ) ;
80+ } ) ;
9181 } ) ;
9282
9383 // change focus to APp
94- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : " App" } } ) ;
84+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : ' App' } } ) ;
9585 // after taking care of the children delete the component
9686 dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
9787} ;
9888
99- export const changeFocusComponent = ( { title } : { title : string } ) => (
100- dispatch : any
101- ) => {
89+ export const changeFocusComponent = ( { title } : { title : string } ) => ( dispatch : any ) => {
10290 dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
10391} ;
10492
10593// make sure childId is being sent in
106- export const changeFocusChild = ( { childId } : { childId : number } ) => (
107- dispatch : any
108- ) => {
94+ export const changeFocusChild = ( { childId } : { childId : number } ) => ( dispatch : any ) => {
10995 dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { childId } } ) ;
11096} ;
11197
11298export const changeComponentFocusChild = ( {
11399 componentId,
114- childId
100+ childId,
115101} : {
116- componentId : number ;
117- childId : number ;
102+ componentId : number ;
103+ childId : number ;
118104} ) => ( dispatch : any ) => {
119105 dispatch ( {
120106 type : CHANGE_COMPONENT_FOCUS_CHILD ,
121- payload : { componentId, childId }
107+ payload : { componentId, childId } ,
122108 } ) ;
123109} ;
124110
125111export const exportFiles = ( {
126112 components,
127113 path,
128114 appName,
129- exportAppBool
115+ exportAppBool,
130116} : {
131- components : ComponentsInt ;
132- path : string ;
133- appName : string ;
134- exportAppBool : boolean ;
117+ components : ComponentsInt ;
118+ path : string ;
119+ appName : string ;
120+ exportAppBool : boolean ;
135121} ) => ( dispatch : any ) => {
136122 // this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
137123 dispatch ( {
138- type : EXPORT_FILES
124+ type : EXPORT_FILES ,
139125 } ) ;
140126
141127 createFiles ( components , path , appName , exportAppBool )
142- . then ( dir =>
143- dispatch ( {
144- type : EXPORT_FILES_SUCCESS ,
145- payload : { status : true , dir : dir [ 0 ] }
146- } )
147- )
148- . catch ( err =>
149- dispatch ( {
150- type : EXPORT_FILES_ERROR ,
151- payload : { status : true , err }
152- } )
153- ) ;
128+ . then ( dir => dispatch ( {
129+ type : EXPORT_FILES_SUCCESS ,
130+ payload : { status : true , dir : dir [ 0 ] } ,
131+ } ) )
132+ . catch ( err => dispatch ( {
133+ type : EXPORT_FILES_ERROR ,
134+ payload : { status : true , err } ,
135+ } ) ) ;
154136} ;
155137
156138export const handleClose = ( ) => ( {
157139 type : HANDLE_CLOSE ,
158- payload : false
140+ payload : false ,
159141} ) ;
160142
161143export const handleTransform = (
162144 componentId : number ,
163145 childId : number ,
164146 {
165- x,
166- y,
167- width,
168- height
169- } : { x : number ; y : number ; width : number ; height : number }
147+ x, y, width, height,
148+ } : { x : number ; y : number ; width : number ; height : number } ,
170149) => ( {
171150 type : HANDLE_TRANSFORM ,
172151 payload : {
@@ -175,22 +154,22 @@ export const handleTransform = (
175154 x,
176155 y,
177156 width,
178- height
179- }
157+ height,
158+ } ,
180159} ) ;
181160
182161export const createApplication = ( {
183162 path,
184163 components = [ ] ,
185164 genOption,
186- appName = " reactype_app" ,
187- exportAppBool
165+ appName = ' reactype_app' ,
166+ exportAppBool,
188167} : {
189- path : string ;
190- components : ComponentsInt ;
191- genOption : number ;
192- appName : string ;
193- exportAppBool : boolean ;
168+ path : string ;
169+ components : ComponentsInt ;
170+ genOption : number ;
171+ appName : string ;
172+ exportAppBool : boolean ;
194173} ) => ( dispatch : any ) => {
195174 if ( genOption === 0 ) {
196175 exportAppBool = false ;
@@ -199,49 +178,47 @@ export const createApplication = ({
199178 appName,
200179 path,
201180 components,
202- exportAppBool
203- } )
181+ exportAppBool,
182+ } ) ,
204183 ) ;
205184 } else if ( genOption ) {
206185 exportAppBool = true ;
207186 dispatch ( {
208- type : CREATE_APPLICATION
187+ type : CREATE_APPLICATION ,
209188 } ) ;
210189 createApplicationUtil ( {
211190 path,
212191 appName,
213- genOption
192+ genOption,
214193 // exportAppBool
215194 } )
216195 . then ( ( ) => {
217196 dispatch ( {
218- type : CREATE_APPLICATION_SUCCESS
197+ type : CREATE_APPLICATION_SUCCESS ,
219198 } ) ;
220199 dispatch (
221200 exportFiles ( {
222201 appName,
223202 path,
224203 components,
225- exportAppBool
226- } )
204+ exportAppBool,
205+ } ) ,
227206 ) ;
228207 } )
229- . catch ( err =>
230- dispatch ( {
231- type : CREATE_APPLICATION_ERROR ,
232- payload : { status : true , err }
233- } )
234- ) ;
208+ . catch ( err => dispatch ( {
209+ type : CREATE_APPLICATION_ERROR ,
210+ payload : { status : true , err } ,
211+ } ) ) ;
235212 }
236213} ;
237214
238215export const openExpansionPanel = ( component : ComponentInt ) => ( {
239216 type : OPEN_EXPANSION_PANEL ,
240- payload : { component }
217+ payload : { component } ,
241218} ) ;
242219
243220export const deleteAllData = ( ) => ( {
244- type : DELETE_ALL_DATA
221+ type : DELETE_ALL_DATA ,
245222} ) ;
246223
247224export const deleteProp = ( propId : number ) => ( dispatch : any ) => {
@@ -250,29 +227,23 @@ export const deleteProp = (propId: number) => (dispatch: any) => {
250227
251228export const addProp = ( prop : PropInt ) => ( {
252229 type : ADD_PROP ,
253- payload : { ...prop }
230+ payload : { ...prop } ,
254231} ) ;
255232
256- export const updateHtmlAttr = ( {
257- attr,
258- value
259- } : {
260- attr : string ;
261- value : string ;
262- } ) => ( dispatch : any ) => {
233+ export const updateHtmlAttr = ( { attr, value } : { attr : string ; value : string } ) => (
234+ dispatch : any ,
235+ ) => {
263236 dispatch ( {
264237 type : UPDATE_HTML_ATTR ,
265- payload : { attr, value }
238+ payload : { attr, value } ,
266239 } ) ;
267240} ;
268241
269- export const updateChildrenSort = ( {
270- newSortValues
271- } : {
272- newSortValues : any ;
273- } ) => ( dispatch : any ) => {
242+ export const updateChildrenSort = ( { newSortValues } : { newSortValues : any } ) => (
243+ dispatch : any ,
244+ ) => {
274245 dispatch ( {
275246 type : UPDATE_CHILDREN_SORT ,
276- payload : { newSortValues }
247+ payload : { newSortValues } ,
277248 } ) ;
278249} ;
0 commit comments