Browse Source

Update ImportModal and useKeyPress from review notes

cihat 3 years ago
parent
commit
84ba94efd0
2 changed files with 7 additions and 10 deletions
  1. 3 7
      src/containers/ImportModal/index.tsx
  2. 4 3
      src/hooks/useKeyPress.tsx

+ 3 - 7
src/containers/ImportModal/index.tsx

@@ -7,7 +7,7 @@ import { ConfigActionType } from "src/reducer/reducer";
 import { Modal, ModalProps } from "src/components/Modal";
 import { Button } from "src/components/Button";
 import { AiOutlineUpload } from "react-icons/ai";
-import useKeyPress from "../../hooks/useKeyPress";
+import useKeyPress from "src/hooks/useKeyPress";
 
 const StyledInput = styled.input`
   background: ${({ theme }) => theme.BACKGROUND_TERTIARY};
@@ -101,13 +101,9 @@ export const ImportModal: React.FC<ModalProps> = ({ visible, setVisible }) => {
   const handleEspacePress = useKeyPress("Escape");
   const handleEnterKeyPress = useKeyPress("Enter");
   React.useEffect(() => {
-    if (handleEspacePress) {
-      setVisible(false);
-    }
+    if (handleEspacePress) setVisible(false);
 
-    if (handleEnterKeyPress && (jsonFile || url)) {
-      handleImportFile();
-    }
+    if (handleEnterKeyPress && (jsonFile || url)) handleImportFile();
   }, [handleEspacePress, handleEnterKeyPress]);
 
   React.useEffect(() => {

+ 4 - 3
src/hooks/useKeyPress.tsx

@@ -1,7 +1,8 @@
-import { useState, useEffect } from "react";
+import React from "react";
 
 const useKeyPress = (targetKey) => {
-  const [keyPressed, setKeyPressed] = useState<boolean>(false);
+  const [keyPressed, setKeyPressed] = React.useState(false);
+
   function downHandler({ key }) {
     if (key === targetKey) {
       setKeyPressed(true);
@@ -12,7 +13,7 @@ const useKeyPress = (targetKey) => {
       setKeyPressed(false);
     }
   };
-  useEffect(() => {
+  React.useEffect(() => {
     window.addEventListener("keydown", downHandler);
     window.addEventListener("keyup", upHandler);