Skip to content

Commit a9a6891

Browse files
fixed deleting passed props bugs
1 parent b264ab4 commit a9a6891

File tree

1 file changed

+58
-12
lines changed

1 file changed

+58
-12
lines changed

app/src/reducers/componentReducer.ts

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -853,13 +853,20 @@ const reducer = (state: State, action: Action) => {
853853
child.passedInProps.forEach((prop, k) => {
854854
if(prop.id === action.payload.rowId) {
855855
child.passedInProps.splice(k, 1);
856-
pPKillah(child);
856+
pPKillahChildren(child);
857857
}
858858
})
859859
})
860860
}
861861
}
862862
});
863+
currComponent.code = generateCode(
864+
components,
865+
currComponent.id,
866+
[...state.rootComponents],
867+
state.projectType,
868+
state.HTMLTypes
869+
)
863870
}
864871

865872
const pPKillah = (myComponent) => {
@@ -872,6 +879,14 @@ const reducer = (state: State, action: Action) => {
872879
}
873880
});
874881
}
882+
myComponent.useStateCodes = updateUseStateCodes(myComponent)
883+
myComponent.code = generateCode(
884+
components,
885+
myComponent.id,
886+
[...state.rootComponents],
887+
state.projectType,
888+
state.HTMLTypes
889+
);
875890
return;
876891
};
877892
myComponent.passedInProps.forEach((prop, i)=> {
@@ -885,9 +900,10 @@ const reducer = (state: State, action: Action) => {
885900
})
886901
}
887902
})
903+
myComponent.useStateCodes = updateUseStateCodes(myComponent)
888904
myComponent.code = generateCode(
889905
components,
890-
currComponent.id,
906+
myComponent.id,
891907
[...state.rootComponents],
892908
state.projectType,
893909
state.HTMLTypes
@@ -963,9 +979,13 @@ const reducer = (state: State, action: Action) => {
963979
components,
964980
state.canvasFocus.componentId
965981
);
982+
//updates the stateProps array to reflect total state initialized in component minus the selected state to be deleted
966983
currComponent.stateProps = action.payload.stateProps;
967984

968-
985+
//CHILDREN ARRAY LOOP (needed for code preview)
986+
//iterate through all components, starting from top, and delete ALL instances of deleted state (provided to us
987+
// in the passedInProps array within the children array of the component
988+
// using the action.payload.rowId (variable name) and action.payload.otherId (setVariable name))
969989
components.forEach((component) => {
970990
console.log('component in for loop', component);
971991
//find all instances of state within child elements and delete state
@@ -981,7 +1001,11 @@ const reducer = (state: State, action: Action) => {
9811001
});
9821002
}
9831003
})
984-
1004+
1005+
// COMPONENT LOOP (needed for tables in State Management Tab)
1006+
//iterate through all components, starting from top, and delete ALL instances of deleted state (provided to us
1007+
// in the passedInProps array within each component
1008+
// using the action.payload.rowId (variable name) and action.payload.otherId (setVariable name))
9851009
for (let i = 0; i < component.passedInProps?.length; i++) {
9861010
if (component.passedInProps[i]['id'] === action.payload.rowId || component.passedInProps[i]['id'] === action.payload.otherId) {
9871011
console.log('prop.id', component.passedInProps[i]['id']);
@@ -1017,6 +1041,27 @@ const reducer = (state: State, action: Action) => {
10171041
// }
10181042
// }
10191043
// }
1044+
let parent;
1045+
for (let i = 0; i < components.length; i++){
1046+
let currComponent = components[i]
1047+
for (let j = 0; j < currComponent.children.length; j++) {
1048+
let currChild = currComponent.children[j];
1049+
if (currChild.typeId === component.id) {
1050+
parent = currComponent;
1051+
}
1052+
}
1053+
}
1054+
console.log('ben parent', {parent})
1055+
if (parent) {
1056+
parent.code = generateCode(
1057+
components,
1058+
parent.id,
1059+
[...state.rootComponents],
1060+
state.projectType,
1061+
state.HTMLTypes
1062+
);
1063+
}
1064+
10201065
component.useStateCodes = updateUseStateCodes(component);
10211066
component.code = generateCode(
10221067
components,
@@ -1025,15 +1070,16 @@ const reducer = (state: State, action: Action) => {
10251070
state.projectType,
10261071
state.HTMLTypes
10271072
);
1073+
console.log({component});
10281074
});
1029-
currComponent.useStateCodes = updateUseStateCodes(currComponent);
1030-
currComponent.code = generateCode(
1031-
components,
1032-
state.canvasFocus.componentId,
1033-
[...state.rootComponents],
1034-
state.projectType,
1035-
state.HTMLTypes
1036-
);
1075+
// currComponent.useStateCodes = updateUseStateCodes(currComponent);
1076+
// currComponent.code = generateCode(
1077+
// components,
1078+
// state.canvasFocus.componentId,
1079+
// [...state.rootComponents],
1080+
// state.projectType,
1081+
// state.HTMLTypes
1082+
// );
10371083
return { ...state, components};
10381084
}
10391085
default:

0 commit comments

Comments
 (0)