Browse Source

:new: コナミコマンドが入力されたことを検知できる

Kazuya_Nagase 7 years ago
parent
commit
9813f0f62e
2 changed files with 27 additions and 3 deletions
  1. 1 0
      src/client/js/app.js
  2. 26 3
      src/client/js/components/StaffCredit/StaffCredit.jsx

+ 1 - 0
src/client/js/app.js

@@ -306,6 +306,7 @@ const componentMappings = {
   'create-page-name-input': <PagePathAutoComplete crowi={crowi} initializedPath={pagePath} addTrailingSlash />,
   'rename-page-name-input': <PagePathAutoComplete crowi={crowi} initializedPath={pagePath} />,
   'duplicate-page-name-input': <PagePathAutoComplete crowi={crowi} initializedPath={pagePath} />,
+  
 };
 // additional definitions if data exists
 if (pageId) {

+ 26 - 3
src/client/js/components/StaffCredit/StaffCredit.jsx

@@ -1,4 +1,5 @@
 import React from 'react';
+import keydown from 'react-keydown';
 
 /**
  * Page staff credit component
@@ -7,12 +8,34 @@ import React from 'react';
  * @class StaffCredit
  * @extends {React.Component}
  */
+
 export default class StaffCredit extends React.Component {
 
+  constructor(props) {
+    super(props);
+
+    this.state = {
+      konamiCommand: ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', '5', '7', '3'],
+      userCommand: [],
+    };
+  }
+
+  @keydown('enter', 'up', 'down', 'right', 'left', '5', '7', '3')
+  check(event) {
+    if (this.state.konamiCommand[this.state.userCommand.length] === event.key) {
+      this.setState({ userCommand: this.state.userCommand.concat(event.key) });
+    }
+    else {
+      this.state.userCommand = [];
+    }
+  }
+
   render() {
-    return (
-      <div>スタッフロール</div>
-    );
+    const isRender = this.state.userCommand.length === this.state.konamiCommand.length;
+    if (isRender) {
+      return <div>スタッフロール</div>;
+    }
+    return null;
   }
 
 }