mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-02-04 01:32:54 +08:00
Add useKeyPress hook to ImportModal
This commit is contained in:
parent
f4ee701225
commit
715a8971dc
@ -7,6 +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";
|
||||
|
||||
const StyledInput = styled.input`
|
||||
background: ${({ theme }) => theme.BACKGROUND_TERTIARY};
|
||||
@ -97,6 +98,19 @@ export const ImportModal: React.FC<ModalProps> = ({ visible, setVisible }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleEspacePress = useKeyPress("Escape");
|
||||
const handleEnterKeyPress = useKeyPress("Enter");
|
||||
React.useEffect(() => {
|
||||
if (handleEspacePress) {
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
if (handleEnterKeyPress) {
|
||||
console.log("test enter");
|
||||
handleImportFile();
|
||||
}
|
||||
}, [handleEspacePress, handleEnterKeyPress]);
|
||||
|
||||
React.useEffect(() => {
|
||||
return () => {
|
||||
setJsonFile(null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user