Skip to content

Commit

Permalink
feat: enable hotkey collapse right panel (janhq#3019)
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur authored Jun 11, 2024
1 parent cf8f401 commit 44536ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
20 changes: 18 additions & 2 deletions web/containers/Providers/KeyListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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>
}
7 changes: 6 additions & 1 deletion web/screens/Settings/Hotkeys/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -21,7 +26,7 @@ const availableHotkeys = [
description: 'Send a message',
},
{
combination: 'Shift + Enter',
combination: 'Shift Enter',
description: 'Insert new line in input box',
},
{
Expand Down

0 comments on commit 44536ec

Please sign in to comment.