Skip to content

Commit 9c50099

Browse files
author
john lim
committed
reverted back and added delete HTML functionality
1 parent a1e7c62 commit 9c50099

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

app/electron/menu.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ var MenuBuilder = function(mainWindow, appName) {
3131
devTools: false
3232
}
3333
});
34-
console.log(process.env.NODE_ENV);
3534
if (process.env.NODE_ENV === 'development') {
3635
tutorial.loadURL(`http://localhost:8080/#/tutorial`);}
37-
else {
36+
else if (process.env.NODE_ENV === 'production'){
3837
tutorial.loadURL(`${Protocol.scheme}://rse/index-prod.html#/tutorial`);
3938
}
4039
tutorial.show();

app/src/components/left/HTMLItem.tsx

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { useDrag } from 'react-dnd';
33
import { ItemTypes } from '../../constants/ItemTypes';
44
import Grid from '@material-ui/core/Grid';
55
import { makeStyles } from '@material-ui/core/styles';
6+
import List from '@material-ui/core/List';
7+
import ListItem from '@material-ui/core/ListItem';
8+
import ListItemText from '@material-ui/core/ListItemText';
9+
import createModal from '../right/createModal';
610

711
const buttonClasses =
812
'MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-button-12 MuiButton-textPrimary';
@@ -34,7 +38,7 @@ const HTMLItem: React.FC<{
3438
handleDelete: (id: number) => void;
3539
}> = ({ name, id, Icon, handleDelete }) => {
3640
const classes = useStyles();
37-
41+
const [modal, setModal] = useState(null);
3842
const [{ isDragging }, drag] = useDrag({
3943
item: {
4044
type: ItemTypes.INSTANCE,
@@ -48,8 +52,66 @@ const HTMLItem: React.FC<{
4852
})
4953
});
5054

55+
const closeModal = () => setModal(null);
56+
57+
// creates modal that asks if user wants to clear workspace
58+
// if user clears their workspace, then their components are removed from state and the modal is closed
59+
const deleteAllInstances = (deleteID: number) => {
60+
// set modal options
61+
const children = (
62+
<List className="export-preference">
63+
<ListItem
64+
key={`clear${deleteID}`}
65+
button
66+
onClick={() => handleDelete(deleteID)}
67+
style={{
68+
border: '1px solid #3f51b5',
69+
marginBottom: '2%',
70+
marginTop: '5%'
71+
}}
72+
>
73+
<ListItemText
74+
primary={'Yes, delete all instances'}
75+
style={{ textAlign: 'center' }}
76+
onClick={closeModal}
77+
/>
78+
</ListItem>
79+
<ListItem
80+
key={`close${deleteID}`}
81+
button
82+
onClick={closeModal}
83+
style={{
84+
border: '1px solid #3f51b5',
85+
marginBottom: '2%',
86+
marginTop: '5%'
87+
}}
88+
>
89+
<ListItemText
90+
primary={'No, do not delete element'}
91+
style={{ textAlign: 'center' }}
92+
onClick={closeModal}
93+
/>
94+
</ListItem>
95+
</List>
96+
);
97+
98+
// create modal
99+
setModal(
100+
createModal({
101+
closeModal,
102+
children,
103+
message: 'Deleting this element will delete all instances of this element within the application.\nDo you still wish to proceed?',
104+
primBtnLabel: null,
105+
primBtnAction: null,
106+
secBtnAction: null,
107+
secBtnLabel: null,
108+
open: true
109+
})
110+
);
111+
};
112+
51113
return (
52-
<Grid item xs={5} key={`html-${name}`}>
114+
<Grid item xs={5} key={`html-g${name}`}>
53115
<div ref={drag} className={classes.HTMLPanelItem}>
54116
<h3>{name}</h3>
55117
<span
@@ -62,8 +124,9 @@ const HTMLItem: React.FC<{
62124
{Icon && <Icon />}
63125
</span>
64126
{id > 11 &&
65-
<button className={buttonClasses} onClick={() => { handleDelete(id) }} > X </button> }
127+
<button className={buttonClasses} onClick={() => deleteAllInstances(id)} > X </button> }
66128
</div>
129+
{modal}
67130
</Grid>
68131
);
69132
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"postinstall": "ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES=true electron-builder install-app-deps",
3333
"dev-server": "cross-env NODE_ENV=development webpack-dev-server --config ./webpack.development.js",
3434
"dev": "concurrently --success first \"npm run dev-server\" \"cross-env NODE_ENV=development electron .\" \"cross-env NODE_ENV=development npm run server\" -k",
35+
"p": "concurrently --success first \"npm run dev-server\" \"cross-env NODE_ENV=production electron .\" \"cross-env NODE_ENV=production npm run server\" -k",
3536
"prod-build": "cross-env NODE_ENV=production npx webpack --mode=production --config ./webpack.production.js",
3637
"prod": "npm run prod-build && electron .",
3738
"pack": "electron-builder --dir",

0 commit comments

Comments
 (0)