diff --git a/src/frontend/src/customization/hooks/custom-handle-bulk-files-download.tsx b/src/frontend/src/customization/hooks/custom-handle-bulk-files-download.tsx new file mode 100644 index 000000000..0103d719d --- /dev/null +++ b/src/frontend/src/customization/hooks/custom-handle-bulk-files-download.tsx @@ -0,0 +1,36 @@ +import { useGetDownloadFilesV2 } from "@/controllers/API/queries/file-management/use-get-download-files"; + +export const useCustomHandleBulkFilesDownload = () => { + const { mutate: downloadFiles } = useGetDownloadFilesV2(); + + const handleBulkDownload = ( + selectedFiles: any, + setSuccessData: (data: { title: string }) => void, + setErrorData: (data: { title: string; list: string[] }) => void, + setIsDownloading: (isDownloading: boolean) => void, + ) => { + setIsDownloading(true); + downloadFiles( + { + ids: selectedFiles.map((file) => file.id), + }, + { + onSuccess: (data) => { + setSuccessData({ title: data.message }); + setIsDownloading(false); + }, + onError: (error) => { + setErrorData({ + title: "Error downloading files", + list: [ + error.message || "An error occurred while downloading the files", + ], + }); + setIsDownloading(false); + }, + }, + ); + }; + + return { handleBulkDownload }; +}; diff --git a/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx b/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx index 1774e45a5..71bd99221 100644 --- a/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx +++ b/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx @@ -8,8 +8,8 @@ import Loading from "@/components/ui/loading"; import { SidebarTrigger } from "@/components/ui/sidebar"; import { useGetFilesV2 } from "@/controllers/API/queries/file-management"; import { useDeleteFilesV2 } from "@/controllers/API/queries/file-management/use-delete-files"; -import { useGetDownloadFilesV2 } from "@/controllers/API/queries/file-management/use-get-download-files"; import { usePostRenameFileV2 } from "@/controllers/API/queries/file-management/use-put-rename-file"; +import { useCustomHandleBulkFilesDownload } from "@/customization/hooks/custom-handle-bulk-files-download"; import { customPostUploadFileV2 } from "@/customization/hooks/use-custom-post-upload-file"; import useUploadFile from "@/hooks/files/use-upload-file"; import DeleteConfirmationModal from "@/modals/deleteConfirmationModal"; @@ -37,6 +37,7 @@ export const FilesPage = () => { const [selectedFiles, setSelectedFiles] = useState([]); const [quantitySelected, setQuantitySelected] = useState(0); const [isShiftPressed, setIsShiftPressed] = useState(false); + const [isDownloading, setIsDownloading] = useState(false); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { @@ -75,8 +76,7 @@ export const FilesPage = () => { const { mutate: rename } = usePostRenameFileV2(); const { mutate: deleteFiles, isPending: isDeleting } = useDeleteFilesV2(); - const { mutate: downloadFiles, isPending: isDownloading } = - useGetDownloadFilesV2(); + const { handleBulkDownload } = useCustomHandleBulkFilesDownload(); const handleRename = (params: NewValueParams) => { rename({ @@ -251,26 +251,14 @@ export const FilesPage = () => { }; const handleDownload = () => { - console.log(selectedFiles); - downloadFiles( - { - ids: selectedFiles.map((file) => file.id), - }, - { - onSuccess: (data) => { - setSuccessData({ title: data.message }); - }, - onError: (error) => { - setErrorData({ - title: "Error downloading files", - list: [ - error.message || "An error occurred while downloading the files", - ], - }); - }, - }, + handleBulkDownload( + selectedFiles, + setSuccessData, + setErrorData, + setIsDownloading, ); }; + const handleDelete = () => { deleteFiles( {