From 88803e31d2c3d1cabe099ea5b41747055ef98dec Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 8 Jul 2025 20:32:10 -0300 Subject: [PATCH] refactor: Extract single file download logic to custom hook (#8944) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ (use-custom-handle-bulk-files-download.ts): add custom hook to handle bulk files download functionality ✨ (use-custom-handle-single-file-download.ts): add custom hook to handle single file download functionality 🔧 (index.tsx): fix import path for use-custom-handle-bulk-files-download hook in filesPage 🔧 (index.tsx): fix import path for use-custom-handle-single-file-download hook in filesContextMenuComponent Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com> --- ... use-custom-handle-bulk-files-download.ts} | 0 .../use-custom-handle-single-file-download.ts | 26 +++++++++++++++++++ .../filesContextMenuComponent/index.tsx | 10 +++---- .../pages/MainPage/pages/filesPage/index.tsx | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) rename src/frontend/src/customization/hooks/{custom-handle-bulk-files-download.tsx => use-custom-handle-bulk-files-download.ts} (100%) create mode 100644 src/frontend/src/customization/hooks/use-custom-handle-single-file-download.ts diff --git a/src/frontend/src/customization/hooks/custom-handle-bulk-files-download.tsx b/src/frontend/src/customization/hooks/use-custom-handle-bulk-files-download.ts similarity index 100% rename from src/frontend/src/customization/hooks/custom-handle-bulk-files-download.tsx rename to src/frontend/src/customization/hooks/use-custom-handle-bulk-files-download.ts diff --git a/src/frontend/src/customization/hooks/use-custom-handle-single-file-download.ts b/src/frontend/src/customization/hooks/use-custom-handle-single-file-download.ts new file mode 100644 index 000000000..53725525b --- /dev/null +++ b/src/frontend/src/customization/hooks/use-custom-handle-single-file-download.ts @@ -0,0 +1,26 @@ +import { useGetDownloadFileV2 } from "@/controllers/API/queries/file-management"; +import { FileType } from "@/types/file_management"; + +interface SingleFileDownloadParams { + id: string; + filename: string; + type: string; +} + +export const useCustomHandleSingleFileDownload = (file: FileType) => { + const { mutate: downloadFile } = useGetDownloadFileV2({ + id: file.id, + filename: file.name, + type: file.path.split(".").pop() || "", + }); + + const handleSingleDownload = ( + params?: SingleFileDownloadParams, + setSuccessData?: (data: { title: string }) => void, + setErrorData?: (data: { title: string; list: string[] }) => void, + ) => { + downloadFile(); + }; + + return { handleSingleDownload }; +}; diff --git a/src/frontend/src/modals/fileManagerModal/components/filesContextMenuComponent/index.tsx b/src/frontend/src/modals/fileManagerModal/components/filesContextMenuComponent/index.tsx index 21f0b5fbd..d309eb825 100644 --- a/src/frontend/src/modals/fileManagerModal/components/filesContextMenuComponent/index.tsx +++ b/src/frontend/src/modals/fileManagerModal/components/filesContextMenuComponent/index.tsx @@ -5,9 +5,9 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; -import { useGetDownloadFileV2 } from "@/controllers/API/queries/file-management"; import { useDeleteFileV2 } from "@/controllers/API/queries/file-management/use-delete-file"; import { useDuplicateFileV2 } from "@/controllers/API/queries/file-management/use-duplicate-file"; +import { useCustomHandleSingleFileDownload } from "@/customization/hooks/use-custom-handle-single-file-download"; import ConfirmationModal from "@/modals/confirmationModal"; import useAlertStore from "@/stores/alertStore"; import { FileType } from "@/types/file_management"; @@ -29,11 +29,7 @@ export default function FilesContextMenuComponent({ const setSuccessData = useAlertStore((state) => state.setSuccessData); - const { mutate: downloadFile } = useGetDownloadFileV2({ - id: file.id, - filename: file.name, - type: file.path.split(".").pop() || "", - }); + const { handleSingleDownload } = useCustomHandleSingleFileDownload(file); const { mutate: deleteFile } = useDeleteFileV2({ id: file.id, @@ -54,7 +50,7 @@ export default function FilesContextMenuComponent({ console.log("replace"); break; case "download": - downloadFile(); + handleSingleDownload(); break; case "delete": setShowDeleteConfirmation(true); diff --git a/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx b/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx index 60bfe98a8..ae14eeb49 100644 --- a/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx +++ b/src/frontend/src/pages/MainPage/pages/filesPage/index.tsx @@ -9,7 +9,7 @@ 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 { usePostRenameFileV2 } from "@/controllers/API/queries/file-management/use-put-rename-file"; -import { useCustomHandleBulkFilesDownload } from "@/customization/hooks/custom-handle-bulk-files-download"; +import { useCustomHandleBulkFilesDownload } from "@/customization/hooks/use-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";