import { cn } from '@/lib/utils'; import { Popover, PopoverButton, PopoverPanel, Transition, } from '@headlessui/react'; import { CopyPlus, File, LoaderCircle, Plus, Trash } from 'lucide-react'; import { Fragment, useRef, useState } from 'react'; import { File as FileType } from '../ChatWindow'; const Attach = ({ fileIds, setFileIds, showText, files, setFiles, }: { fileIds: string[]; setFileIds: (fileIds: string[]) => void; showText?: boolean; files: FileType[]; setFiles: (files: FileType[]) => void; }) => { const [loading, setLoading] = useState(false); const fileInputRef = useRef(); const handleChange = async (e: React.ChangeEvent) => { setLoading(true); const data = new FormData(); for (let i = 0; i < e.target.files!.length; i++) { data.append('files', e.target.files![i]); } const embeddingModelProvider = localStorage.getItem( 'embeddingModelProvider', ); const embeddingModel = localStorage.getItem('embeddingModel'); data.append('embedding_model_provider', embeddingModelProvider!); data.append('embedding_model', embeddingModel!); const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/uploads`, { method: 'POST', body: data, }); const resData = await res.json(); setFiles([...files, ...resData.files]); setFileIds([...fileIds, ...resData.files.map((file: any) => file.fileId)]); setLoading(false); }; return loading ? (

Uploading..

) : files.length > 0 ? ( 0 ? '-ml-2 lg:-ml-3' : '', )} > {files.length > 1 && ( <>

{files.length} files

)} {files.length === 1 && ( <>

{files[0].fileName.length > 10 ? files[0].fileName.replace(/\.\w+$/, '').substring(0, 3) + '...' + files[0].fileExtension : files[0].fileName}

)}

Attached files

{files.map((file, i) => (

{file.fileName.length > 25 ? file.fileName.replace(/\.\w+$/, '').substring(0, 25) + '...' + file.fileExtension : file.fileName}

))}
) : ( ); }; export default Attach;