feat: add AI shortcut functionality for enhanced user interaction
- Introduced a new hook, useAIShortcut, to manage keyboard shortcuts for creating new chats and closing the AI chat panel. - Integrated the useAIShortcut hook into the AIChatRoot component to enable these shortcuts when the AI chat is focused. These changes improve user experience by providing quick access to essential chat functions through keyboard shortcuts. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { useEffect, useMemo, useRef } from "react"
|
||||
import { Focusable } from "~/components/common/Focusable"
|
||||
import { HotkeyScope } from "~/constants"
|
||||
|
||||
import { useAIShortcut } from "../../hooks/useAIShortcut"
|
||||
import type { AIPanelRefs } from "../../store/AIChatContext"
|
||||
import {
|
||||
AIChatStoreContext,
|
||||
@@ -34,7 +35,7 @@ const AIChatRootInner: FC<AIChatRootProps> = ({ children, chatId: externalChatId
|
||||
const panelRef = useRef<HTMLDivElement>(null!)
|
||||
const inputRef = useRef<HTMLTextAreaElement>(null!)
|
||||
const refsContext = useMemo<AIPanelRefs>(() => ({ panelRef, inputRef }), [panelRef, inputRef])
|
||||
|
||||
useAIShortcut()
|
||||
if (!currentChatId) {
|
||||
return (
|
||||
<div className="bg-background flex size-full items-center justify-center">
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useGlobalFocusableScopeSelector } from "@follow/components/common/Focusable/hooks.js"
|
||||
import { useEffect } from "react"
|
||||
import { tinykeys } from "tinykeys"
|
||||
|
||||
import { setAIPanelVisibility } from "~/atoms/settings/ai"
|
||||
import { FocusablePresets } from "~/components/common/Focusable"
|
||||
|
||||
import { useChatActions } from "../store/hooks"
|
||||
|
||||
export const useAIShortcut = () => {
|
||||
const isFocus = useGlobalFocusableScopeSelector(FocusablePresets.isAIChat)
|
||||
|
||||
const chatActions = useChatActions()
|
||||
useEffect(() => {
|
||||
if (!isFocus) return
|
||||
return tinykeys(document.documentElement, {
|
||||
"$mod+n": (e) => {
|
||||
e.preventDefault()
|
||||
// New chat
|
||||
chatActions.newChat()
|
||||
},
|
||||
"$mod+w": (e) => {
|
||||
e.preventDefault()
|
||||
// close AI chat
|
||||
setAIPanelVisibility(false)
|
||||
},
|
||||
})
|
||||
}, [chatActions, isFocus])
|
||||
}
|
||||
@@ -442,8 +442,8 @@ export const AllItem: EntryListItemFC = ({ entryId, entryPreview, translation })
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between truncate text-[13px]">
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="flex min-w-0 items-center justify-between text-[13px]">
|
||||
<div className="flex min-w-0 items-center gap-1">
|
||||
<FeedIcon
|
||||
fallback
|
||||
noMargin
|
||||
@@ -457,15 +457,11 @@ export const AllItem: EntryListItemFC = ({ entryId, entryPreview, translation })
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className={cn("text-zinc-500")}>
|
||||
{dayjs
|
||||
.duration(dayjs(entry.publishedAt).diff(dayjs(), "minute"), "minute")
|
||||
.humanize()}
|
||||
{t("space")}
|
||||
{t("words.ago")}
|
||||
</span>
|
||||
</div>
|
||||
<span className={"text-text-secondary ml-2 min-w-0 shrink-0"}>
|
||||
{dayjs.duration(dayjs(entry.publishedAt).diff(dayjs(), "minute"), "minute").humanize()}
|
||||
{t("space")}
|
||||
{t("words.ago")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user