Skip to content

Commit 8fec947

Browse files
committed
Add shortkey for opening add new form
1 parent 42b2148 commit 8fec947

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

frontend/src/components/neuron/index.tsx

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { PlusOutlined, QuestionCircleOutlined } from "@ant-design/icons";
22
import { Button, Tour, TourProps, message, notification } from "antd";
3-
import { useRef, useState } from "react";
3+
import { useContext, useEffect, useRef, useState } from "react";
44
import { useSelector } from "react-redux";
55
import { FlexRow } from "../../common";
66

77
import { styled } from "styled-components";
8+
import { AppContext } from "../../App";
89
import Tooltip from "../../common/tooltip";
910
import {
1011
setNeuron,
@@ -31,15 +32,25 @@ const Ilearn = () => {
3132
const refCategoryFilter = useRef<any>(null);
3233
const refStudyButton = useRef<any>(null);
3334
const refIntervals = useRef<any>(null);
35+
3436
const [open, setOpen] = useState<boolean>(false);
37+
const [hasChanged, setHasChanged] = useState<boolean>(false);
38+
const [studyList, setStudyList] = useState<Neuron[]>([]);
39+
const [repititionDay, setRepititionDay] = useState<number>();
40+
const [showEditModal, setShowEditModal] = useState<boolean>(false);
41+
const [showStudyModal, setShowStudyModal] = useState<boolean>(false);
3542

36-
const [hasChanged, setHasChanged] = useState(false);
3743
const { selectedNode, selected } = useSelector((v: RootState) => v.neuron);
44+
const { keyEvent } = useContext(AppContext)!;
3845
const dispatch = useAppDispatch();
39-
const [studyList, setStudyList] = useState<Neuron[]>([]);
40-
const [repititionDay, setRepititionDay] = useState<number>();
41-
const [showEditModal, setShowEditModal] = useState(false);
42-
const [showStudyModal, setShowStudyModal] = useState(false);
46+
47+
useEffect(() => {
48+
// Ctrl+C opens a modal to add new
49+
if (keyEvent?.key === "c" && keyEvent.ctrlKey && !showEditModal && !showStudyModal) {
50+
keyEvent.preventDefault();
51+
setShowEditModal(true);
52+
}
53+
}, [keyEvent]);
4354

4455
const steps: TourProps["steps"] = [
4556
{

0 commit comments

Comments
 (0)