Skip to content

Commit 96fc00a

Browse files
committed
line 600 appstateslice
1 parent af3676f commit 96fc00a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

app/src/redux/reducers/slice/appStateSlice.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,26 +493,31 @@ const appStateSlice = createSlice({
493493
);
494494
// find the moved element's former parent
495495
// delete the element from it's former parent's children array
496-
496+
if (component) {
497497
const { directParent, childIndexValue } = findParent(
498498
component,
499499
currentChildId
500500
);
501501
// BREAKING HERE during manipulation of positions. Sometimes get a null value when manipulating positions
502502
// Only run if the directParent exists
503503
if (directParent) {
504+
if (directParent.children) {
504505
const child = { ...directParent.children[childIndexValue] };
505506
directParent.children.splice(childIndexValue, 1);
506507
// if the childId is null, this signifies that we are adding a child to the top level component rather than another child element
507508
if (newParentChildId === null) {
508509
component.children.push(child);
510+
509511
}
510512
// 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
511513
else {
512514
const directParent = findChild(component, newParentChildId);
515+
if (directParent?.children) {
513516
directParent.children.push(child);
517+
}
514518
}
515519
}
520+
}
516521
let nextTopSeparatorId = state.nextTopSeparatorId;
517522
components[state.canvasFocus.componentId - 1].children =
518523
manageSeparators.mergeSeparator(
@@ -534,6 +539,8 @@ const appStateSlice = createSlice({
534539
);
535540
state.components = components;
536541
state.nextTopSeparatorId = nextTopSeparatorId;
542+
543+
}
537544
},
538545

539546
updateCss: (state, action) => {
@@ -543,7 +550,10 @@ const appStateSlice = createSlice({
543550
components,
544551
state.canvasFocus.componentId
545552
);
553+
// closed if statement at the end of the block
554+
if (component && state.canvasFocus.childId) {
546555
const targetChild = findChild(component, state.canvasFocus.childId);
556+
if(targetChild) {
547557
targetChild.style = style;
548558
component.code = generateCode(
549559
components,
@@ -555,6 +565,8 @@ const appStateSlice = createSlice({
555565
action.payload.contextParam
556566
);
557567
state.components = components;
568+
}
569+
}
558570
},
559571

560572
updateAttributes: (state, action) => {
@@ -565,8 +577,10 @@ const appStateSlice = createSlice({
565577
components,
566578
state.canvasFocus.componentId
567579
);
580+
// closed if statement at the end of the block
581+
if (component && state.canvasFocus.childId) {
568582
const targetChild = findChild(component, state.canvasFocus.childId);
569-
583+
if (targetChild) {
570584
targetChild.attributes = attributes;
571585

572586
component.code = generateCode(
@@ -579,6 +593,8 @@ const appStateSlice = createSlice({
579593
action.payload.contextParam
580594
);
581595
state.components = components;
596+
}
597+
}
582598
},
583599

584600
updateEvents: (state, action) => {

0 commit comments

Comments
 (0)