@@ -85,21 +85,25 @@ const reducer = (state: State, action: Action) => {
85
85
// update all ids and typeIds to match one another
86
86
const updateAllIds = ( comp : Component [ ] | ChildElement [ ] ) => {
87
87
// put components' names and ids into an obj
88
- const obj = { } ;
89
- comp . forEach ( ( el ) => {
90
- obj [ el . name ] = el . id ;
91
- } ) ;
88
+ const obj = { spr : 1000 , others : 1 } ;
89
+ // comp.forEach((el) => {
90
+ // if (!obj[el.name]) obj[el.name] = el.id;
91
+ // });
92
92
// for each of the components, if it has children, iterate through that children array
93
93
comp . forEach ( ( el ) => {
94
94
if ( el . children . length > 0 ) {
95
95
for ( let i = 0 ; i < el . children . length ; i ++ ) {
96
96
// update each child's childId
97
- el . children [ i ] . childId = i + 1 ;
98
- // if the child's name and id exists in the object
99
- if ( obj [ el . children [ i ] . name ] ) {
100
- // set the child's typeId to be the value in the object of the child's name key
101
- el . children [ i ] . typeId = obj [ el . children [ i ] . name ] ;
97
+ if ( el . children [ i ] . name === 'separator' ) {
98
+ el . children [ i ] . childId = obj [ 'spr' ] ++ ;
99
+ } else {
100
+ el . children [ i ] . childId = obj [ 'others' ] ++ ;
102
101
}
102
+ // // if the child's name and id exists in the object
103
+ // if (obj[el.children[i].name]) {
104
+ // // set the child's typeId to be the value in the object of the child's name key
105
+ // el.children[i].typeId = obj[el.children[i].name];
106
+ // }
103
107
// recursively call the updateAllIds function on the child's children array if
104
108
// the child's children array is greater than 0
105
109
if ( el . children [ i ] . children . length > 0 ) {
@@ -145,7 +149,7 @@ const reducer = (state: State, action: Action) => {
145
149
// component has a children array, iterate through the array of children
146
150
child . forEach ( ( el ) => {
147
151
if ( el . children . length ) {
148
- const arr = [ ] ;
152
+ const arr : ChildElement [ ] = [ ] ;
149
153
for ( let i = 0 ; i < el . children . length ; i ++ ) {
150
154
// check to see if the name variable doesn't match the name of the child
151
155
if ( el . children [ i ] . name !== name ) {
@@ -510,7 +514,6 @@ const reducer = (state: State, action: Action) => {
510
514
) ;
511
515
return { ...state , components } ;
512
516
}
513
- // ------------------------------------------- added code below -------------------------------------------
514
517
case 'UPDATE EVENTS' : {
515
518
const { events } = action . payload ;
516
519
if ( JSON . stringify ( events ) === '{}' ) return state ;
@@ -552,8 +555,6 @@ const reducer = (state: State, action: Action) => {
552
555
) ;
553
556
return { ...state , components } ;
554
557
}
555
- // ------------------------------------------- added code above -------------------------------------------
556
-
557
558
case 'DELETE CHILD' : {
558
559
// if in-focus instance is a top-level component and not a child, don't delete anything
559
560
if ( ! state . canvasFocus . childId ) return state ;
@@ -752,6 +753,7 @@ const reducer = (state: State, action: Action) => {
752
753
} ) ;
753
754
const components : Component [ ] = deleteById ( action . payload , name ) ;
754
755
const rootComponents : number [ ] = updateRoots ( components ) ;
756
+ const canvasFocus = { ...state . canvasFocus , childId : null } ;
755
757
components . forEach ( ( el , i ) => {
756
758
el . code = generateCode (
757
759
components ,
@@ -763,6 +765,7 @@ const reducer = (state: State, action: Action) => {
763
765
} ) ;
764
766
return {
765
767
...state ,
768
+ canvasFocus,
766
769
HTMLTypes
767
770
} ;
768
771
}
0 commit comments