Skip to content

Commit 15d6a3f

Browse files
committed
added keybindings for undo and redo
1 parent d99e010 commit 15d6a3f

File tree

8 files changed

+34
-16
lines changed

8 files changed

+34
-16
lines changed

app/src/components/left/HTMLPanel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ const HTMLPanel = (props): JSX.Element => {
188188
onChange={handleTagChange}
189189
className={isThemeLight ? `${classes.input} ${classes.lightThemeFontColor}` : `${classes.input} ${classes.darkThemeFontColor}`}
190190
style={{ marginBottom: '10px' }}
191-
192191
/>
193192

194193
{(!tag.charAt(0).match(/[A-Za-z]/) || !alphanumeric(tag) || tag.trim() === '' || checkNameDupe(tag))

app/src/components/main/Canvas.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ function Canvas() {
3232
// make a deep clone of state
3333
const deepCopiedState = JSON.parse(JSON.stringify(state));
3434
state.past.push(deepCopiedState.components[0].children);
35-
console.log('state in snapShotFunc', state)
3635
};
3736

3837
// This hook will allow the user to drag items from the left panel on to the canvas

app/src/components/main/DirectChildHTMLNestable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const snapShotFunc = () => {
5454
drop: (item: any, monitor: DropTargetMonitor) => {
5555
const didDrop = monitor.didDrop();
5656
// takes a snapshot of state to be used in UNDO and REDO cases
57-
// snapShotFunc();
57+
snapShotFunc();
5858
if (didDrop) {
5959
return;
6060
}

app/src/components/top/NavBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@material-ui/core/styles';
88
import AppBar from '@material-ui/core/AppBar';
99
import Avatar from '@material-ui/core/Avatar';
10+
import Brightness3Icon from '@material-ui/icons/Brightness3';
1011
import Toolbar from '@material-ui/core/Toolbar';
1112
import Typography from '@material-ui/core/Typography';
1213
import Button from '@material-ui/core/Button';
@@ -29,7 +30,6 @@ import StateContext from '../../context/context';
2930
import logo from '../../public/icons/win/logo.png';
3031

3132

32-
3333
// ROUTING TO DASHBOARD
3434
import { Link } from "react-router-dom";
3535

app/src/containers/AppContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import RightContainer from './RightContainer';
88
import { theme1, theme2 } from '../public/styles/theme';
99

1010

11-
1211
export const styleContext = createContext({
1312
style: null,
1413
setStyle: null

app/src/containers/RightContainer.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import React, {
44
useEffect,
55
useMemo,
66
useRef,
7+
useCallback,
78
} from 'react';
8-
import initialState from '../context/initialState';
99
import { makeStyles } from '@material-ui/core/styles';
1010
import FormControl from '@material-ui/core/FormControl';
1111
import Select from '@material-ui/core/Select';
@@ -25,7 +25,8 @@ import List from '@material-ui/core/List';
2525
import ListItem from '@material-ui/core/ListItem';
2626
import ListItemText from '@material-ui/core/ListItemText';
2727
import createModal from '../components/right/createModal';
28-
import ComponentPanel from '../components/right/ComponentPanel'
28+
import ComponentPanel from '../components/right/ComponentPanel';
29+
import { keys } from '@material-ui/core/styles/createBreakpoints';
2930

3031
// need to pass in props to use the useHistory feature of react router
3132
const RightContainer = ({isThemeLight}): JSX.Element => {
@@ -44,11 +45,11 @@ const RightContainer = ({isThemeLight}): JSX.Element => {
4445
const { style } = useContext(styleContext);
4546
const [modal, setModal] = useState(null);
4647

47-
4848
const resetFields = () => {
4949
const style = configTarget.child
50-
? configTarget.child.style
51-
: configTarget.style;
50+
? configTarget.child.style
51+
: configTarget.style;
52+
console.log('styleContext style', style)
5253
setDisplayMode(style.display ? style.display : '');
5354
setFlexDir(style.flexDirection ? style.flexDirection : '');
5455
setFlexJustify(style.justifyContent ? style.justifyContent : '');
@@ -67,7 +68,7 @@ const RightContainer = ({isThemeLight}): JSX.Element => {
6768
// handles all input field changes, with specific updates called based on input's name
6869
const handleChange = (e: React.ChangeEvent<{ value: any }>) => {
6970
let inputVal = e.target.value;
70-
71+
console.log('inputVal', inputVal)
7172
switch (e.target.name) {
7273
case 'display':
7374
setDisplayMode(inputVal);
@@ -187,7 +188,7 @@ const RightContainer = ({isThemeLight}): JSX.Element => {
187188
if (compWidth !== '') styleObj.width = compWidth;
188189
if (compHeight !== '') styleObj.height = compHeight;
189190
if (BGColor !== '') styleObj.backgroundColor = BGColor;
190-
191+
191192
dispatch({
192193
type: 'UPDATE CSS',
193194
payload: { style: styleObj }
@@ -205,6 +206,18 @@ const redoAction = () => {
205206
dispatch({ type: 'REDO', payload: {} });
206207
};
207208

209+
const undoRedoKey = useCallback((e) => {
210+
(e.key === 'z' && e.metaKey && !e.shiftKey) ? undoAction() :
211+
(e.shiftKey && e.metaKey && e.key === 'z') ? redoAction() : '';
212+
}, []);
213+
214+
useEffect(() => {
215+
document.addEventListener("keydown", undoRedoKey);
216+
return () => {
217+
document.removeEventListener("keydown", undoRedoKey);
218+
};
219+
}, []);
220+
208221
// placeholder for handling deleting instance
209222
const handleDelete = () => {
210223
dispatch({ type: 'DELETE CHILD', payload: {} });
@@ -331,7 +344,7 @@ const redoAction = () => {
331344
className={classes.select}
332345
inputProps={{ className: isThemeLight ? `${classes.selectInput} ${classes.lightThemeFontColor}` : `${classes.selectInput} ${classes.darkThemeFontColor}` }}
333346
>
334-
<MenuItem value=""></MenuItem>
347+
<MenuItem value="">none</MenuItem>
335348
<MenuItem value={'block'}>block</MenuItem>
336349
<MenuItem value={'inline-block'}>inline-block</MenuItem>
337350
<MenuItem value={'flex'}>flex</MenuItem>
@@ -427,7 +440,7 @@ const redoAction = () => {
427440
className={classes.select}
428441
inputProps={{ className: isThemeLight ? `${classes.selectInput} ${classes.lightThemeFontColor}` : `${classes.selectInput} ${classes.darkThemeFontColor}` }}
429442
>
430-
<MenuItem value=""></MenuItem>
443+
<MenuItem value="">none</MenuItem>
431444
<MenuItem value={'auto'}>auto</MenuItem>
432445
<MenuItem value={'50%'}>50%</MenuItem>
433446
<MenuItem value={'25%'}>25%</MenuItem>
@@ -449,7 +462,7 @@ const redoAction = () => {
449462
className={classes.select}
450463
inputProps={{ className: isThemeLight ? `${classes.selectInput} ${classes.lightThemeFontColor}` : `${classes.selectInput} ${classes.darkThemeFontColor}` }}
451464
>
452-
<MenuItem value=""></MenuItem>
465+
<MenuItem value="">none</MenuItem>
453466
<MenuItem value={'auto'}>auto</MenuItem>
454467
<MenuItem value={'100%'}>100%</MenuItem>
455468
<MenuItem value={'50%'}>50%</MenuItem>
@@ -470,6 +483,7 @@ const redoAction = () => {
470483
inputProps={{ className: isThemeLight ? `${classes.selectInput} ${classes.lightThemeFontColor}` : `${classes.selectInput} ${classes.darkThemeFontColor}` }}
471484
value={BGColor}
472485
onChange={handleChange}
486+
placeholder="#B6B8B7"
473487
/>
474488
</FormControl>
475489
</div>
@@ -515,20 +529,24 @@ const redoAction = () => {
515529
</div>
516530
)}
517531
<div className = {classes.buttonRow}>
532+
{/* <HotKeys keyMap={undoKeyMap} handlers={undoHandlers}> */}
518533
<Button
519534
color="primary"
520535
className={classes.button}
521536
onClick={undoAction}
522537
>
523538
<i className="fas fa-undo"></i>
524539
</Button>
540+
{/* </HotKeys> */}
541+
{/* <HotKeys> */}
525542
<Button
526543
color="primary"
527544
className={classes.button}
528545
onClick={redoAction}
529546
>
530547
<i className="fas fa-redo"></i>
531548
</Button>
549+
{/* </HotKeys> */}
532550
</div>
533551
</div>
534552

app/src/reducers/componentReducer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ const reducer = (state: State, action: Action) => {
620620
state.components[0].children = state.past[state.past.length-1];
621621
//the last element of past array gets pushed into future;
622622
state.future.push(state.past.pop());
623+
624+
console.log('state in undo', state)
623625
//generate code for the Code Preview
624626
state.components.forEach((el, i) => {
625627
el.code = generateCode(
@@ -641,6 +643,8 @@ const reducer = (state: State, action: Action) => {
641643
state.components[0].children = state.future[state.future.length - 1];
642644
//the last element of the future array gets pushed into the past array and the last element of the future array gets popped off
643645
state.past.push(state.future.pop());
646+
647+
console.log('state in redo', state)
644648
//generate code for the Code Preview
645649
state.components.forEach((el, i) => {
646650
el.code = generateCode(

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@
198198
"nodemon": "^2.0.4",
199199
"postcss-loader": "^2.1.6",
200200
"sass-loader": "^7.0.3",
201-
"spectron": "^11.1.0",
202201
"style-loader": "^0.20.3",
203202
"supertest": "^4.0.2",
204203
"ts-jest": "^25.3.0",

0 commit comments

Comments
 (0)