From 24467dd626de7b4196e85dd55ba537b50fbe9fce Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Fri, 21 Jun 2024 12:34:28 -0400 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20refactor:=20Improve=20Text?= =?UTF-8?q?=20Commands=20(#3152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor(useMentions): separate usage of `useSelectMention` * refactor: separate handleKeyUp logic from useTextarea * fix(Mention): cleanup blur timer * refactor(handleKeyUp): improve command handling, prevent unintended re-trigger * chore: remove console log * chore: temporarily comment plus command --- client/src/components/Chat/Input/ChatForm.tsx | 14 +-- .../Chat/Input/Files/AttachFile.tsx | 1 + client/src/components/Chat/Input/Mention.tsx | 16 +++- client/src/hooks/Input/index.ts | 1 + client/src/hooks/Input/useHandleKeyUp.ts | 93 +++++++++++++++++++ client/src/hooks/Input/useMentions.ts | 12 +-- client/src/hooks/Input/useTextarea.ts | 22 +---- 7 files changed, 121 insertions(+), 38 deletions(-) create mode 100644 client/src/hooks/Input/useHandleKeyUp.ts diff --git a/client/src/components/Chat/Input/ChatForm.tsx b/client/src/components/Chat/Input/ChatForm.tsx index ea88457ce2..9f1fd47788 100644 --- a/client/src/components/Chat/Input/ChatForm.tsx +++ b/client/src/components/Chat/Input/ChatForm.tsx @@ -7,7 +7,7 @@ import { fileConfig as defaultFileConfig, } from 'librechat-data-provider'; import { useChatContext, useAssistantsMapContext, useChatFormContext } from '~/Providers'; -import { useRequiresKey, useTextarea, useSubmitMessage } from '~/hooks'; +import { useRequiresKey, useTextarea, useSubmitMessage, useHandleKeyUp } from '~/hooks'; import { useAutoSave } from '~/hooks/Input/useAutoSave'; import { TextareaAutosize } from '~/components/ui'; import { useGetFileConfig } from '~/data-provider'; @@ -34,12 +34,12 @@ const ChatForm = ({ index = 0 }) => { ); const { requiresKey } = useRequiresKey(); - const { handlePaste, handleKeyDown, handleKeyUp, handleCompositionStart, handleCompositionEnd } = - useTextarea({ - textAreaRef, - submitButtonRef, - disabled: !!requiresKey, - }); + const handleKeyUp = useHandleKeyUp({ index, textAreaRef }); + const { handlePaste, handleKeyDown, handleCompositionStart, handleCompositionEnd } = useTextarea({ + textAreaRef, + submitButtonRef, + disabled: !!requiresKey, + }); const { files, diff --git a/client/src/components/Chat/Input/Files/AttachFile.tsx b/client/src/components/Chat/Input/Files/AttachFile.tsx index 029077d573..1cc136d99d 100644 --- a/client/src/components/Chat/Input/Files/AttachFile.tsx +++ b/client/src/components/Chat/Input/Files/AttachFile.tsx @@ -35,6 +35,7 @@ const AttachFile = ({