Skip to content

Commit

Permalink
fix: add new shortcut to create new thread (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo authored Apr 12, 2024
1 parent 8dbd252 commit 997d0e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
15 changes: 14 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,19 @@ 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])
setMainViewState(MainViewState.Thread)
return
}

if (e.key === 'b' && prefixKey) {
setShowLeftSideBar((showLeftSideBar) => !showLeftSideBar)
return
Expand All @@ -49,6 +60,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
19 changes: 1 addition & 18 deletions web/screens/Settings/Advanced/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import {
import { useAtom, useAtomValue } from 'jotai'
import { AlertTriangleIcon, AlertCircleIcon } from 'lucide-react'

import ShortcutModal from '@/containers/ShortcutModal'

import { snackbar, toaster } from '@/containers/Toast'

import { useActiveModel } from '@/hooks/useActiveModel'
Expand Down Expand Up @@ -177,22 +175,7 @@ const Advanced = () => {

return (
<ScrollArea className="px-4">
<div className="block w-full">
{/* 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>

<div className="block w-full py-4">
{/* 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-shrink-0 space-y-1.5">
Expand Down
16 changes: 16 additions & 0 deletions web/screens/Settings/Appearance/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ShortcutModal from '@/containers/ShortcutModal'

import ToggleAccent from '@/screens/Settings/Appearance/TogglePrimary'
import ToggleTheme from '@/screens/Settings/Appearance/ToggleTheme'

Expand All @@ -24,6 +26,20 @@ export default function AppearanceOptions() {
</div>
<ToggleAccent />
</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>
)
}

0 comments on commit 997d0e7

Please sign in to comment.