Skip to content

Commit

Permalink
refactor: remove hotkeys-js dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakia committed Mar 6, 2024
1 parent 9dc3bdc commit 92a49fc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
"eslint-plugin-react": "7.33.0",
"file-loader": "^6.2.0",
"highlight.js": "^11.8.0",
"hotkeys-js": "^3.13.7",
"html-inline-script-webpack-plugin": "^2.0.3",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.5.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState, useEffect, useRef } from 'react'
import PropTypes from 'prop-types'
import ClearIcon from '@mui/icons-material/Clear'
import KeyboardCommandKeyIcon from '@mui/icons-material/KeyboardCommandKey'
import hotkeys from 'hotkeys-js'

import { debounce } from '@core/utils'

Expand All @@ -21,15 +20,17 @@ const RepresentativesSearch = ({
}, 300)

useEffect(() => {
const handleHotkeys = (event, handler) => {
event.preventDefault()
inputRef.current.focus()
const handleKeyDown = (event) => {
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
event.preventDefault()
inputRef.current.focus()
}
}

hotkeys('command+k,ctrl+k', handleHotkeys)
document.addEventListener('keydown', handleKeyDown)

return () => {
hotkeys.unbind('command+k,ctrl+k')
document.removeEventListener('keydown', handleKeyDown)
}
}, [])

Expand Down
13 changes: 7 additions & 6 deletions src/views/components/search-bar/search-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState, useEffect, useRef } from 'react'
import KeyboardCommandKeyIcon from '@mui/icons-material/KeyboardCommandKey'
import ClearIcon from '@mui/icons-material/Clear'
import SearchIcon from '@mui/icons-material/Search'
import hotkeys from 'hotkeys-js'

import history from '@core/history'

Expand All @@ -17,15 +16,17 @@ const SearchBar = () => {
const input_ref = useRef(null)

useEffect(() => {
const handle_hotkeys = (event, handler) => {
event.preventDefault()
input_ref.current.focus()
const handle_key_down = (event) => {
if ((event.metaKey || event.ctrlKey) && event.key === 'l') {
event.preventDefault()
input_ref.current.focus()
}
}

hotkeys('command+l,ctrl+l', handle_hotkeys)
document.addEventListener('keydown', handle_key_down)

return () => {
hotkeys.unbind('command+l,ctrl+l')
document.removeEventListener('keydown', handle_key_down)
}
}, [])

Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9841,13 +9841,6 @@ __metadata:
languageName: node
linkType: hard

"hotkeys-js@npm:^3.13.7":
version: 3.13.7
resolution: "hotkeys-js@npm:3.13.7"
checksum: 8c1da52704c1c2a97810d0d2c9d0917b87a7edd250aae79cd4b185b9374b2ddc7ba24eeec8491018ba51726b72faecf89042fede2b3a05d0599f334355bb968c
languageName: node
linkType: hard

"hpack.js@npm:^2.1.6":
version: 2.1.6
resolution: "hpack.js@npm:2.1.6"
Expand Down Expand Up @@ -15718,7 +15711,6 @@ __metadata:
front-matter: ^4.0.2
fs-extra: ^11.1.1
highlight.js: ^11.8.0
hotkeys-js: ^3.13.7
html-inline-script-webpack-plugin: ^2.0.3
html-loader: ^2.1.2
html-webpack-plugin: ^5.5.3
Expand Down

0 comments on commit 92a49fc

Please sign in to comment.