mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-26 08:56:47 +08:00
### What problem does this PR solve? Feat: Bind data to the agent module of the home page #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { useSetModalState } from '@/hooks/common-hooks';
|
|
import { UseRowSelectionType } from '@/hooks/logic-hooks/use-row-selection';
|
|
import { useMoveFile } from '@/hooks/use-file-request';
|
|
import { useCallback, useRef, useState } from 'react';
|
|
|
|
export const useHandleMoveFile = ({
|
|
clearRowSelection,
|
|
}: Pick<UseRowSelectionType, 'clearRowSelection'>) => {
|
|
const {
|
|
visible: moveFileVisible,
|
|
hideModal: hideMoveFileModal,
|
|
showModal: showMoveFileModal,
|
|
} = useSetModalState();
|
|
const { moveFile, loading } = useMoveFile();
|
|
const [sourceFileIds, setSourceFileIds] = useState<string[]>([]);
|
|
const isBulkRef = useRef(false);
|
|
|
|
const onMoveFileOk = useCallback(
|
|
async (targetFolderId: string) => {
|
|
const ret = await moveFile({
|
|
src_file_ids: sourceFileIds,
|
|
dest_file_id: targetFolderId,
|
|
});
|
|
|
|
if (ret === 0) {
|
|
if (isBulkRef.current) {
|
|
clearRowSelection();
|
|
}
|
|
hideMoveFileModal();
|
|
}
|
|
return ret;
|
|
},
|
|
[moveFile, sourceFileIds, hideMoveFileModal, clearRowSelection],
|
|
);
|
|
|
|
const handleShowMoveFileModal = useCallback(
|
|
(ids: string[], isBulk = false) => {
|
|
isBulkRef.current = isBulk;
|
|
setSourceFileIds(ids);
|
|
showMoveFileModal();
|
|
},
|
|
[showMoveFileModal],
|
|
);
|
|
|
|
return {
|
|
initialValue: '',
|
|
moveFileLoading: loading,
|
|
onMoveFileOk,
|
|
moveFileVisible,
|
|
hideMoveFileModal,
|
|
showMoveFileModal: handleShowMoveFileModal,
|
|
};
|
|
};
|
|
|
|
export type UseMoveDocumentReturnType = ReturnType<typeof useHandleMoveFile>;
|
|
|
|
export type UseMoveDocumentShowType = Pick<
|
|
ReturnType<typeof useHandleMoveFile>,
|
|
'showMoveFileModal'
|
|
>;
|