({ input, setInput, inputRef, formRef, disabled, chatStarted, isSending, isLoading, chatUploadedFiles, setChatUploadedFiles, chatFileDetails, setChatFileDetails, chatManager, setChatStarted, setChatMessages, setStatusMessage, setIsSending, setProgress, setIsLoadingFirstMessage })
| 27 | } |
| 28 | |
| 29 | const InputForm: React.FC<Props> = ({ input, setInput, inputRef, formRef, disabled, chatStarted, isSending, isLoading, chatUploadedFiles, setChatUploadedFiles, chatFileDetails, setChatFileDetails, chatManager, setChatStarted, setChatMessages, setStatusMessage, setIsSending, setProgress, setIsLoadingFirstMessage }) => { |
| 30 | const handleFormSubmit = async (e: React.FormEvent<HTMLFormElement>) => { |
| 31 | e.preventDefault(); |
| 32 | if (isSending) { |
| 33 | return; |
| 34 | } |
| 35 | const message = input; |
| 36 | setInput(''); |
| 37 | setIsSending(true); |
| 38 | if (chatManager) { |
| 39 | const currentFiles = chatUploadedFiles; |
| 40 | setChatUploadedFiles([]); |
| 41 | setChatFileDetails([]); |
| 42 | try { |
| 43 | await chatManager.sendMessage(message, currentFiles, chatFileDetails); |
| 44 | } catch (error) { |
| 45 | console.error('Error sending message:', error); |
| 46 | } finally { |
| 47 | setIsSending(false); |
| 48 | } |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | const handleChatFilesUpload = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 53 | if (event.target.files) { |
| 54 | const newFiles = Array.from(event.target.files); |
| 55 | if (chatFileDetails.length + newFiles.length > 10) { |
| 56 | alert('You can only upload up to 10 files.'); |
| 57 | return; |
| 58 | } |
| 59 | const fileArray = newFiles.map((file) => ({ |
| 60 | name: file.name, |
| 61 | type: file.type, |
| 62 | size: file.size, |
| 63 | })); |
| 64 | setChatFileDetails([...chatFileDetails, ...fileArray]); |
| 65 | setChatUploadedFiles([...chatUploadedFiles, ...newFiles]); |
| 66 | } |
| 67 | event.target.value = ''; |
| 68 | }; |
| 69 | |
| 70 | const removeChatFile = (fileName: string) => { |
| 71 | const updatedFileDetails = chatFileDetails.filter((file) => file.name !== fileName); |
| 72 | setChatFileDetails(updatedFileDetails); |
| 73 | |
| 74 | const updatedUploadedFiles = chatUploadedFiles.filter((file) => file.name !== fileName); |
| 75 | setChatUploadedFiles(updatedUploadedFiles); |
| 76 | }; |
| 77 | |
| 78 | return ( |
| 79 | <div className="fixed bottom-0 flex w-full flex-col items-center space-y-3 bg-gradient-to-b from-transparent via-gray-100 to-gray-100 p-5 pb-3 sm:px-0"> |
| 80 | <div className="flex flex-col items-stretch w-full max-w-screen-md"> |
| 81 | <div className="flex flex-wrap items-center space-x-2 mb-2"> |
| 82 | {chatFileDetails.map((file) => ( |
| 83 | <div key={file.name} className="flex items-center space-x-1"> |
| 84 | {file.type.startsWith('image') ? <ImageIcon className="h-3 w-3" /> : <DocumentIcon className="h-3 w-3" />} |
| 85 | <span className="text-xs text-gray-500">{file.name}</span> |
| 86 | <button |
nothing calls this directly
no test coverage detected