From af2319aa6458a92caec2c09386fdf251502c03cb Mon Sep 17 00:00:00 2001
From: Jason <jason.daurus@gmail.com>
Date: Tue, 5 Jul 2016 22:28:00 +0800
Subject: [web] listen to window.onKeyDown

---
 web/src/js/components/ProxyApp.jsx | 58 +++++---------------------------------
 1 file changed, 7 insertions(+), 51 deletions(-)

(limited to 'web/src/js/components/ProxyApp.jsx')

diff --git a/web/src/js/components/ProxyApp.jsx b/web/src/js/components/ProxyApp.jsx
index e8c0e6d6..62b13932 100644
--- a/web/src/js/components/ProxyApp.jsx
+++ b/web/src/js/components/ProxyApp.jsx
@@ -12,23 +12,18 @@ import { Key } from '../utils.js'
 
 class ProxyAppMain extends Component {
 
-    static childContextTypes = {
-        returnFocus: PropTypes.func.isRequired,
-    }
-
     static contextTypes = {
         router: PropTypes.object.isRequired,
     }
 
-    constructor(props, context) {
-        super(props, context)
-
-        this.focus = this.focus.bind(this)
-        this.onKeyDown = this.onKeyDown.bind(this)
-    }
-
     componentWillMount() {
         this.props.appInit()
+        window.addEventListener('keydown', this.props.onKeyDown);
+    }
+
+    componentWillUnmount() {
+        this.props.appDestruct()
+        window.removeEventListener('keydown', this.props.onKeyDown);
     }
 
     componentWillReceiveProps(nextProps) {
@@ -42,49 +37,10 @@ class ProxyAppMain extends Component {
         }
     }
 
-    /**
-     * @todo listen to window's key events
-     */
-    componentDidMount() {
-        this.focus()
-    }
-
-    componentWillUnmount() {
-        this.props.appDestruct()
-    }
-
-    /**
-     * @todo use props
-     */
-    getChildContext() {
-        return { returnFocus: this.focus }
-    }
-
-    /**
-     * @todo remove it
-     */
-    focus() {
-        document.activeElement.blur()
-        window.getSelection().removeAllRanges()
-        ReactDOM.findDOMNode(this).focus()
-    }
-
-    /**
-     * @todo move to actions
-     * @todo bind on window
-     */
-    onKeyDown(e) {
-        if (e.ctrlKey) {
-            return
-        }
-        this.props.onKeyDown(e.keyCode)
-        e.preventDefault()
-    }
-
     render() {
         const { showEventLog, location, children, query } = this.props
         return (
-            <div id="container" tabIndex="0" onKeyDown={this.onKeyDown}>
+            <div id="container" tabIndex="0">
                 <Header ref="header" query={query} />
                 {React.cloneElement(
                     children,
-- 
cgit v1.2.3

