Skip to content

Commit 9a133d0

Browse files
small reducer changes
1 parent 8c428ad commit 9a133d0

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/utils/componentReducer.util.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ export const changeFocusComponent = (state, { title = state.focusComponent.title
370370
newFocusChild = newFocusComp.childrenArray.find(child => child.childId === newFocusComp.focusChildId);
371371
}
372372

373-
// if no docus child found .. reset
374373
if (!newFocusChild) {
375374
newFocusChild = cloneDeep(state.initialApplicationFocusChild);
376375
}
@@ -387,9 +386,6 @@ export const changeFocusComponent = (state, { title = state.focusComponent.title
387386
};
388387

389388
export const changeFocusChild = (state, { title, childId }) => {
390-
// just finds first child with given title, need to pass in specific childId somehow
391-
// maybe default to title if childId is unknown
392-
console.log('change foc comp reducer: childId: ', childId);
393389
const focComp = state.components.find(comp => comp.title === state.focusComponent.title);
394390
let newFocusChild = focComp.childrenArray.find(child => child.childId === childId);
395391

@@ -417,11 +413,12 @@ export const changeFocusChild = (state, { title, childId }) => {
417413

418414
export const changeComponentFocusChild = (state, { componentId, childId }) => {
419415
const component = state.components.find(comp => comp.id === componentId);
420-
component.focusChildId = childId;
416+
const modifiedComponent = cloneDeep(component);
417+
modifiedComponent.focusChildId = childId;
421418
const components = state.components.filter(comp => comp.id !== componentId);
422419
return {
423420
...state,
424-
components: [component, ...components],
421+
components: [modifiedComponent, ...components],
425422
};
426423
};
427424

@@ -600,7 +597,7 @@ export const addProp = (state, { key, value = null, required, type }) => {
600597
nextPropId: selectedComponent.nextPropId + 1,
601598
};
602599

603-
const newComponents = state.components.filter(comp => comp.id != selectedComponent.id);
600+
const newComponents = state.components.filter(comp => comp.id !== selectedComponent.id);
604601
newComponents.push(modifiedComponent);
605602
return {
606603
...state,
@@ -610,16 +607,15 @@ export const addProp = (state, { key, value = null, required, type }) => {
610607
};
611608

612609
export const deleteProp = (state, propId) => {
613-
console.log(`Hello. Delete prop talking. propId:${propId}`);
614610
if (!state.focusComponent.id) {
615611
console.log('Delete prop error. no focused component ');
616612
return state;
617613
}
618-
// make a deep copy of focusCOmponent. we are gonne be modifying that copy
614+
619615
const modifiedComponent = cloneDeep(state.components.find(comp => comp.id === state.focusComponent.id));
620616

621617
const indexToDelete = modifiedComponent.props.findIndex(prop => prop.id === propId);
622-
if (indexToDelete < 0) {
618+
if (indexToDelete === -1) {
623619
console.log(`Delete prop Error. Prop id:${propId} not found in ${modifiedComponent.title}`);
624620
return state;
625621
}
@@ -645,7 +641,6 @@ export const updateHtmlAttr = (state, { attr, value }) => {
645641
const modifiedChild = cloneDeep(state.focusChild);
646642
modifiedChild.HTMLInfo[attr] = value;
647643

648-
// make a deep copy of focusCOmponent. we are gonne be modifying that copy
649644
const modifiedComponent = cloneDeep(state.components.find(comp => comp.id === state.focusComponent.id));
650645

651646
modifiedComponent.childrenArray = modifiedComponent.childrenArray.filter(

0 commit comments

Comments
 (0)