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 AttachSmall = ({ fileIds, setFileIds, files, setFiles, }: { fileIds: string[]; setFileIds: (fileIds: string[]) => void; 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 ? (
) : files.length > 0 ? (

Attached files

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

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

))}
) : ( ); }; export default AttachSmall;