mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-06 18:45:08 +08:00
### What problem does this PR solve? Feat: Upload files in the chat box #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
27
web/src/pages/next-chats/hooks/use-upload-file.ts
Normal file
27
web/src/pages/next-chats/hooks/use-upload-file.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { FileUploadProps } from '@/components/file-upload';
|
||||
import { useUploadAndParseFile } from '@/hooks/use-chat-request';
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
export function useUploadFile() {
|
||||
const { uploadAndParseFile } = useUploadAndParseFile();
|
||||
const [fileIds, setFileIds] = useState<string[]>([]);
|
||||
|
||||
const handleUploadFile: NonNullable<FileUploadProps['onUpload']> =
|
||||
useCallback(
|
||||
async (files) => {
|
||||
if (Array.isArray(files) && files.length) {
|
||||
const ret = await uploadAndParseFile(files[0]);
|
||||
if (ret.code === 0 && Array.isArray(ret.data)) {
|
||||
setFileIds((list) => [...list, ...ret.data]);
|
||||
}
|
||||
}
|
||||
},
|
||||
[uploadAndParseFile],
|
||||
);
|
||||
|
||||
const clearFileIds = useCallback(() => {
|
||||
setFileIds([]);
|
||||
}, []);
|
||||
|
||||
return { handleUploadFile, clearFileIds, fileIds };
|
||||
}
|
||||
Reference in New Issue
Block a user