Skip to content

Commit d53e993

Browse files
committed
keypress func
1 parent 1d4e49d commit d53e993

1 file changed

Lines changed: 34 additions & 20 deletions

File tree

duct-drone-app/src/App.jsx

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ import './App.css';
1717

1818
/* eslint-disable react/prefer-stateless-function */
1919
class App extends Component {
20+
constructor(props){
21+
super(props);
22+
this.escFunction = this.escFunction.bind(this);
23+
}
24+
escFunction = (event) => {
25+
console.log(event.key);
26+
}
27+
componentDidMount(){
28+
document.addEventListener("keydown", this.escFunction, false);
29+
}
30+
componentWillUnmount(){
31+
document.removeEventListener("keydown", this.escFunction, false);
32+
}
2033
render() {
2134
const currentDataCols = [
2235
{
@@ -90,27 +103,28 @@ class App extends Component {
90103
},
91104
];
92105
return (
93-
<Router>
94-
<Container>
95-
<Row style={{ height: '100%', width: '100%', border: 'black' }}>
96-
<Col><div className="Sidebar"><Sidebar /></div></Col>
97-
<Col xs={9}>
98-
<div id="feed" />
99-
<div id="action-bar">
100-
<Switch>
101-
<Route path="/" exact component={Control} />
102-
<Route path="/data/" component={() => <DataTable columns={currentDataCols} data={currentData} />} />
103-
<Route path="/logs/" component={() => <DataTable columns={logCols} data={logData} />} />
104-
</Switch>
105-
<Navigation />
106-
</div>
107-
108-
</Col>
109-
<Col />
110-
</Row>
106+
<div onKeyPress={(e) => console.log(e.key)}>
107+
<Router>
108+
<Container>
109+
<Row style={{ height: '100%', width: '100%', border: 'black' }}>
110+
<Col><div className="Sidebar"><Sidebar /></div></Col>
111+
<Col xs={9}>
112+
<div id="feed" />
113+
<div id="action-bar">
114+
<Switch>
115+
<Route path="/" exact component={Control} />
116+
<Route path="/data/" component={() => <DataTable columns={currentDataCols} data={currentData} />} />
117+
<Route path="/logs/" component={() => <DataTable columns={logCols} data={logData} />} />
118+
</Switch>
119+
<Navigation />
120+
</div>
121+
</Col>
122+
<Col />
123+
</Row>
124+
</Container>
125+
</Router>
126+
</div>
111127

112-
</Container>
113-
</Router>
114128
);
115129
}
116130
}

0 commit comments

Comments
 (0)