@@ -751,6 +751,7 @@ const reducer = (state: State, action: Action) => {
751
751
components ,
752
752
state . canvasFocus . componentId
753
753
) ;
754
+ //will add update StateProps to current components' array
754
755
currComponent . stateProps . push ( action . payload . newState ) ;
755
756
currComponent . useStateCodes = updateUseStateCodes ( currComponent ) ;
756
757
currComponent . stateProps . push ( action . payload . setNewState ) ;
@@ -761,7 +762,6 @@ const reducer = (state: State, action: Action) => {
761
762
state . projectType ,
762
763
state . HTMLTypes
763
764
) ;
764
- console . log ( 'action.payload' , action . payload )
765
765
return { ...state , components} ;
766
766
}
767
767
/*
@@ -773,10 +773,9 @@ const reducer = (state: State, action: Action) => {
773
773
const components = [ ...state . components ] ;
774
774
const currComponent = findComponent (
775
775
components ,
776
- //legacyPD - tom
777
- // need to change this to match the id from the tree
778
776
state . canvasFocus . componentId
779
777
) ;
778
+ //find the parent for deleting instances of where the parent is passing props to children
780
779
let parent ;
781
780
for ( let i = 0 ; i < components . length ; i ++ ) {
782
781
let currComponent = components [ i ]
@@ -788,30 +787,36 @@ const reducer = (state: State, action: Action) => {
788
787
}
789
788
}
790
789
790
+ //search for whether the child exists in the parent's children array
791
+ //if so update the passed in props child element with the updates passed in props
791
792
parent . children . forEach ( ( child ) => {
792
793
if ( child . name === currComponent . name ) {
793
794
child . passedInProps . push ( action . payload . passedInProps ) ;
794
795
}
795
796
} )
796
797
797
798
798
- // do a check if prop already exists in passed in props
799
+ //prevents passing in props more than one time to the current component
799
800
for ( let i = 0 ; i < currComponent . passedInProps . length ; i ++ ) {
800
801
let curr = currComponent . passedInProps [ i ] ;
801
802
if ( curr . id === action . payload . passedInProps . id ) {
802
803
return { ...state , components} ;
803
804
}
804
805
}
806
+ // check each components passedInProps property and updating there as well.
805
807
currComponent . passedInProps . push ( action . payload . passedInProps ) ;
808
+
809
+ //update the import codes for the current component
806
810
currComponent . useStateCodes = updateUseStateCodes ( currComponent ) ;
807
-
811
+ //update code preview for current component
808
812
currComponent . code = generateCode (
809
813
components ,
810
814
state . canvasFocus . componentId ,
811
815
[ ...state . rootComponents ] ,
812
816
state . projectType ,
813
817
state . HTMLTypes
814
818
) ;
819
+ //update code preview for parent component (since we have added it to the children array)
815
820
parent . code = generateCode (
816
821
components ,
817
822
parent . id ,
@@ -830,7 +835,7 @@ const reducer = (state: State, action: Action) => {
830
835
state . canvasFocus . componentId
831
836
) ;
832
837
833
- //find the parent
838
+ //find the parent of the component that we are deleting from
834
839
let parent ;
835
840
for ( let i = 0 ; i < components . length ; i ++ ) {
836
841
let currComponent = components [ i ]
@@ -843,7 +848,7 @@ const reducer = (state: State, action: Action) => {
843
848
}
844
849
845
850
//deletes all instances of passedInProps from the children arrays of the current Component
846
- const pPKillahChildren = ( currComponent ) => {
851
+ const deletePassedInPropsChildren = ( currComponent ) => {
847
852
// when there are no children, return up a level
848
853
if ( ! currComponent . children ) return ;
849
854
currComponent . passedInProps ?. forEach ( ( prop , i ) => {
@@ -853,13 +858,14 @@ const reducer = (state: State, action: Action) => {
853
858
child . passedInProps . forEach ( ( prop , k ) => {
854
859
if ( prop . id === action . payload . rowId ) {
855
860
child . passedInProps . splice ( k , 1 ) ;
856
- pPKillahChildren ( child ) ;
861
+ deletePassedInPropsChildren ( child ) ;
857
862
}
858
863
} )
859
864
} )
860
865
}
861
866
}
862
867
} ) ;
868
+ //for every component we update, generate new code
863
869
currComponent . code = generateCode (
864
870
components ,
865
871
currComponent . id ,
@@ -868,9 +874,8 @@ const reducer = (state: State, action: Action) => {
868
874
state . HTMLTypes
869
875
)
870
876
}
871
-
872
- const pPKillah = ( myComponent ) => {
873
- console . log ( { myComponent} )
877
+ //delete from the components passedInProps array
878
+ const deletePassedInProps = ( myComponent ) => {
874
879
if ( myComponent . children . filter ( ( el ) => el . type === 'Component' ) . length === 0 ) {
875
880
if ( myComponent . passedInProps . length > 0 ) {
876
881
myComponent . passedInProps . forEach ( ( prop , index ) => {
@@ -895,8 +900,7 @@ const reducer = (state: State, action: Action) => {
895
900
myComponent . children . filter ( el => el . type === "Component" ) . forEach ( ( child , i ) => {
896
901
let next = components . find ( comp =>
897
902
comp . id === child . typeId ) ;
898
- console . log ( myComponent ) ;
899
- pPKillah ( next ) ;
903
+ deletePassedInProps ( next ) ;
900
904
} )
901
905
}
902
906
} )
@@ -910,66 +914,17 @@ const reducer = (state: State, action: Action) => {
910
914
) ;
911
915
}
912
916
913
- pPKillahChildren ( parent ) ;
914
- pPKillah ( currComponent ) ;
917
+ deletePassedInPropsChildren ( parent ) ;
918
+ deletePassedInProps ( currComponent ) ;
915
919
916
- /*
917
- Check whether the current component selected has passed in props and splices out that
918
- piece of state from the array.
919
- */
920
- // let index;
921
- // //find the index of the passedInProps array of the current component
922
- // for (let i = 0; i < currComponent.passedInProps.length; i++) {
923
- // if (currComponent.passedInProps[i].id === action.payload.rowId) {
924
- // index = i;
925
- // console.log({currComponent}, 'in delete passedi n props')
926
- // break;
927
- // }
928
- // }
929
- // // this loop identfies the parent so we can change the children array and modify the passedInProps
930
- // //AND we can splice the prop out of the child component's passedInProps
931
- // let parent;
932
- // for (let i = 0; i < components.length; i++){
933
- // let currComponent = components[i]
934
- // for (let j = 0; j < currComponent.children.length; j++) {
935
- // let currChild = currComponent.children[j];
936
- // if (currChild.typeId === state.canvasFocus.componentId) {
937
- // parent = currComponent;
938
- // }
939
- // currComponent.passedInProps?.forEach((prop, i) => {
940
- // if (prop.id === action.payload.rowId) {
941
- // currComponent.passedInProps.splice(i, 1);
942
- // }
943
- // })
944
920
945
- // }
946
- // }
947
- // //this loops splices the passedInProps from the parent components children array (this is needed
948
- // // for the code preview)
949
- // parent.children.forEach((child) => {
950
- // if (child.name === currComponent.name) {
951
- // child.passedInProps.splice(index, 1);
952
- // }
953
- // })
954
-
955
-
956
- // currComponent.passedInProps.splice(index, 1);
957
- // currComponent.useStateCodes = updateUseStateCodes(currComponent);
958
- // currComponent.code = generateCode(
959
- // components,
960
- // state.canvasFocus.componentId,
961
- // [...state.rootComponents],
962
- // state.projectType,
963
- // state.HTMLTypes
964
- // );
965
921
parent . code = generateCode (
966
922
components ,
967
923
parent . id ,
968
924
[ ...state . rootComponents ] ,
969
925
state . projectType ,
970
926
state . HTMLTypes
971
927
) ;
972
- console . log ( components )
973
928
return { ...state , components} ;
974
929
}
975
930
@@ -987,16 +942,13 @@ const reducer = (state: State, action: Action) => {
987
942
// in the passedInProps array within the children array of the component
988
943
// using the action.payload.rowId (variable name) and action.payload.otherId (setVariable name))
989
944
components . forEach ( ( component ) => {
990
- console . log ( 'component in for loop' , component ) ;
991
945
//find all instances of state within child elements and delete state
992
946
993
947
component . children . forEach ( ( child ) => {
994
- console . log ( 'child.passedinprops before delete' , child . passedInProps )
995
948
if ( child . type === 'Component' ) {
996
949
child . passedInProps . forEach ( ( prop , i ) => {
997
950
if ( prop . id === action . payload . rowId || prop . id === action . payload . otherId ) {
998
951
child . passedInProps . splice ( i , 1 ) ;
999
- console . log ( 'child.passedinprops after delete' , child . passedInProps )
1000
952
}
1001
953
} ) ;
1002
954
}
@@ -1008,9 +960,6 @@ const reducer = (state: State, action: Action) => {
1008
960
// using the action.payload.rowId (variable name) and action.payload.otherId (setVariable name))
1009
961
for ( let i = 0 ; i < component . passedInProps ?. length ; i ++ ) {
1010
962
if ( component . passedInProps [ i ] [ 'id' ] === action . payload . rowId || component . passedInProps [ i ] [ 'id' ] === action . payload . otherId ) {
1011
- console . log ( 'prop.id' , component . passedInProps [ i ] [ 'id' ] ) ;
1012
- console . log ( 'rowid' , action . payload . rowId )
1013
- console . log ( 'otherid' , action . payload . otherId )
1014
963
component . passedInProps . splice ( i , 1 ) ;
1015
964
i -- ;
1016
965
}
@@ -1021,26 +970,28 @@ const reducer = (state: State, action: Action) => {
1021
970
// check if a useContext if created and if the useContext contains the providerId
1022
971
// we then delete from the set, statesFromProvider, the row id, and regenerate the code
1023
972
// Ex: useContext {1: {statesFromProvider: Set, compLink, compText}, 2 : ..., 3 : ... }
1024
- // if(component.useContext && component.useContext[state.canvasFocus.componentId ]) {
1025
- // component.useContext[state.canvasFocus.componentId].statesFromProvider.delete(action.payload.rowId);
1026
- // // iterate over children to see where it is being used, then reset that compText/compLink/useState
1027
- // for (let child of component.children) {
1028
- // if (child.stateUsed) {
1029
- // if (child.stateUsed.compTextProviderId === currComponent.id && child.stateUsed.compTextPropsId === action.payload.rowId) {
1030
- // child.attributes.compText = '';
1031
- // delete child.stateUsed.compText;
1032
- // delete child.stateUsed.compTextProviderId;
1033
- // delete child.stateUsed.compTextPropsId;
1034
- // }
1035
- // if (child.stateUsed.compLinkProviderId === currComponent.id && child.stateUsed.compLinkPropsId === action.payload.rowId) {
1036
- // child.attributes.compLink = '';
1037
- // delete child.stateUsed.compLink;
1038
- // delete child.stateUsed.compLinkProviderId;
1039
- // delete child.stateUsed.compLinkPropsId;
1040
- // }
1041
- // }
1042
- // }
1043
- // }
973
+ if ( component . useContext && component . useContext [ state . canvasFocus . componentId ] ) {
974
+ component . useContext [ state . canvasFocus . componentId ] . statesFromProvider . delete ( action . payload . rowId ) ;
975
+ // iterate over children to see where it is being used, then reset that compText/compLink/useState
976
+ for ( let child of component . children ) {
977
+ if ( child . stateUsed ) {
978
+ if ( child . stateUsed . compTextProviderId === currComponent . id && child . stateUsed . compTextPropsId === action . payload . rowId ) {
979
+ child . attributes . compText = '' ;
980
+ delete child . stateUsed . compText ;
981
+ delete child . stateUsed . compTextProviderId ;
982
+ delete child . stateUsed . compTextPropsId ;
983
+ }
984
+ if ( child . stateUsed . compLinkProviderId === currComponent . id && child . stateUsed . compLinkPropsId === action . payload . rowId ) {
985
+ child . attributes . compLink = '' ;
986
+ delete child . stateUsed . compLink ;
987
+ delete child . stateUsed . compLinkProviderId ;
988
+ delete child . stateUsed . compLinkPropsId ;
989
+ }
990
+ }
991
+ }
992
+ }
993
+
994
+ // find parent
1044
995
let parent ;
1045
996
for ( let i = 0 ; i < components . length ; i ++ ) {
1046
997
let currComponent = components [ i ]
@@ -1051,7 +1002,6 @@ const reducer = (state: State, action: Action) => {
1051
1002
}
1052
1003
}
1053
1004
}
1054
- console . log ( 'ben parent' , { parent} )
1055
1005
if ( parent ) {
1056
1006
parent . code = generateCode (
1057
1007
components ,
@@ -1070,16 +1020,7 @@ const reducer = (state: State, action: Action) => {
1070
1020
state . projectType ,
1071
1021
state . HTMLTypes
1072
1022
) ;
1073
- console . log ( { component} ) ;
1074
1023
} ) ;
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
- // );
1083
1024
return { ...state , components} ;
1084
1025
}
1085
1026
default :
0 commit comments