diff --git a/frontend/src/components/MessageInput.tsx b/frontend/src/components/MessageInput.tsx new file mode 100644 index 00000000..7335cfa8 --- /dev/null +++ b/frontend/src/components/MessageInput.tsx @@ -0,0 +1,94 @@ +import { useEffect, useRef } from 'react'; +import { useTranslation } from 'react-i18next'; +import { useDarkTheme } from '../hooks'; +import Send from '../assets/send.svg'; +import SendDark from '../assets/send_dark.svg'; +import SpinnerDark from '../assets/spinner-dark.svg'; +import Spinner from '../assets/spinner.svg'; + +interface MessageInputProps { + value: string; + onChange: (e: React.ChangeEvent) => void; + onSubmit: () => void; + loading: boolean; +} + +export default function MessageInput({ + value, + onChange, + onSubmit, + loading, +}: MessageInputProps) { + const { t } = useTranslation(); + const [isDarkTheme] = useDarkTheme(); + const inputRef = useRef(null); + + const handleInput = () => { + if (inputRef.current) { + if (window.innerWidth < 350) inputRef.current.style.height = 'auto'; + else inputRef.current.style.height = '64px'; + inputRef.current.style.height = `${Math.min( + inputRef.current.scrollHeight, + 96, + )}px`; + } + }; + + // Focus the textarea and set initial height on mount. + useEffect(() => { + inputRef.current?.focus(); + handleInput(); + }, []); + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + onSubmit(); + if (inputRef.current) { + inputRef.current.value = ''; + handleInput(); + } + } + }; + + return ( +
+ + - {status === 'loading' ? ( - {t('loading')} - ) : ( -
- -
- )} + setInput(e.target.value)} + onSubmit={handleQuestionSubmission} + loading={status === 'loading'} + />

diff --git a/frontend/src/conversation/ConversationMessages.tsx b/frontend/src/conversation/ConversationMessages.tsx index 698d0402..8cb878ef 100644 --- a/frontend/src/conversation/ConversationMessages.tsx +++ b/frontend/src/conversation/ConversationMessages.tsx @@ -139,7 +139,7 @@ export default function ConversationMessages({ ref={conversationRef} onWheel={handleUserInterruption} onTouchMove={handleUserInterruption} - className="flex justify-center w-full overflow-y-auto h-screen sm:mt-12" + className="flex justify-center w-full overflow-y-auto h-screen sm:pt-12 " > {queries.length > 0 && !hasScrolledToLast && ( - - {t('sharedConv.meta')} - - - ) : ( - <> - + )} - {/* Add the textarea input here */} -

-
-
- -