mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: global hotkeys.
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
43
client/src/components/Dashboard/GlobalHotkeys.js
Normal file
43
client/src/components/Dashboard/GlobalHotkeys.js
Normal 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);
|
||||
Reference in New Issue
Block a user