mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-02-04 01:32:54 +08:00
Update ImportModal and useKeyPress from review notes
This commit is contained in:
parent
22b1aaed47
commit
84ba94efd0
@ -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(() => {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user