mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 16:59:21 +08:00
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
'use client'
|
|
import FileListItem from './components/file-list-item'
|
|
import UploadDropzone from './components/upload-dropzone'
|
|
import { useLocalFileUpload } from './hooks/use-local-file-upload'
|
|
|
|
type LocalFileProps = {
|
|
allowedExtensions: string[]
|
|
supportBatchUpload?: boolean
|
|
}
|
|
|
|
const LocalFile = ({
|
|
allowedExtensions,
|
|
supportBatchUpload = true,
|
|
}: LocalFileProps) => {
|
|
const {
|
|
dropRef,
|
|
dragRef,
|
|
fileUploaderRef,
|
|
dragging,
|
|
localFileList,
|
|
fileUploadConfig,
|
|
acceptTypes,
|
|
supportTypesShowNames,
|
|
hideUpload,
|
|
selectHandle,
|
|
fileChangeHandle,
|
|
removeFile,
|
|
handlePreview,
|
|
} = useLocalFileUpload({ allowedExtensions, supportBatchUpload })
|
|
|
|
return (
|
|
<div className="flex flex-col">
|
|
{!hideUpload && (
|
|
<UploadDropzone
|
|
dropRef={dropRef}
|
|
dragRef={dragRef}
|
|
fileUploaderRef={fileUploaderRef}
|
|
dragging={dragging}
|
|
supportBatchUpload={supportBatchUpload}
|
|
supportTypesShowNames={supportTypesShowNames}
|
|
fileUploadConfig={fileUploadConfig}
|
|
acceptTypes={acceptTypes}
|
|
onSelectFile={selectHandle}
|
|
onFileChange={fileChangeHandle}
|
|
allowedExtensions={allowedExtensions}
|
|
/>
|
|
)}
|
|
{localFileList.length > 0 && (
|
|
<div className="mt-1 flex flex-col gap-y-1">
|
|
{localFileList.map((fileItem, index) => (
|
|
<FileListItem
|
|
key={`${fileItem.fileID}-${index}`}
|
|
fileItem={fileItem}
|
|
onPreview={handlePreview}
|
|
onRemove={removeFile}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default LocalFile
|