Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

Update ImportModal and useKeyPress from review notes

cihat84ba94efd060
diff --git a/src/containers/ImportModal/index.tsx b/src/containers/ImportModal/index.tsx
index 464835a8..51a2bc23 100644
--- a/src/containers/ImportModal/index.tsx
+++ b/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(() => {
diff --git a/src/hooks/useKeyPress.tsx b/src/hooks/useKeyPress.tsx
index c0767c00..a3e5c77a 100644
--- a/src/hooks/useKeyPress.tsx
+++ b/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);