Skip to content

Commit be5568c

Browse files
committed
Merged conflicts with latest pull
2 parents e09c3f4 + 2716d6c commit be5568c

File tree

11 files changed

+223
-36
lines changed

11 files changed

+223
-36
lines changed

main.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ function openFile() {
4141
mainWindow.webContents.send('new-file', file);
4242
}
4343

44+
//functions to replace the default behavior of undo and redo
45+
function undo() {
46+
mainWindow.webContents.send('undo');
47+
}
48+
49+
function redo() {
50+
mainWindow.webContents.send('redo');
51+
}
52+
53+
4454
function toggleTutorial() {
4555
mainWindow.webContents.send('tutorial_clicked');
4656
}
@@ -107,8 +117,20 @@ const createWindow = () => {
107117
{
108118
label: 'Edit',
109119
submenu: [
110-
{ role: 'undo' },
111-
{ role: 'redo' },
120+
{
121+
label: 'Undo',
122+
accelerator: process.platform === 'darwin' ? 'Cmd+Z' : 'Ctrl+Z', //these hotkeys are a tad bit glitchy
123+
click() {
124+
undo();
125+
}
126+
},
127+
{
128+
label: 'Redo',
129+
accelerator: process.platform === 'darwin' ? 'Cmd+Shift+Z' : 'Ctrl+Shift+Z',
130+
click() {
131+
redo();
132+
}
133+
},
112134
{ type: 'separator' },
113135
{ role: 'cut' },
114136
{ role: 'copy' },

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@
124124
"redux": "^4.0.0",
125125
"redux-devtools-extension": "^2.13.5",
126126
"redux-logger": "^3.0.6",
127-
"redux-thunk": "^2.3.0"
127+
"redux-thunk": "^2.3.0",
128+
"redux-undo": "^1.0.1"
128129
},
129130
"devDependencies": {
130131
"@babel/preset-typescript": "^7.3.3",

src/actionTypes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ export const DELETE_IMAGE: string = 'DELETE_IMAGE';
3232
export const TOGGLE_STATE: string = 'TOGGLE_STATE';
3333
export const TOGGLE_CLASS: string = 'TOGGLE_CLASS';
3434
export const CHANGE_TUTORIAL: string = 'CHANGE_TUTORIAL';
35+
export const UNDO: string = 'UNDO';
36+
export const REDO: string = 'REDO';

src/actions/components.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
CHANGE_IMAGE_SOURCE,
3535
DELETE_IMAGE,
3636
CHANGE_TUTORIAL,
37+
UNDO,
38+
REDO,
3739
} from '../actionTypes/index';
3840

3941
import { loadState } from '../localStorage'; //this is a warning from 'localStorage' being a .js file instead of .ts. Convert to .ts to remove this warning.
@@ -55,14 +57,16 @@ export const loadInitData = () => (dispatch: (arg: Action) => void) => {
5557
dispatch({
5658
type: LOAD_INIT_DATA,
5759
payload: {
58-
data: data ? data.workspace : {},
60+
data: data
61+
? { ...data.workspace, history: [], historyIndex: 0, future: [] } //erase history upon opening app
62+
: {},
5963
},
6064
});
6165
});
6266
};
6367

6468
export const addComponent = ({ title }: { title: string }) => (
65-
dispatch: (arg: Action) => void,
69+
dispatch: (arg: Action) => void
6670
) => {
6771
dispatch({ type: ADD_COMPONENT, payload: { title } });
6872
};
@@ -114,14 +118,14 @@ export const deleteComponent = ({
114118
};
115119

116120
export const changeFocusComponent = ({ title }: { title: string }) => (
117-
dispatch: (arg: Action) => void,
121+
dispatch: (arg: Action) => void
118122
) => {
119123
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
120124
};
121125

122126
// make sure childId is being sent in
123127
export const changeFocusChild = ({ childId }: { childId: number }) => (
124-
dispatch: (arg: Action) => void,
128+
dispatch: (arg: Action) => void
125129
) => {
126130
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { childId } });
127131
};
@@ -163,13 +167,13 @@ export const exportFiles = ({
163167
dispatch({
164168
type: EXPORT_FILES_SUCCESS,
165169
payload: { status: true, dir: dir[0] },
166-
}),
170+
})
167171
)
168172
.catch((err: string) =>
169173
dispatch({
170174
type: EXPORT_FILES_ERROR,
171175
payload: { status: true, err },
172-
}),
176+
})
173177
);
174178
};
175179

@@ -186,7 +190,7 @@ export const handleTransform = (
186190
y,
187191
width,
188192
height,
189-
}: { x: number; y: number; width: number; height: number },
193+
}: { x: number; y: number; width: number; height: number }
190194
) => ({
191195
type: HANDLE_TRANSFORM,
192196
payload: {
@@ -220,7 +224,7 @@ export const createApplication = ({
220224
path,
221225
components,
222226
exportAppBool,
223-
}),
227+
})
224228
);
225229
} else if (genOption) {
226230
exportAppBool = true;
@@ -242,14 +246,14 @@ export const createApplication = ({
242246
path,
243247
components,
244248
exportAppBool,
245-
}),
249+
})
246250
);
247251
})
248252
.catch((err: string) =>
249253
dispatch({
250254
type: CREATE_APPLICATION_ERROR,
251255
payload: { status: true, err },
252-
}),
256+
})
253257
);
254258
}
255259
};
@@ -264,19 +268,19 @@ export const deleteAllData = () => ({
264268
});
265269

266270
export const deleteProp = (propId: number) => (
267-
dispatch: (arg: Action) => void,
271+
dispatch: (arg: Action) => void
268272
) => {
269273
dispatch({ type: DELETE_PROP, payload: propId });
270274
};
271275

272276
export const toggleComponentState = (id: string) => (
273-
dispatch: (arg: Action) => void,
277+
dispatch: (arg: Action) => void
274278
) => {
275279
dispatch({ type: TOGGLE_STATE, payload: id });
276280
};
277281

278282
export const toggleComponentClass = (id: string) => (
279-
dispatch: (arg: Action) => void,
283+
dispatch: (arg: Action) => void
280284
) => {
281285
dispatch({ type: TOGGLE_CLASS, payload: id });
282286
};
@@ -286,6 +290,16 @@ export const addProp = (prop: PropInt) => ({
286290
payload: { ...prop },
287291
});
288292

293+
294+
//action creators for undo and redo
295+
export const undo = () => ({
296+
type: UNDO,
297+
});
298+
299+
export const redo = () => ({
300+
type: REDO,
301+
});
302+
289303
export const updateHtmlAttr = ({
290304
attr,
291305
value,

src/components/LeftColExpansionPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
8080
{/* {This is the component responsible for the collapsing transition animation for each component card} */}
8181
<Collapse
8282
in={focusedToggle}
83-
collapsedHeight={'70px'}
84-
timeout={500} //The type for the Collapse component is asking for a string, but if you put in a string and not a number, the component itself breaks.
83+
collapsedHeight={'70px'} //The type for the Collapse component is asking for a string, but if you put in a string and not a number, the component itself breaks.
8584
style={{ borderRadius: '5px' }}
85+
timeout={500}
8686
>
8787
{/* NOT SURE WHY COLOR: RED IS USED, TRIED REMOVING IT AND NO VISIBLE CHANGE OCCURED. */}
8888
<Grid

src/components/Props.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ const styles = (theme: any) => ({
125125
}
126126
},
127127
dataTable: {
128+
border: '1px solid red',
128129
backgroundColor: 'red',
129-
width: '60%'
130+
width: '60%',
130131
},
131132
light: {
132133
color: '#eee'

src/components/Tutorial.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Tutorial extends Component<Props> {
207207
closeAfterTransition
208208
BackdropComponent={Backdrop}
209209
BackdropProps={{
210-
timeout: 500,
210+
timeout: {enter: 500, exit: 500},
211211
}}
212212
style={{
213213
display: 'grid',

src/containers/AppContainer.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ interface Props {
2929
loadInitData(): void;
3030
changeImagePath(imageSource: string): void;
3131
changeTutorial(tutorial: number): void;
32+
undo(): void;
33+
redo(): void;
3234
tutorial: number;
3335
}
3436

@@ -63,6 +65,8 @@ const mapDispatchToProps = (dispatch: (arg: any) => void) => ({
6365
//function to change the tutorial step
6466
changeTutorial: (tutorial: number) =>
6567
dispatch(actions.changeTutorial(tutorial)),
68+
undo: () => dispatch(actions.undo()),
69+
redo: () => dispatch(actions.redo()),
6670
});
6771

6872
class AppContainer extends Component<Props, State> {
@@ -82,7 +86,7 @@ class AppContainer extends Component<Props, State> {
8286
//it changes the imagesource in the global state to be whatever filepath it is
8387
//on the user's comp.
8488

85-
//TODO Fix event typing?
89+
//New File command listener
8690
IPC.on('new-file', (event: string, file: string) => {
8791
const image = new window.Image();
8892
image.src = file;
@@ -92,9 +96,21 @@ class AppContainer extends Component<Props, State> {
9296
this.setState({ image, changed: true });
9397
};
9498
});
99+
100+
//Tutorial command listener
95101
IPC.on('tutorial_clicked', () => {
96102
this.props.changeTutorial(1);
97103
});
104+
105+
//Undo command listener
106+
IPC.on('undo', () => {
107+
this.props.undo();
108+
});
109+
110+
//Redo command listener
111+
IPC.on('redo', () => {
112+
this.props.redo();
113+
});
98114
}
99115

100116
handleNext = (tutorial: number) => {

src/reducers/componentReducer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import {
3333
DELETE_PROP,
3434
UPDATE_HTML_ATTR,
3535
UPDATE_CHILDREN_SORT,
36+
UNDO,
37+
REDO,
3638
} from '../actionTypes/index';
3739

3840
import {
@@ -57,6 +59,8 @@ import {
5759
updateChildrenSort,
5860
toggleComponentState,
5961
toggleComponentClass,
62+
undo,
63+
redo
6064
} from '../utils/componentReducer.util';
6165
import cloneDeep from '../utils/cloneDeep';
6266

@@ -111,6 +115,9 @@ const initialApplicationState: ApplicationStateInt = {
111115
components: [appComponent],
112116
appDir: '',
113117
loading: false,
118+
history: [],
119+
historyIndex: 0,
120+
future: []
114121
};
115122

116123
const componentReducer = (state = initialApplicationState, action: Action) => {
@@ -171,6 +178,10 @@ const componentReducer = (state = initialApplicationState, action: Action) => {
171178
return updateHtmlAttr(state, action.payload);
172179
case UPDATE_CHILDREN_SORT:
173180
return updateChildrenSort(state, action.payload);
181+
case UNDO:
182+
return undo(state);
183+
case REDO:
184+
return redo(state);
174185
default:
175186
return state;
176187
}

src/utils/Interfaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ export interface ApplicationStateInt {
7676
components: ComponentsInt;
7777
appDir: string;
7878
loading: boolean;
79+
history: ApplicationStateInt[];
80+
historyIndex: number;
81+
future: ApplicationStateInt[];
7982
}
8083

84+
85+
8186
//Global Action interface \
8287
export interface Action {
8388
type: string;

0 commit comments

Comments
 (0)