Files
ragflow/web/src/pages/files/use-move-file.ts
balibabu 5bb1c383ac Feat: Bind data to the agent module of the home page #3221 (#7385)
### 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)
2025-04-29 09:50:54 +08:00

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'
>;