feat: enable hotkey collapse right panel (#3019)

This commit is contained in:
Faisal Amir 2024-06-11 18:46:27 +07:00 committed by GitHub
parent cf8f401dab
commit 44536ec929
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View File

@ -8,7 +8,11 @@ import { MainViewState } from '@/constants/screens'
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
import { mainViewStateAtom, showLeftPanelAtom } from '@/helpers/atoms/App.atom'
import {
mainViewStateAtom,
showLeftPanelAtom,
showRightPanelAtom,
} from '@/helpers/atoms/App.atom'
import { assistantsAtom } from '@/helpers/atoms/Assistant.atom'
type Props = {
@ -17,6 +21,7 @@ type Props = {
export default function KeyListener({ children }: Props) {
const setShowLeftPanel = useSetAtom(showLeftPanelAtom)
const setShowRightPanel = useSetAtom(showRightPanelAtom)
const setMainViewState = useSetAtom(mainViewStateAtom)
const { requestCreateNewThread } = useCreateNewThread()
const assistants = useAtomValue(assistantsAtom)
@ -25,6 +30,11 @@ export default function KeyListener({ children }: Props) {
const onKeyDown = (e: KeyboardEvent) => {
const prefixKey = isMac ? e.metaKey : e.ctrlKey
if (e.key === 'b' && prefixKey && e.shiftKey) {
setShowRightPanel((showRightideBar) => !showRightideBar)
return
}
if (e.key === 'n' && prefixKey) {
requestCreateNewThread(assistants[0])
setMainViewState(MainViewState.Thread)
@ -43,7 +53,13 @@ export default function KeyListener({ children }: Props) {
}
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [assistants, requestCreateNewThread, setMainViewState, setShowLeftPanel])
}, [
assistants,
requestCreateNewThread,
setMainViewState,
setShowLeftPanel,
setShowRightPanel,
])
return <Fragment>{children}</Fragment>
}

View File

@ -11,6 +11,11 @@ const availableHotkeys = [
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
description: 'Toggle collapsible left panel',
},
{
combination: 'Shift B',
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
description: 'Toggle collapsible right panel',
},
{
combination: ',',
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
@ -21,7 +26,7 @@ const availableHotkeys = [
description: 'Send a message',
},
{
combination: 'Shift + Enter',
combination: 'Shift Enter',
description: 'Insert new line in input box',
},
{