mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-04 03:25:30 +08:00
### What problem does this PR solve? Feat: Upload document #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
35
web/src/pages/files/use-upload-file.ts
Normal file
35
web/src/pages/files/use-upload-file.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useUploadFile } from '@/hooks/use-file-request';
|
||||
import { useCallback } from 'react';
|
||||
import { useGetFolderId } from './hooks';
|
||||
|
||||
export const useHandleUploadFile = () => {
|
||||
const {
|
||||
visible: fileUploadVisible,
|
||||
hideModal: hideFileUploadModal,
|
||||
showModal: showFileUploadModal,
|
||||
} = useSetModalState();
|
||||
const { uploadFile, loading } = useUploadFile();
|
||||
const id = useGetFolderId();
|
||||
|
||||
const onFileUploadOk = useCallback(
|
||||
async (fileList: File[]): Promise<number | undefined> => {
|
||||
if (fileList.length > 0) {
|
||||
const ret: number = await uploadFile({ fileList, parentId: id });
|
||||
if (ret === 0) {
|
||||
hideFileUploadModal();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
[uploadFile, hideFileUploadModal, id],
|
||||
);
|
||||
|
||||
return {
|
||||
fileUploadLoading: loading,
|
||||
onFileUploadOk,
|
||||
fileUploadVisible,
|
||||
hideFileUploadModal,
|
||||
showFileUploadModal,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user