fix: add new shortcut to create new thread (#2701)
This commit is contained in:
parent
8dbd2524b8
commit
997d0e72c5
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
import { Fragment, ReactNode, useEffect } from 'react'
|
import { Fragment, ReactNode, useEffect } from 'react'
|
||||||
|
|
||||||
import { atom, useSetAtom } from 'jotai'
|
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import { MainViewState } from '@/constants/screens'
|
import { MainViewState } from '@/constants/screens'
|
||||||
|
|
||||||
|
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
|
||||||
|
|
||||||
import { mainViewStateAtom } from '@/helpers/atoms/App.atom'
|
import { mainViewStateAtom } from '@/helpers/atoms/App.atom'
|
||||||
|
import { assistantsAtom } from '@/helpers/atoms/Assistant.atom'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
@ -21,11 +24,19 @@ export default function KeyListener({ children }: Props) {
|
|||||||
const setShowSelectModelModal = useSetAtom(showSelectModelModalAtom)
|
const setShowSelectModelModal = useSetAtom(showSelectModelModalAtom)
|
||||||
const setMainViewState = useSetAtom(mainViewStateAtom)
|
const setMainViewState = useSetAtom(mainViewStateAtom)
|
||||||
const showCommandSearchModal = useSetAtom(showCommandSearchModalAtom)
|
const showCommandSearchModal = useSetAtom(showCommandSearchModalAtom)
|
||||||
|
const { requestCreateNewThread } = useCreateNewThread()
|
||||||
|
const assistants = useAtomValue(assistantsAtom)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onKeyDown = (e: KeyboardEvent) => {
|
const onKeyDown = (e: KeyboardEvent) => {
|
||||||
const prefixKey = isMac ? e.metaKey : e.ctrlKey
|
const prefixKey = isMac ? e.metaKey : e.ctrlKey
|
||||||
|
|
||||||
|
if (e.key === 'n' && prefixKey) {
|
||||||
|
requestCreateNewThread(assistants[0])
|
||||||
|
setMainViewState(MainViewState.Thread)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (e.key === 'b' && prefixKey) {
|
if (e.key === 'b' && prefixKey) {
|
||||||
setShowLeftSideBar((showLeftSideBar) => !showLeftSideBar)
|
setShowLeftSideBar((showLeftSideBar) => !showLeftSideBar)
|
||||||
return
|
return
|
||||||
@ -49,6 +60,8 @@ export default function KeyListener({ children }: Props) {
|
|||||||
document.addEventListener('keydown', onKeyDown)
|
document.addEventListener('keydown', onKeyDown)
|
||||||
return () => document.removeEventListener('keydown', onKeyDown)
|
return () => document.removeEventListener('keydown', onKeyDown)
|
||||||
}, [
|
}, [
|
||||||
|
assistants,
|
||||||
|
requestCreateNewThread,
|
||||||
setMainViewState,
|
setMainViewState,
|
||||||
setShowLeftSideBar,
|
setShowLeftSideBar,
|
||||||
setShowSelectModelModal,
|
setShowSelectModelModal,
|
||||||
|
|||||||
@ -10,6 +10,11 @@ import {
|
|||||||
} from '@janhq/uikit'
|
} from '@janhq/uikit'
|
||||||
|
|
||||||
const availableShortcuts = [
|
const availableShortcuts = [
|
||||||
|
{
|
||||||
|
combination: 'N',
|
||||||
|
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
|
||||||
|
description: 'Create a new thread',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
combination: 'E',
|
combination: 'E',
|
||||||
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
|
modifierKeys: [isMac ? '⌘' : 'Ctrl'],
|
||||||
|
|||||||
@ -26,8 +26,6 @@ import {
|
|||||||
import { useAtom, useAtomValue } from 'jotai'
|
import { useAtom, useAtomValue } from 'jotai'
|
||||||
import { AlertTriangleIcon, AlertCircleIcon } from 'lucide-react'
|
import { AlertTriangleIcon, AlertCircleIcon } from 'lucide-react'
|
||||||
|
|
||||||
import ShortcutModal from '@/containers/ShortcutModal'
|
|
||||||
|
|
||||||
import { snackbar, toaster } from '@/containers/Toast'
|
import { snackbar, toaster } from '@/containers/Toast'
|
||||||
|
|
||||||
import { useActiveModel } from '@/hooks/useActiveModel'
|
import { useActiveModel } from '@/hooks/useActiveModel'
|
||||||
@ -177,22 +175,7 @@ const Advanced = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollArea className="px-4">
|
<ScrollArea className="px-4">
|
||||||
<div className="block w-full">
|
<div className="block w-full py-4">
|
||||||
{/* Keyboard shortcut */}
|
|
||||||
<div className="flex w-full items-start justify-between border-b border-border py-4 first:pt-4 last:border-none">
|
|
||||||
<div className="flex-shrink-0 space-y-1.5">
|
|
||||||
<div className="flex gap-x-2">
|
|
||||||
<h6 className="text-sm font-semibold capitalize">
|
|
||||||
Keyboard Shortcuts
|
|
||||||
</h6>
|
|
||||||
</div>
|
|
||||||
<p className="leading-relaxed">
|
|
||||||
Shortcuts that you might find useful in Jan app.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<ShortcutModal />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Experimental */}
|
{/* Experimental */}
|
||||||
<div className="flex w-full items-start justify-between border-b border-border py-4 first:pt-0 last:border-none">
|
<div className="flex w-full items-start justify-between border-b border-border py-4 first:pt-0 last:border-none">
|
||||||
<div className="flex-shrink-0 space-y-1.5">
|
<div className="flex-shrink-0 space-y-1.5">
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import ShortcutModal from '@/containers/ShortcutModal'
|
||||||
|
|
||||||
import ToggleAccent from '@/screens/Settings/Appearance/TogglePrimary'
|
import ToggleAccent from '@/screens/Settings/Appearance/TogglePrimary'
|
||||||
import ToggleTheme from '@/screens/Settings/Appearance/ToggleTheme'
|
import ToggleTheme from '@/screens/Settings/Appearance/ToggleTheme'
|
||||||
|
|
||||||
@ -24,6 +26,20 @@ export default function AppearanceOptions() {
|
|||||||
</div>
|
</div>
|
||||||
<ToggleAccent />
|
<ToggleAccent />
|
||||||
</div>
|
</div>
|
||||||
|
{/* Keyboard shortcut */}
|
||||||
|
<div className="flex w-full items-start justify-between border-b border-border py-3 first:pt-4 last:border-none">
|
||||||
|
<div className="flex-shrink-0 space-y-1.5">
|
||||||
|
<div className="flex gap-x-2">
|
||||||
|
<h6 className="text-sm font-semibold capitalize">
|
||||||
|
Keyboard Shortcuts
|
||||||
|
</h6>
|
||||||
|
</div>
|
||||||
|
<p className="leading-relaxed">
|
||||||
|
Shortcuts that you might find useful in Jan app.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ShortcutModal />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user