@@ -202,6 +202,7 @@ const reducer = (state: State, action: Action) => {
202
202
return state ;
203
203
204
204
const components = [ ...state . components ] ;
205
+
205
206
const newComponent = {
206
207
id : state . components . length + 1 ,
207
208
name : action . payload . componentName ,
@@ -224,6 +225,7 @@ const reducer = (state: State, action: Action) => {
224
225
} ;
225
226
226
227
const nextComponentId = state . nextComponentId + 1 ;
228
+ console . log ( 'add component' , components )
227
229
return {
228
230
...state ,
229
231
components,
@@ -242,7 +244,7 @@ const reducer = (state: State, action: Action) => {
242
244
243
245
const parentComponentId : number = state . canvasFocus . componentId ;
244
246
const components = [ ...state . components ] ;
245
-
247
+ console . log ( 'add child' , components )
246
248
247
249
// find component (an object) that we're adding a child to
248
250
const parentComponent = findComponent ( components , parentComponentId ) ;
@@ -327,11 +329,13 @@ const reducer = (state: State, action: Action) => {
327
329
} ;
328
330
const nextChildId = state . nextChildId + 1 ;
329
331
let nextTopSeparatorId = state . nextTopSeparatorId + 1 ;
330
-
331
- let addChildArray = components [ 0 ] . children ;
332
+ console . log ( 'canvasFocus' , canvasFocus )
333
+ console . log ( 'components' , components )
334
+ // let addChildArray = components[0].children;
335
+ let addChildArray = components [ canvasFocus . componentId - 1 ] . children
332
336
addChildArray = manageSeparators . mergeSeparator ( addChildArray , 1 ) ;
333
337
if ( directParent && directParent . name === 'separator' ) nextTopSeparatorId = manageSeparators . handleSeparators ( addChildArray , 'add' ) ;
334
- components [ 0 ] . children = addChildArray ;
338
+ components [ canvasFocus . componentId - 1 ] . children = addChildArray ;
335
339
336
340
return { ...state , components, nextChildId, canvasFocus, nextTopSeparatorId } ;
337
341
}
@@ -380,8 +384,8 @@ const reducer = (state: State, action: Action) => {
380
384
381
385
let nextTopSeparatorId = state . nextTopSeparatorId ;
382
386
383
- components [ 0 ] . children = manageSeparators . mergeSeparator ( components [ 0 ] . children , 0 ) ;
384
- nextTopSeparatorId = manageSeparators . handleSeparators ( components [ 0 ] . children , 'change position' )
387
+ components [ state . canvasFocus . componentId - 1 ] . children = manageSeparators . mergeSeparator ( components [ state . canvasFocus . componentId - 1 ] . children , 0 ) ;
388
+ nextTopSeparatorId = manageSeparators . handleSeparators ( components [ state . canvasFocus . componentId - 1 ] . children , 'change position' )
385
389
return { ...state , components, nextTopSeparatorId } ;
386
390
}
387
391
// Change the focus component and child
@@ -448,8 +452,9 @@ const reducer = (state: State, action: Action) => {
448
452
) ;
449
453
450
454
451
- let nextTopSeparatorId = manageSeparators . handleSeparators ( components [ 0 ] . children , 'delete' )
452
455
const canvasFocus = { ...state . canvasFocus , childId : null } ;
456
+ console . log ( 'before invoking handleSep' )
457
+ let nextTopSeparatorId = manageSeparators . handleSeparators ( components [ canvasFocus . componentId - 1 ] . children , 'delete' )
453
458
return { ...state , components, canvasFocus, nextTopSeparatorId } ;
454
459
}
455
460
@@ -538,7 +543,6 @@ const reducer = (state: State, action: Action) => {
538
543
case 'RESET STATE' : {
539
544
const nextChildId = 1 ;
540
545
const nextTopSeparatorId = 1000 ;
541
- const nextBottomSeparatorId = 5000 ;
542
546
const rootComponents = [ 1 ] ;
543
547
const nextComponentId = 2 ;
544
548
const canvasFocus = {
@@ -557,7 +561,6 @@ const reducer = (state: State, action: Action) => {
557
561
...state ,
558
562
nextChildId,
559
563
nextTopSeparatorId,
560
- nextBottomSeparatorId,
561
564
rootComponents,
562
565
nextComponentId,
563
566
components,
0 commit comments