diff --git a/web/src/components/file-upload.tsx b/web/src/components/file-upload.tsx index d880e4342..b6941f8e9 100644 --- a/web/src/components/file-upload.tsx +++ b/web/src/components/file-upload.tsx @@ -1,3 +1,5 @@ +// https://www.diceui.com/docs/components/file-upload + 'use client'; import { cn } from '@/lib/utils'; diff --git a/web/src/components/message-input/next.tsx b/web/src/components/message-input/next.tsx new file mode 100644 index 000000000..787a0ed8d --- /dev/null +++ b/web/src/components/message-input/next.tsx @@ -0,0 +1,171 @@ +'use client'; + +import { + FileUpload, + FileUploadDropzone, + FileUploadItem, + FileUploadItemDelete, + FileUploadItemMetadata, + FileUploadItemPreview, + FileUploadItemProgress, + FileUploadList, + FileUploadTrigger, + type FileUploadProps, +} from '@/components/file-upload'; +import { Button } from '@/components/ui/button'; +import { Textarea } from '@/components/ui/textarea'; +import { CircleStop, Paperclip, Send, Upload, X } from 'lucide-react'; +import * as React from 'react'; +import { toast } from 'sonner'; + +interface IProps { + disabled: boolean; + value: string; + sendDisabled: boolean; + sendLoading: boolean; + conversationId: string; + uploadMethod?: string; + isShared?: boolean; + showUploadIcon?: boolean; + isUploading?: boolean; + onPressEnter(...prams: any[]): void; + onInputChange: React.ChangeEventHandler; + createConversationBeforeUploadDocument?(message: string): Promise; + stopOutputMessage?(): void; + onUpload?: NonNullable; +} + +export function NextMessageInput({ + isUploading = false, + value, + sendDisabled, + sendLoading, + disabled, + showUploadIcon = true, + onUpload, + onInputChange, + stopOutputMessage, + onPressEnter, +}: IProps) { + const [files, setFiles] = React.useState([]); + + const onFileReject = React.useCallback((file: File, message: string) => { + toast(message, { + description: `"${file.name.length > 20 ? `${file.name.slice(0, 20)}...` : file.name}" has been rejected`, + }); + }, []); + + const submit = React.useCallback(() => { + if (isUploading) return; + onPressEnter(); + setFiles([]); + }, [isUploading, onPressEnter]); + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + submit(); + } + }; + + const onSubmit = React.useCallback( + (event: React.FormEvent) => { + event.preventDefault(); + submit(); + }, + [submit], + ); + + return ( + + event.preventDefault()} + className="absolute top-0 left-0 z-0 flex size-full items-center justify-center rounded-none border-none bg-background/50 p-0 opacity-0 backdrop-blur transition-opacity duration-200 ease-out data-[dragging]:z-10 data-[dragging]:opacity-100" + > +
+
+ +
+

Drag & drop files here

+

+ Upload max 5 files each up to 5MB +

+
+
+
+ + {files.map((file, index) => ( + + + + + + + + + + ))} + +