Просмотр исходного кода

Merge pull request #2490 from weseek/imprv/gw2848

Imprv/gw2848
Yuki Takei 5 лет назад
Родитель
Сommit
fceb1134c9

+ 2 - 0
src/client/js/components/Hotkeys/Hotkeys.jsx

@@ -2,6 +2,7 @@ import React from 'react';
 import HotkeysDetector from '../HotkeysDetector/HotkeysDetector';
 import HotkeysDetector from '../HotkeysDetector/HotkeysDetector';
 import StaffCredit from '../StaffCredit/StaffCredit';
 import StaffCredit from '../StaffCredit/StaffCredit';
 import MirrorMode from '../MirrorMode/MirrorMode';
 import MirrorMode from '../MirrorMode/MirrorMode';
+import PageCreate from '../PageHotkeys/PageCreate';
 import PageEdit from '../PageHotkeys/PageEdit';
 import PageEdit from '../PageHotkeys/PageEdit';
 
 
 export default class Hotkeys extends React.Component {
 export default class Hotkeys extends React.Component {
@@ -14,6 +15,7 @@ export default class Hotkeys extends React.Component {
     this.supportClasses = [
     this.supportClasses = [
       StaffCredit,
       StaffCredit,
       MirrorMode,
       MirrorMode,
+      PageCreate,
       PageEdit,
       PageEdit,
     ];
     ];
     this.keymap = this.keymapSet();
     this.keymap = this.keymapSet();

+ 29 - 18
src/client/js/components/HotkeysDetector/HotkeysDetector.jsx

@@ -15,27 +15,38 @@ export default class HotkeysDetector extends React.Component {
   }
   }
 
 
   check(event) {
   check(event) {
-    this.setState({
-      userCommand: this.state.userCommand.concat(event.key),
-    });
-
-    // filters the corresponding hotkeys(keys) that the user has pressed so far
-    const tempUserCommand = this.state.userCommand;
-    this.processingCommands = this.hotkeyList.filter((value) => {
-      return value.slice(0, tempUserCommand.length).toString() === tempUserCommand.toString();
-    });
-
-    // executes if there were keymap that matches what the user pressed fully.
-    if ((this.processingCommands.length === 1) && (this.hotkeyList.find(ary => ary.toString() === this.state.userCommand.toString()))) {
-      this.props.onDetected(this.processingCommands[0]);
-      this.setState({
-        userCommand: [],
-      });
+    const target = event.target;
+    // ignore when target dom is input
+    const inputPattern = /^input|textinput|textarea$/i;
+    if (inputPattern.test(target.tagName) || target.isContentEditable) {
+      return;
     }
     }
-    else if (this.processingCommands.toString() === [].toString()) {
+
+    // don't fire when not needed
+    if (!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
+      console.log(event.key);
       this.setState({
       this.setState({
-        userCommand: [],
+        userCommand: this.state.userCommand.concat(event.key),
       });
       });
+
+      // filters the corresponding hotkeys(keys) that the user has pressed so far
+      const tempUserCommand = this.state.userCommand;
+      this.processingCommands = this.hotkeyList.filter((value) => {
+        return value.slice(0, tempUserCommand.length).toString() === tempUserCommand.toString();
+      });
+
+      // executes if there were keymap that matches what the user pressed fully.
+      if ((this.processingCommands.length === 1) && (this.hotkeyList.find(ary => ary.toString() === this.state.userCommand.toString()))) {
+        this.props.onDetected(this.processingCommands[0]);
+        this.setState({
+          userCommand: [],
+        });
+      }
+      else if (this.processingCommands.toString() === [].toString()) {
+        this.setState({
+          userCommand: [],
+        });
+      }
     }
     }
     return null;
     return null;
 
 

+ 42 - 0
src/client/js/components/PageHotkeys/PageCreate.jsx

@@ -0,0 +1,42 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import NavigationContainer from '../../services/NavigationContainer';
+import { withUnstatedContainers } from '../UnstatedUtils';
+
+
+/**
+ *
+ * @export
+ * @extends {React.Component}
+ */
+
+export default class PageCreate extends React.Component {
+
+  // when this is called it returns the hotkey stroke
+  static getHotkeyStroke() {
+    return ['c'];
+  }
+
+  static getComponent() {
+    const PageCreateWrapper = withUnstatedContainers(PageCreate, [NavigationContainer]);
+    return <PageCreateWrapper />;
+  }
+
+  componentDidMount() {
+    this.props.navigationContainer.openPageCreateModal();
+    return null;
+  }
+
+  render() {
+    return (
+      <React.Fragment>
+      </React.Fragment>
+    );
+  }
+
+}
+
+
+PageCreate.propTypes = {
+  navigationContainer: PropTypes.instanceOf(NavigationContainer).isRequired,
+};

+ 0 - 20
src/client/js/services/NavigationContainer.js

@@ -36,8 +36,6 @@ export default class NavigationContainer extends Container {
 
 
     this.openPageCreateModal = this.openPageCreateModal.bind(this);
     this.openPageCreateModal = this.openPageCreateModal.bind(this);
     this.closePageCreateModal = this.closePageCreateModal.bind(this);
     this.closePageCreateModal = this.closePageCreateModal.bind(this);
-
-    this.initHotkeys();
     this.initDeviceSize();
     this.initDeviceSize();
     this.initScrollEvent();
     this.initScrollEvent();
   }
   }
@@ -49,24 +47,6 @@ export default class NavigationContainer extends Container {
     return 'NavigationContainer';
     return 'NavigationContainer';
   }
   }
 
 
-  initHotkeys() {
-    window.addEventListener('keydown', (event) => {
-      const target = event.target;
-
-      // ignore when target dom is input
-      const inputPattern = /^input|textinput|textarea$/i;
-      if (inputPattern.test(target.tagName) || target.isContentEditable) {
-        return;
-      }
-
-      if (event.key === 'c') {
-        // don't fire when not needed
-        if (!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
-          this.setState({ isPageCreateModalShown: true });
-        }
-      }
-    });
-  }
 
 
   initDeviceSize() {
   initDeviceSize() {
     const mdOrAvobeHandler = async(mql) => {
     const mdOrAvobeHandler = async(mql) => {