Skip to content

Commit be891e0

Browse files
committed
deleting page functionality
1 parent fd0637e commit be891e0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

app/src/reducers/componentReducer.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ const reducer = (state: State, action: Action) => {
8787
return;
8888
};
8989

90+
const updateIds = (components: Array<Object>) => {
91+
components.forEach((comp, i) => comp.id = i + 1)
92+
}
93+
9094
switch (action.type) {
9195
// Add a new component type
9296
// add component to the component array and increment our counter for the componentId
@@ -164,6 +168,8 @@ const reducer = (state: State, action: Action) => {
164168
parentComponent.children.push(newChild);
165169
}
166170
// 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
171+
172+
167173
else {
168174
const directParent = findChild(parentComponent, childId);
169175
directParent.children.push(newChild);
@@ -287,18 +293,15 @@ const reducer = (state: State, action: Action) => {
287293
}
288294

289295
case 'DELETE PAGE': {
290-
const id = state.canvasFocus.componentId;
291-
console.log('id: ', id);
292-
293-
const components = [...state.components].filter(comp => comp.id !== id);
294-
console.log('components: ', components);
295-
const component = [...state.components].filter(comp => comp.id === id)[0];
296-
console.log('component: ', component);
297-
// const boo = isPage(id);
296+
const id: number = state.canvasFocus.componentId;
297+
// console.log('id: ', id);
298298

299-
// console.log('all components', state.components);
299+
const components = [...state.components].filter(comp => comp.id != id);
300+
// console.log('components: ', components);
301+
updateIds(components);
302+
// // console.log('all components', state.components);
300303

301-
const canvasFocus = { componentsId: 1 }
304+
const canvasFocus = { componentId: 1, childId: null }
302305
return {...state, components, canvasFocus}
303306
}
304307

0 commit comments

Comments
 (0)