refactor: Extract single file download logic to custom hook (#8944)

 (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>
This commit is contained in:
Cristhian Zanforlin Lousa 2025-07-08 20:32:10 -03:00 committed by GitHub
commit 88803e31d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 8 deletions

View file

@ -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 };
};

View file

@ -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);

View file

@ -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";