Skip to content

Commit 76fad4d

Browse files
committed
Add event emitter... but didn't even need to use it, for some shortcut keys.
1 parent bb5c22f commit 76fad4d

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

src/Components/AppDrawer.tsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Link } from 'react-router-dom';
2+
import { Link, withRouter } from 'react-router-dom';
33

44
import Drawer from '@material-ui/core/Drawer';
55
import MenuOpen from '@material-ui/icons/MenuOpen';
@@ -11,13 +11,34 @@ interface IDrawerState {
1111
drawerOpen: boolean;
1212
}
1313

14-
export class AppDrawer extends React.Component<any, IDrawerState> {
14+
class AppDrawerComponent extends React.Component<any, IDrawerState> {
15+
1516
constructor(p: any, s: IDrawerState) {
1617
super(p,s);
1718

1819
this.state = {
1920
drawerOpen: false,
2021
};
22+
23+
window.onkeypress = (e: KeyboardEvent) => {
24+
if (e.ctrlKey) {
25+
const { history } = this.props;
26+
27+
switch (e.key) {
28+
case 'd':
29+
history.push('/');
30+
break;
31+
case 'r':
32+
history.push('/records');
33+
break;
34+
case 'p':
35+
history.push('/reports');
36+
break;
37+
default:
38+
return false;
39+
}
40+
}
41+
}
2142
}
2243

2344
private _toggleDrawer = (): void => {
@@ -39,23 +60,28 @@ export class AppDrawer extends React.Component<any, IDrawerState> {
3960
<Typography
4061
variant="h3"
4162
>
42-
<Link onClick={this._toggleDrawer} to="/">Dashboard</Link>
63+
<Link onClick={this._toggleDrawer} to="/">Dashboard</Link><br/>
64+
<span className="shortcut-key">CTRL</span><span className="shortcut-plus">+</span><span className="shortcut-key">D</span>
4365
</Typography>
4466

4567
<Typography
4668
variant="h3"
4769
>
48-
<Link onClick={this._toggleDrawer} to="/records">Records</Link>
70+
<Link onClick={this._toggleDrawer} to="/records">Records</Link><br/>
71+
<span className="shortcut-key">CTRL</span><span className="shortcut-plus">+</span><span className="shortcut-key">R</span>
4972
</Typography>
5073

5174
<Typography
5275
variant="h3"
5376
>
54-
<Link onClick={this._toggleDrawer} to="/reports">Reports</Link>
77+
<Link onClick={this._toggleDrawer} to="/reports">Reports</Link><br/>
78+
<span className="shortcut-key">CTRL</span><span className="shortcut-plus">+</span><span className="shortcut-key">P</span>
5579
</Typography>
5680
</div>
5781
</Drawer>
5882
</>
5983
);
6084
}
61-
}
85+
}
86+
87+
export const AppDrawer = withRouter(AppDrawerComponent);

src/Components/app-drawer.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.drawer {
2-
width: 30vw;
2+
min-width: 30vw;
33
display: flex;
44
flex-direction: column;
55
align-items: left;
@@ -16,6 +16,7 @@
1616
.drawer a {
1717
text-decoration: none;
1818
color: white;
19+
padding-right: 1rem;
1920
}
2021

2122
.drawer a:visited {
@@ -32,4 +33,23 @@
3233
position: absolute;
3334
left: 0;
3435
top: 0;
36+
}
37+
38+
.shortcut-plus {
39+
font-size: 14px;
40+
line-height: 3rem;
41+
vertical-align: middle;
42+
padding: 8px;
43+
}
44+
.shortcut-key {
45+
font-size: 8px;
46+
line-height: 3rem;
47+
padding: 8px 12px;
48+
min-width: 2rem;
49+
vertical-align: middle;
50+
border: 1px solid rgb(145, 145, 145);
51+
border-radius: 4px;
52+
background-color: rgb(198, 198, 198);
53+
color: black;
54+
font-weight: 500;
3555
}

src/Utils/index.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const EventEmitter = {
2+
events: [],
3+
dispatch: (event, data) => {
4+
if (!this.events[event]) {
5+
return;
6+
}
7+
this.events[event].forEach(cb => cb(data));
8+
},
9+
subscribe: (event, cb) => {
10+
if (!this.events[event]) {
11+
return;
12+
}
13+
this.events[event].push(cb);
14+
}
15+
}
16+
17+
module.exports = {
18+
EventEmitter,
19+
};

src/index.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ body {
2121
.full-size-text {
2222
font-weight: 100;
2323
font-size: 4rem;
24-
2524
}

0 commit comments

Comments
 (0)