From 9b2359fc2724b807cba18c3a33f69f91ebaf521e Mon Sep 17 00:00:00 2001 From: Danny Avila <110412045+danny-avila@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:10:06 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20refactor:=20Improve=20I?= =?UTF-8?q?nput=20Placeholder=20Handling=20and=20Error=20Management=20?= =?UTF-8?q?=F0=9F=94=84=20(#1296)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: identify new chat buttons with testid * fix: avoid parsing error in useSSE, which causes errorHandler to fail * fix: ensure last message isn't setting latestMessage when conversationId is `new` and text is the same due to possible re-renders * refactor: set placeholder through inputRef and useEffect * Update useSSE.ts * Update useSSE.ts --- client/src/components/Chat/Input/Textarea.tsx | 2 - client/src/components/Chat/Menus/NewChat.tsx | 3 +- client/src/components/Nav/MobileNav.tsx | 7 ++- client/src/components/Nav/NewChat.tsx | 2 +- client/src/hooks/Input/useTextarea.ts | 56 ++++++++++++++----- .../src/hooks/Messages/useMessageHelpers.ts | 12 +++- client/src/hooks/useSSE.ts | 5 ++ 7 files changed, 64 insertions(+), 23 deletions(-) diff --git a/client/src/components/Chat/Input/Textarea.tsx b/client/src/components/Chat/Input/Textarea.tsx index 7050fef349..70cd0dee41 100644 --- a/client/src/components/Chat/Input/Textarea.tsx +++ b/client/src/components/Chat/Input/Textarea.tsx @@ -11,7 +11,6 @@ export default function Textarea({ value, disabled, onChange, setText, submitMes handleKeyDown, handleCompositionStart, handleCompositionEnd, - placeholder, } = useTextarea({ setText, submitMessage, disabled }); return ( @@ -31,7 +30,6 @@ export default function Textarea({ value, disabled, onChange, setText, submitMes data-testid="text-input" style={{ height: 44, overflowY: 'auto' }} rows={1} - placeholder={placeholder} className={cn( supportsFiles[endpoint] ? ' pl-10 md:pl-[55px]' : 'pl-3 md:pl-4', 'm-0 w-full resize-none border-0 bg-transparent py-[10px] pr-10 placeholder-black/50 focus:ring-0 focus-visible:ring-0 dark:bg-transparent dark:placeholder-white/50 md:py-3.5 md:pr-12 ', diff --git a/client/src/components/Chat/Menus/NewChat.tsx b/client/src/components/Chat/Menus/NewChat.tsx index 28af271c64..4035714f9c 100644 --- a/client/src/components/Chat/Menus/NewChat.tsx +++ b/client/src/components/Chat/Menus/NewChat.tsx @@ -1,7 +1,7 @@ import { useChatContext } from '~/Providers'; import { useMediaQuery } from '~/hooks'; -export default function Header() { +export default function NewChat() { const { newConversation } = useChatContext(); const isSmallScreen = useMediaQuery('(max-width: 768px)'); if (isSmallScreen) { @@ -9,6 +9,7 @@ export default function Header() { } return (