blob: a12c817ba20f10adc6370dd506124caa40a68e3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as actions from './search.actions'
class PanicButton extends Component {
constructor() {
super()
this.keydown = this.keydown.bind(this)
}
componentDidMount() {
document.addEventListener('keydown', this.keydown)
}
componentWillUnmount() {
document.removeEventListener('keydown', this.keydown)
}
keydown(e) {
if (e.keyCode === 27) {
this.panic()
}
}
panic() {
this.props.actions.panic()
this.props.history.push('/search/')
}
render() {
return (
<button className='btn panic' onClick={() => this.panic()}>
<span>⚠</span> Panic
</button>
)
}
}
const mapStateToProps = state => ({
})
const mapDispatchToProps = dispatch => ({
actions: bindActionCreators({ panic: actions.panic }, dispatch)
})
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(PanicButton))
|