|
14 | 14 | // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
15 | 15 | // THIS SOFTWARE.
|
16 | 16 |
|
17 |
| - |
18 | 17 | // This component is based on flamebearer project
|
19 | 18 | // https://github.com/mapbox/flamebearer
|
20 | 19 |
|
| 20 | +import React, { useEffect } from "react"; |
| 21 | +import { connect } from "react-redux"; |
21 | 22 |
|
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"; |
32 | 24 |
|
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; |
40 | 27 |
|
41 | 28 | // 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(); |
45 | 33 | }
|
46 |
| - } |
47 |
| - |
| 34 | + }; |
48 | 35 |
|
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 | + }); |
52 | 42 |
|
53 |
| - render() { |
54 |
| - return <ShortcutConsumer> |
| 43 | + return ( |
| 44 | + <ShortcutConsumer> |
55 | 45 | {({ shortcuts }) => (
|
56 | 46 | <div>
|
57 |
| - <h2 style={{marginTop:0}}>🔥 Keyboard Shortcuts</h2> |
| 47 | + <h2 style={{ marginTop: 0 }}>🔥 Keyboard Shortcuts</h2> |
58 | 48 | <table className="shortcuts">
|
59 | 49 | <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 | + ))} |
66 | 62 | </tbody>
|
67 | 63 | </table>
|
68 | 64 | </div>
|
69 | 65 | )}
|
70 |
| - </ShortcutConsumer>; |
71 |
| - } |
| 66 | + </ShortcutConsumer> |
| 67 | + ); |
72 | 68 | }
|
73 | 69 |
|
74 |
| -export default connect( |
75 |
| - (x) => x, |
76 |
| - { } |
77 |
| -)(withShortcut(ShortcutsModal)); |
| 70 | +export default connect((x) => x, {})(withShortcut(ShortcutsModal)); |
0 commit comments