Skip to content

Commit

Permalink
refactor(core): start of global hotkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jul 7, 2022
1 parent 8722db6 commit 002411b
Show file tree
Hide file tree
Showing 4 changed files with 874 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"immutable": "4.0.0",
"imports-loader": "3.1.1",
"ip-address": "8.1.0",
"jquery-events-to-dom-events": "1.1.0",
"js-string-escape": "1.0.1",
"jsonwebtoken": "8.5.1",
"ldapjs": "2.3.1",
Expand Down Expand Up @@ -99,9 +100,11 @@
"react-colorful": "5.5.1",
"react-dom": "17.0.2",
"react-grid-layout": "1.3.4",
"react-hot-keys": "2.7.2",
"react-html-parser": "2.0.2",
"react-idle-timer": "5.4.0",
"react-infinite-scroller": "1.2.5",
"react-markdown": "8.0.3",
"react-redux": "7.2.6",
"react-singleton-hook": "3.4.0",
"react-sizeme": "3.0.2",
Expand All @@ -111,6 +114,8 @@
"redux-define": "1.1.1",
"redux-saga": "1.1.3",
"redux-saga-thunk": "0.7.3",
"rehype-raw": "6.1.1",
"remark-gfm": "3.0.1",
"request": "2.88.0",
"rimraf": "3.0.2",
"sanitize-html": "2.7.0",
Expand Down
5 changes: 5 additions & 0 deletions src/client/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import renderer from './renderer'

import SocketGlobal from 'containers/Global/SocketGlobal'
import SessionLoader from 'lib2/sessionLoader'
import HotKeysGlobal from 'containers/Global/HotKeysGlobal'
import BackupRestoreOverlay from 'containers/Global/BackupRestoreOverlay'

const sagaMiddleware = createSagaMiddleware()

Expand Down Expand Up @@ -58,6 +60,9 @@ if (document.getElementById('globals')) {
<SingletonHooksContainer />
<SessionLoader />
<SocketGlobal />
<HotKeysGlobal />

<BackupRestoreOverlay />
</>
</Provider>
)
Expand Down
42 changes: 42 additions & 0 deletions src/client/containers/Global/HotKeysGlobal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import ReactHotkeys from 'react-hot-keys'

class HotKeysGlobal extends React.Component {
keyList = ['g+d', 'g+t', 'shift+/']

onKeyDown (keyName, e, handle) {
// Route Change
if (keyName === 'g+d') History.pushState(null, null, '/dashboard')
if (keyName === 'g+t') History.pushState(null, null, '/tickets/active')

if (keyName === 'ctrl+g') console.log('split key')

// Help
if (keyName === 'shift+/') console.log('Show shortcut help')
}

render () {
const hasKeyboardShortcutEnabled = this.props.sessionUser
? this.props.sessionUser.preferences.keyboardShortcuts
: true
return (
<>
{hasKeyboardShortcutEnabled && (
<ReactHotkeys keyName={this.keyList.join(',')} onKeyDown={this.onKeyDown.bind(this)} />
)}
</>
)
}
}

HotKeysGlobal.propTypes = {
sessionUser: PropTypes.object
}

const mapStateToProps = state => ({
sessionUser: state.shared.sessionUser
})

export default connect(mapStateToProps, {})(HotKeysGlobal)
Loading

0 comments on commit 002411b

Please sign in to comment.