@@ -87,6 +87,10 @@ const reducer = (state: State, action: Action) => {
87
87
return ;
88
88
} ;
89
89
90
+ const updateIds = ( components : Array < Object > ) => {
91
+ components . forEach ( ( comp , i ) => comp . id = i + 1 )
92
+ }
93
+
90
94
switch ( action . type ) {
91
95
// Add a new component type
92
96
// add component to the component array and increment our counter for the componentId
@@ -164,6 +168,8 @@ const reducer = (state: State, action: Action) => {
164
168
parentComponent . children . push ( newChild ) ;
165
169
}
166
170
// if there is a childId (childId here references the direct parent of the new child) find that child and a new child to its children array
171
+
172
+
167
173
else {
168
174
const directParent = findChild ( parentComponent , childId ) ;
169
175
directParent . children . push ( newChild ) ;
@@ -287,18 +293,15 @@ const reducer = (state: State, action: Action) => {
287
293
}
288
294
289
295
case 'DELETE PAGE' : {
290
- const id = state . canvasFocus . componentId ;
291
- console . log ( 'id: ' , id ) ;
292
-
293
- const components = [ ...state . components ] . filter ( comp => comp . id !== id ) ;
294
- console . log ( 'components: ' , components ) ;
295
- const component = [ ...state . components ] . filter ( comp => comp . id === id ) [ 0 ] ;
296
- console . log ( 'component: ' , component ) ;
297
- // const boo = isPage(id);
296
+ const id : number = state . canvasFocus . componentId ;
297
+ // console.log('id: ', id);
298
298
299
- // console.log('all components', state.components);
299
+ const components = [ ...state . components ] . filter ( comp => comp . id != id ) ;
300
+ // console.log('components: ', components);
301
+ updateIds ( components ) ;
302
+ // // console.log('all components', state.components);
300
303
301
- const canvasFocus = { componentsId : 1 }
304
+ const canvasFocus = { componentId : 1 , childId : null }
302
305
return { ...state , components, canvasFocus}
303
306
}
304
307
0 commit comments