From c1cb8069fec3d179ca58c64525f6030614226d41 Mon Sep 17 00:00:00 2001 From: Rowadz Date: Tue, 3 Oct 2023 19:59:06 +0200 Subject: [PATCH] add keyboards shortcuts --- src/App.tsx | 79 +++++++++++-------- src/components/Header.tsx | 2 +- .../ModelsComponents/ModelHeader.tsx | 9 +-- src/index.js | 5 +- src/redux/actions.js | 7 +- src/redux/reducers/builder.reducer.js | 2 +- 6 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 285c46f..caef3e1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,12 +1,14 @@ -import React from 'react' +import { useEffect } from 'react' // import 'rsuite/dist/styles/rsuite-dark.css' import './App.css' import { HTML5Backend } from 'react-dnd-html5-backend' import { DndProvider } from 'react-dnd' import { Header, Content, Footer, Generate, FlowGenerate } from './components' -import { HashRouter as Router, Route, Routes } from 'react-router-dom' +import { Route, Routes, useNavigate } from 'react-router-dom' import { ErrorBoundary } from './ErrorBoundary' import { FLAGS } from 'flags' +import { useDispatch } from 'react-redux' +import { toggleBuilderAction } from 'redux/actions' console.log( `%c @@ -29,46 +31,55 @@ console.log( ) function App() { + const dispatch = useDispatch() + const navigate = useNavigate() + useEffect(() => { + const handleKeydown = ({ key }: KeyboardEvent) => { + if (key === 'b' || key === 'B') { + dispatch(toggleBuilderAction()) + } else if (key === 'g' || key === 'G') { + navigate('/generate') + } + } + document.addEventListener('keydown', handleKeydown) + return () => document.removeEventListener('keydown', handleKeydown) + }) + return ( - - -
- - - -