Skip to content

Commit b5b5ccf

Browse files
Merge pull request #3 from stormikph/deletePages
Delete pages
2 parents c3caf96 + 7f84fe6 commit b5b5ccf

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

app/src/containers/RightContainer.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ const RightContainer = (props): JSX.Element => {
131131
state.canvasFocus.componentId
132132
]);
133133

134+
const isPage = (configTarget) : boolean => {
135+
const { components, rootComponents } = state;
136+
return components
137+
.filter(component => rootComponents.includes(component.id))
138+
.some(el => el.id === configTarget.id);
139+
}
140+
134141
// dispatch to 'UPDATE CSS' called when save button is clicked,
135142
// passing in style object constructed from all changed input values
136143
const handleSave = (): Object => {
@@ -156,6 +163,10 @@ const RightContainer = (props): JSX.Element => {
156163
dispatch({ type: 'DELETE CHILD', payload: {} });
157164
};
158165

166+
const handlePageDelete = (id) => () => {
167+
dispatch({ type: 'DELETE PAGE', payload: { id }});
168+
}
169+
159170
const handleDeleteReusableComponent = () => {
160171
dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
161172
}
@@ -367,19 +378,29 @@ const RightContainer = (props): JSX.Element => {
367378
DELETE INSTANCE
368379
</Button>
369380
</div>
370-
) : isReusable(configTarget) ?
371-
(
381+
) : (isPage(configTarget) ? (
382+
<div className={classes.buttonRow}>
383+
<Button
384+
color="secondary"
385+
className={classes.button}
386+
onClick={handlePageDelete(configTarget.id)}
387+
>
388+
DELETE PAGE
389+
</Button>
390+
</div>
391+
) : isReusable(configTarget) ? (
372392
<div className={classes.buttonRow}>
373393
<Button
374394
color="secondary"
375395
className={classes.button}
376396
onClick={handleDeleteReusableComponent}
377-
>
378-
DELETE REUSABLE COMPONENT
397+
>
398+
DELETE PAGE
379399
</Button>
380400
</div>
381-
) : ''
382-
}
401+
) :
402+
''
403+
)}
383404
</div>
384405
<ProjectManager />
385406
</div>

app/src/reducers/componentReducer.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ const reducer = (state: State, action: Action) => {
186186
parentComponent.children.push(newChild);
187187
}
188188
// 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
189+
190+
189191
else {
190192
const directParent = findChild(parentComponent, childId);
191193
directParent.children.push(newChild);
@@ -310,6 +312,18 @@ const reducer = (state: State, action: Action) => {
310312
return { ...state, components, canvasFocus };
311313
}
312314

315+
case 'DELETE PAGE': {
316+
const id: number = state.canvasFocus.componentId;
317+
// console.log('id: ', id);
318+
319+
const components = [...state.components].filter(comp => comp.id != id);
320+
// console.log('components: ', components);
321+
updateIds(components);
322+
// // console.log('all components', state.components);
323+
324+
const canvasFocus = { componentId: 1, childId: null }
325+
return {...state, components, canvasFocus}
326+
}
313327
case 'DELETE REUSABLE COMPONENT' : {
314328
// TODO: bug when deleting element inside page
315329
// can't edit component name

0 commit comments

Comments
 (0)