Skip to content

Commit 5b012b2

Browse files
author
john lim
committed
reducer changes
1 parent 3c20a26 commit 5b012b2

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

app/src/reducers/componentReducer.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
State,
44
Action,
55
Component,
6-
ChildElement
6+
ChildElement,
7+
HTMLType
78
} from '../interfaces/Interfaces';
89
import initialState from '../context/initialState';
910
import generateCode from '../helperFunctions/generateCode';
@@ -569,12 +570,24 @@ const reducer = (state: State, action: Action) => {
569570
}
570571

571572
case 'DELETE ELEMENT': {
572-
const HTMLTypes = [...state.HTMLTypes];
573-
for (let i = 0; i < HTMLTypes.length; i += 1) {
574-
if (HTMLTypes[i].id === action.payload) {
575-
HTMLTypes.splice(i, 1);
573+
let name: string = '';
574+
const HTMLTypes: HTMLType[] = [...state.HTMLTypes].filter(el => {
575+
if (el.id === action.payload) {
576+
name = el.tag;
576577
}
577-
}
578+
return el.id !== action.payload;
579+
});
580+
const components: Component[] = deleteById(action.payload, name);
581+
const rootComponents: number[] = updateRoots(components);
582+
components.forEach((el, i) => {
583+
el.code = generateCode(
584+
components,
585+
components[i].id,
586+
rootComponents,
587+
state.projectType,
588+
state.HTMLTypes
589+
);
590+
})
578591
return {
579592
...state,
580593
HTMLTypes

0 commit comments

Comments
 (0)