Update ImportModal and useKeyPress from review notes

This commit is contained in:
cihat 2022-06-17 18:52:40 +03:00
parent 22b1aaed47
commit 84ba94efd0
2 changed files with 7 additions and 10 deletions

View File

@ -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(() => {

View File

@ -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);