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:
parent
f390d3a4e9
commit
88803e31d2
4 changed files with 30 additions and 8 deletions
|
|
@ -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 };
|
||||||
|
};
|
||||||
|
|
@ -5,9 +5,9 @@ import {
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} 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 { useDeleteFileV2 } from "@/controllers/API/queries/file-management/use-delete-file";
|
||||||
import { useDuplicateFileV2 } from "@/controllers/API/queries/file-management/use-duplicate-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 ConfirmationModal from "@/modals/confirmationModal";
|
||||||
import useAlertStore from "@/stores/alertStore";
|
import useAlertStore from "@/stores/alertStore";
|
||||||
import { FileType } from "@/types/file_management";
|
import { FileType } from "@/types/file_management";
|
||||||
|
|
@ -29,11 +29,7 @@ export default function FilesContextMenuComponent({
|
||||||
|
|
||||||
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
||||||
|
|
||||||
const { mutate: downloadFile } = useGetDownloadFileV2({
|
const { handleSingleDownload } = useCustomHandleSingleFileDownload(file);
|
||||||
id: file.id,
|
|
||||||
filename: file.name,
|
|
||||||
type: file.path.split(".").pop() || "",
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mutate: deleteFile } = useDeleteFileV2({
|
const { mutate: deleteFile } = useDeleteFileV2({
|
||||||
id: file.id,
|
id: file.id,
|
||||||
|
|
@ -54,7 +50,7 @@ export default function FilesContextMenuComponent({
|
||||||
console.log("replace");
|
console.log("replace");
|
||||||
break;
|
break;
|
||||||
case "download":
|
case "download":
|
||||||
downloadFile();
|
handleSingleDownload();
|
||||||
break;
|
break;
|
||||||
case "delete":
|
case "delete":
|
||||||
setShowDeleteConfirmation(true);
|
setShowDeleteConfirmation(true);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||||
import { useGetFilesV2 } from "@/controllers/API/queries/file-management";
|
import { useGetFilesV2 } from "@/controllers/API/queries/file-management";
|
||||||
import { useDeleteFilesV2 } from "@/controllers/API/queries/file-management/use-delete-files";
|
import { useDeleteFilesV2 } from "@/controllers/API/queries/file-management/use-delete-files";
|
||||||
import { usePostRenameFileV2 } from "@/controllers/API/queries/file-management/use-put-rename-file";
|
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 { customPostUploadFileV2 } from "@/customization/hooks/use-custom-post-upload-file";
|
||||||
import useUploadFile from "@/hooks/files/use-upload-file";
|
import useUploadFile from "@/hooks/files/use-upload-file";
|
||||||
import DeleteConfirmationModal from "@/modals/deleteConfirmationModal";
|
import DeleteConfirmationModal from "@/modals/deleteConfirmationModal";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue