Skip to content

Commit

Permalink
fix: add new shortcut to create new thread
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Apr 12, 2024
1 parent 4a9a9f2 commit 72ee88c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion web/containers/Providers/KeyListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import { Fragment, ReactNode, useEffect } from 'react'

import { atom, useSetAtom } from 'jotai'
import { atom, useAtomValue, useSetAtom } from 'jotai'

import { MainViewState } from '@/constants/screens'

import { useCreateNewThread } from '@/hooks/useCreateNewThread'

import { mainViewStateAtom } from '@/helpers/atoms/App.atom'
import { assistantsAtom } from '@/helpers/atoms/Assistant.atom'

type Props = {
children: ReactNode
Expand All @@ -21,11 +24,18 @@ export default function KeyListener({ children }: Props) {
const setShowSelectModelModal = useSetAtom(showSelectModelModalAtom)
const setMainViewState = useSetAtom(mainViewStateAtom)
const showCommandSearchModal = useSetAtom(showCommandSearchModalAtom)
const { requestCreateNewThread } = useCreateNewThread()
const assistants = useAtomValue(assistantsAtom)

useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
const prefixKey = isMac ? e.metaKey : e.ctrlKey

if (e.key === 'n' && prefixKey) {
requestCreateNewThread(assistants[0])
return
}

if (e.key === 'b' && prefixKey) {
setShowLeftSideBar((showLeftSideBar) => !showLeftSideBar)
return
Expand All @@ -49,6 +59,8 @@ export default function KeyListener({ children }: Props) {
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [
assistants,
requestCreateNewThread,
setMainViewState,
setShowLeftSideBar,
setShowSelectModelModal,
Expand Down
5 changes: 5 additions & 0 deletions web/containers/ShortcutModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import {
} from '@janhq/uikit'

const availableShortcuts = [
{
combination: 'N',
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
description: 'Create a new thread',
},
{
combination: 'E',
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
Expand Down

0 comments on commit 72ee88c

Please sign in to comment.