feat: global hotkeys.

This commit is contained in:
elforjani3
2021-01-18 22:53:02 +02:00
parent 90c568dc63
commit 4b798e4ea0
6 changed files with 81 additions and 9 deletions

View File

@@ -10,12 +10,12 @@ import DialogsContainer from 'components/DialogsContainer';
import PreferencesPage from 'components/Preferences/PreferencesPage';
import Search from 'containers/GeneralSearch/Search';
import DashboardSplitPane from 'components/Dashboard/DashboardSplitePane';
import GlobalHotkeys from './GlobalHotkeys';
import withSettingsActions from 'containers/Settings/withSettingsActions';
import { compose } from 'utils';
import 'style/pages/Dashboard/Dashboard.scss'
import 'style/pages/Dashboard/Dashboard.scss';
/**
* Dashboard page.
@@ -46,6 +46,7 @@ function Dashboard({
<Search />
<DialogsContainer />
<GlobalHotkeys />
</DashboardLoadingIndicator>
);
}

View File

@@ -0,0 +1,43 @@
import React from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { useHistory } from 'react-router-dom';
import routes from 'routes/dashboard';
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
import { compose } from 'utils';
function GlobalHotkeys({
// #withDashboardActions
toggleSidebarExpend,
recordSidebarPreviousExpand,
}) {
const history = useHistory();
const globalHotkeys = (function (array) {
const result = [];
array.forEach(({ hotkey }) =>
typeof hotkey !== 'undefined' ? result.push(hotkey) : null,
);
return result.toString();
})(routes);
const handleSidebarToggleBtn = () => {
toggleSidebarExpend();
recordSidebarPreviousExpand();
};
useHotkeys(
globalHotkeys,
(event, handle) => {
routes.map(({ path, hotkey }) => {
if (handle.key === hotkey) {
history.push(path);
}
});
},
[history],
);
useHotkeys('ctrl+/', (event, handle) => handleSidebarToggleBtn());
return <div></div>;
}
export default compose(withDashboardActions)(GlobalHotkeys);