Skip to content

Commit 8fba659

Browse files
committed
Lint & Modernize ShortcutsModal
1 parent fb27aea commit 8fba659

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

webapp/javascript/components/ShortcutsModal.jsx

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,57 @@
1414
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
1515
// THIS SOFTWARE.
1616

17-
1817
// This component is based on flamebearer project
1918
// https://github.com/mapbox/flamebearer
2019

20+
import React, { useEffect } from "react";
21+
import { connect } from "react-redux";
2122

22-
import React from 'react';
23-
import {connect} from 'react-redux';
24-
import clsx from "clsx";
25-
26-
import { withShortcut, ShortcutConsumer } from 'react-keybind'
27-
28-
class ShortcutsModal extends React.Component {
29-
constructor (props){
30-
super(props);
31-
}
23+
import { withShortcut, ShortcutConsumer } from "react-keybind";
3224

33-
componentDidMount = () => {
34-
window.document.addEventListener('keydown', this.handleKeyDown);
35-
}
36-
37-
componentWillUnMount = () => {
38-
window.document.removeEventListener('keydown', this.handleKeyDown);
39-
}
25+
function ShortcutsModal(props) {
26+
const { closeModal } = props;
4027

4128
// react-keybind doesn't work with modals
42-
handleKeyDown = (event) => {
43-
if (event.keyCode == 27) { // esc
44-
this.props.closeModal();
29+
const handleKeyDown = (event) => {
30+
if (event.keyCode === 27) {
31+
// esc
32+
closeModal();
4533
}
46-
}
47-
34+
};
4835

49-
closeModal = () => {
50-
this.props.closeModal();
51-
}
36+
useEffect(() => {
37+
window.document.addEventListener("keydown", handleKeyDown);
38+
return function cleanup() {
39+
window.document.removeEventListener("keydown", handleKeyDown);
40+
};
41+
});
5242

53-
render() {
54-
return <ShortcutConsumer>
43+
return (
44+
<ShortcutConsumer>
5545
{({ shortcuts }) => (
5646
<div>
57-
<h2 style={{marginTop:0}}>🔥 Keyboard Shortcuts</h2>
47+
<h2 style={{ marginTop: 0 }}>🔥 Keyboard Shortcuts</h2>
5848
<table className="shortcuts">
5949
<tbody>
60-
{shortcuts.filter(x => x.title !== "Skip").map((x) => {
61-
return <tr key={x.id} className="shortcut">
62-
<td style={{paddingRight: '20px'}}><tt>{x.keys}</tt></td>
63-
<td><span>{x.description}</span></td>
64-
</tr>
65-
})}
50+
{shortcuts
51+
.filter((x) => x.title !== "Skip")
52+
.map((x) => (
53+
<tr key={x.id} className="shortcut">
54+
<td style={{ paddingRight: "20px" }}>
55+
<tt>{x.keys}</tt>
56+
</td>
57+
<td>
58+
<span>{x.description}</span>
59+
</td>
60+
</tr>
61+
))}
6662
</tbody>
6763
</table>
6864
</div>
6965
)}
70-
</ShortcutConsumer>;
71-
}
66+
</ShortcutConsumer>
67+
);
7268
}
7369

74-
export default connect(
75-
(x) => x,
76-
{ }
77-
)(withShortcut(ShortcutsModal));
70+
export default connect((x) => x, {})(withShortcut(ShortcutsModal));

0 commit comments

Comments
 (0)