Skip to content

Commit 7b150f7

Browse files
committed
Commented edits
1 parent eb7085f commit 7b150f7

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const {
66
Menu,
77
shell,
88
dialog,
9-
ipcMain
9+
ipcMain,
10+
globalShortcut
1011
} = require('electron');
1112

1213
// Uncomment below for hot reloading during development
@@ -41,6 +42,10 @@ function openFile() {
4142
mainWindow.webContents.send('new-file', file);
4243
}
4344

45+
function escape() {
46+
mainWindow.webContents.send('escape');
47+
}
48+
4449
//functions to replace the default behavior of undo and redo
4550
function undo() {
4651
mainWindow.webContents.send('undo');
@@ -262,6 +267,9 @@ app.on('ready', () => {
262267
} else {
263268
createWindow();
264269
}
270+
globalShortcut.register('Escape', () => {
271+
escape();
272+
})
265273
});
266274

267275
// Quit when all windows are closed.

src/components/LeftColExpansionPanel.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
6363
// state/class toggles will be displayed when a component is focused
6464
const focusedToggle = isFocused() === 'focused' ? true : false;
6565

66+
//this function determines whether edit mode for component name should be entered or not
67+
//resets the title if 'escape' key is hit
6668
const handleEdit = () => {
6769
if (editMode !== id) {
6870
handleChangeName(title);
@@ -125,7 +127,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
125127
// button // commented out to disable materialUI hover shading effect. TBD if any adverse effects occur
126128
// style={{ color: 'red' }}
127129
onClick={() => {
128-
if (focusComponent.title !== title)
130+
if (focusComponent.title !== title) //changed the logic here so it only focuses if you click on a different card. Otherwise, you can't double click into edit mode for the title.
129131
changeFocusComponent({ title });
130132
}}
131133
>
@@ -147,32 +149,32 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
147149
{title}
148150
</Typography>
149151
) : (
150-
<TextField
152+
<TextField //show a text field for editing instead if edit mode entered
151153
id="filled"
152154
label="Change Component Name"
153155
defaultValue={title}
154156
variant="outlined"
155157
className={classes.text}
156158
InputProps={{
157-
className: classes.light,
159+
className: classes.light, //all of these styling makes the input box border, label, and text default to white.
158160
}}
159161
InputLabelProps={{
160162
className: classes.inputLabel,
161163
}}
162164
autoFocus
163-
onChange={e => handleChangeName(e.target.value)}
165+
onChange={e => handleChangeName(e.target.value)} //event handler for key press
164166
onKeyPress={ev => {
165-
if (ev.key === 'Enter') {
167+
if (ev.key === 'Enter') { //event handler for enter pressed
166168
handleEditComponent();
167169
ev.preventDefault();
168170
}
169171
}}
170-
onKeyUp={ev => {
171-
if (ev.keyCode === 27) {
172-
handleEdit();
173-
ev.preventDefault();
174-
}
175-
}}
172+
// onKeyUp={ev => { //the old escape handler, keeping it here just in case a bug in the main.js escape handler wasn't caught
173+
// if (ev.keyCode === 27) {
174+
// handleEdit();
175+
// ev.preventDefault();
176+
// }
177+
// }}
176178
/>
177179
)}
178180
{/* ALL OF THE STATE/CLASS TOGGLES AND LABELS ARE ONLY RENDERED IF THEIR COMPONENT IS THE FOCUSED COMPONENT

src/containers/AppContainer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface Props {
3232
undo(): void;
3333
redo(): void;
3434
tutorial: number;
35+
toggleEditMode(arg: {id: number}): void;
3536
}
3637

3738
//Type for the state that should not be assigned within the
@@ -67,6 +68,8 @@ const mapDispatchToProps = (dispatch: (arg: any) => void) => ({
6768
dispatch(actions.changeTutorial(tutorial)),
6869
undo: () => dispatch(actions.undo()),
6970
redo: () => dispatch(actions.redo()),
71+
toggleEditMode: ({ id }: { id: number }) =>
72+
dispatch(actions.toggleEditMode({ id })),
7073
});
7174

7275
class AppContainer extends Component<Props, State> {
@@ -111,6 +114,10 @@ class AppContainer extends Component<Props, State> {
111114
IPC.on('redo', () => {
112115
this.props.redo();
113116
});
117+
118+
IPC.on('escape', () => {
119+
this.props.toggleEditMode({id:-1});
120+
})
114121
}
115122

116123
handleNext = (tutorial: number) => {

src/containers/LeftContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,23 @@ class LeftContainer extends Component<LeftContPropsInt, StateInt> {
140140
});
141141
}
142142

143+
//this function is for handling the value of the new component name typed in
143144
handleChange = (event: any) => {
144145
const newValue: string = event.target.value;
145146
this.setState({
146147
componentName: newValue,
147148
});
148149
};
149150

151+
//this functions handles the values for an edited name being typed
150152
handleChangeName = (value: string) => {
151153
const newValue: string = value;
152154
this.setState({
153155
componentEditName: newValue,
154156
});
155157
};
156158

159+
157160
handleAddComponent = () => {
158161
this.props.addComponent({ title: this.state.componentName });
159162

@@ -169,7 +172,7 @@ class LeftContainer extends Component<LeftContPropsInt, StateInt> {
169172
title: this.state.componentEditName,
170173
});
171174

172-
// reset the currently added componentName state field to blank after adding
175+
// reset the currently added componentName state field to blank after editing
173176
this.setState({
174177
componentEditName: '',
175178
});

src/utils/componentReducer.util.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ export const toggleComponentClass = (
551551
};
552552
};
553553

554+
//a reducer function to see if component name editing mode should be entered
554555
export const toggleEditMode = (
555556
state: ApplicationStateInt,
556557
{ id }: { id: number }
@@ -566,6 +567,10 @@ export const toggleEditMode = (
566567
};
567568
};
568569

570+
/*For the function below, it first changes the title of the component being edited to the new name.
571+
Then, it checks for each child component that exists and make sure the names of those child components
572+
are changed as well. Otherwise, the code will break because when you focus on a component with the changed component
573+
as a child. */
569574
export const editComponent = (
570575
state: ApplicationStateInt,
571576
{ id, title }: { id: number; title: string }

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"module": "commonjs",
77
"target": "es6",
88
"jsx": "react",
9-
"lib": ["es5","es6", "dom", "es2017"],
9+
"lib": ["es6", "dom", "es2017"],
1010
"allowSyntheticDefaultImports": true
1111
},
1212
"include": ["./src/**/*"]

0 commit comments

Comments
 (0)