mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
chore: update hooks file ext
This commit is contained in:
parent
245ae4cbcc
commit
f75e76c447
6 changed files with 30 additions and 26 deletions
|
|
@ -5,7 +5,7 @@ import { Portal } from 'components/Portal'
|
|||
import { Resizable } from 'components/Resizable'
|
||||
import { SettingsBar } from 'components/settings/SettingsBar'
|
||||
import { ToggleShowButton } from 'components/ToggleShowButton'
|
||||
import { ConfigsContextShape, useConfigs } from 'containers/ConfigsContext'
|
||||
import { useConfigs } from 'containers/ConfigsContext'
|
||||
import { platform } from 'platforms'
|
||||
import { useGitHubAttachCopyFileButton, useGitHubAttachCopySnippetButton } from 'platforms/GitHub'
|
||||
import * as React from 'react'
|
||||
|
|
@ -17,13 +17,13 @@ import { useLoadedContext } from 'utils/hooks/useLoadedContext'
|
|||
import { loadWithPJAX, useOnPJAXDone, usePJAX } from 'utils/hooks/usePJAX'
|
||||
import { useProgressBar } from 'utils/hooks/useProgressBar'
|
||||
import { useStateIO } from 'utils/hooks/useStateIO'
|
||||
import * as keyHelper from 'utils/keyHelper'
|
||||
import { useToggleSideBarWithKeyboard } from '../utils/hooks/useToggleSideBarWithKeyboard'
|
||||
import { SideBarErrorContext } from './ErrorContext'
|
||||
import { Icon } from './Icon'
|
||||
import { IIFC } from './IIFC'
|
||||
import { LoadingIndicator } from './LoadingIndicator'
|
||||
import { RepoContext } from './RepoContext'
|
||||
import { SideBarState, SideBarStateContext } from './SideBarState'
|
||||
import { SideBarStateContext } from './SideBarState'
|
||||
import { Theme } from './Theme'
|
||||
|
||||
export function SideBar() {
|
||||
|
|
@ -175,26 +175,3 @@ export function SideBar() {
|
|||
</Theme>
|
||||
)
|
||||
}
|
||||
|
||||
function useToggleSideBarWithKeyboard(
|
||||
state: SideBarState,
|
||||
configContext: ConfigsContextShape,
|
||||
toggleShowSideBar: () => void,
|
||||
) {
|
||||
const isDisabled = state === 'disabled'
|
||||
React.useEffect(
|
||||
function attachKeyDown() {
|
||||
if (isDisabled || !configContext.value.shortcut) return
|
||||
|
||||
function onKeyDown(e: KeyboardEvent) {
|
||||
const keys = keyHelper.parseEvent(e)
|
||||
if (keys === configContext.value.shortcut) {
|
||||
toggleShowSideBar()
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', onKeyDown)
|
||||
return () => window.removeEventListener('keydown', onKeyDown)
|
||||
},
|
||||
[toggleShowSideBar, isDisabled, configContext.value.shortcut],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
27
src/utils/hooks/useToggleSideBarWithKeyboard.ts
Normal file
27
src/utils/hooks/useToggleSideBarWithKeyboard.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { ConfigsContextShape } from 'containers/ConfigsContext'
|
||||
import * as React from 'react'
|
||||
import * as keyHelper from 'utils/keyHelper'
|
||||
import { SideBarState } from '../../components/SideBarState'
|
||||
|
||||
export function useToggleSideBarWithKeyboard(
|
||||
state: SideBarState,
|
||||
configContext: ConfigsContextShape,
|
||||
toggleShowSideBar: () => void,
|
||||
) {
|
||||
const isDisabled = state === 'disabled'
|
||||
React.useEffect(
|
||||
function attachKeyDown() {
|
||||
if (isDisabled || !configContext.value.shortcut) return
|
||||
|
||||
function onKeyDown(e: KeyboardEvent) {
|
||||
const keys = keyHelper.parseEvent(e)
|
||||
if (keys === configContext.value.shortcut) {
|
||||
toggleShowSideBar()
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', onKeyDown)
|
||||
return () => window.removeEventListener('keydown', onKeyDown)
|
||||
},
|
||||
[toggleShowSideBar, isDisabled, configContext.value.shortcut],
|
||||
)
|
||||
}
|
||||
Loading…
Reference in a new issue