diff --git a/src/frontend/apps/drive/src/features/explorer/hooks/useTableKeyboardNavigation.ts b/src/frontend/apps/drive/src/features/explorer/hooks/useTableKeyboardNavigation.ts index dc229aca..2529d815 100644 --- a/src/frontend/apps/drive/src/features/explorer/hooks/useTableKeyboardNavigation.ts +++ b/src/frontend/apps/drive/src/features/explorer/hooks/useTableKeyboardNavigation.ts @@ -24,6 +24,10 @@ export const useTableKeyboardNavigation = ({ // the case by default, if we start the area selection from outside the table, the body will be focused instead of the table, making the // onKeyDown event not being triggered on table) + if (isDisabled) { + return; + } + if (tableRef.current) { tableRef.current.focus({ preventScroll: true, diff --git a/src/frontend/apps/drive/src/features/explorer/hooks/useUpload.tsx b/src/frontend/apps/drive/src/features/explorer/hooks/useUpload.tsx index 78905705..93ad77ad 100644 --- a/src/frontend/apps/drive/src/features/explorer/hooks/useUpload.tsx +++ b/src/frontend/apps/drive/src/features/explorer/hooks/useUpload.tsx @@ -13,6 +13,9 @@ import { addToast } from "@/features/ui/components/toaster/Toaster"; import { FileUploadToast } from "../components/toasts/FileUploadToast"; import { useQueryClient } from "@tanstack/react-query"; import { getEntitlements } from "@/utils/entitlements"; +import { useCanCreateChildren } from "@/features/items/utils"; +import { getMyFilesQueryKey } from "@/utils/defaultRoutes"; +import { useRouter } from "next/router"; type FileUpload = FileWithPath & { parentId?: string; @@ -33,6 +36,7 @@ type Upload = { }; const useUpload = ({ item }: { item: Item }) => { + const router = useRouter(); const createFolder = useMutationCreateFolder(); const queryClient = useQueryClient(); @@ -117,10 +121,11 @@ const useUpload = ({ item }: { item: Item }) => { // Create the folders and assign each file a parentId. const createFoldersFromDrop = async ( - parentItem: Item, + parentItem: Item | undefined, folderUploads: FolderUpload[] ) => { const promises = []; + for (const folder of folderUploads) { promises.push( () => @@ -128,13 +133,21 @@ const useUpload = ({ item }: { item: Item }) => { createFolder.mutate( { title: folder.item.title!, - parentId: parentItem.id, + parentId: parentItem?.id, }, { onSuccess: async (createdFolder) => { - queryClient.invalidateQueries({ - queryKey: ["items", parentItem.id], - }); + + queryClient.invalidateQueries({ + queryKey: getMyFilesQueryKey(), + }); + + if (parentItem) { + queryClient.invalidateQueries({ + queryKey: ["items", parentItem.id], + }); + } + folder.files.forEach((file) => { file.parentId = createdFolder.id; }); @@ -154,9 +167,9 @@ const useUpload = ({ item }: { item: Item }) => { // Assign each file a parentId and create the folders if it is a folder upload. const handleHierarchy = async (upload: Upload) => { upload.folder.files.forEach((file) => { - file.parentId = item!.id; + file.parentId = item?.id; }); - await createFoldersFromDrop(item!, upload.folder.children); + await createFoldersFromDrop(item, upload.folder.children); }; return { @@ -187,8 +200,11 @@ const pathNicefy = (path: string) => { export const useUploadZone = ({ item }: { item: Item }) => { const { t } = useTranslation(); + const createFile = useMutationCreateFile(); + const canCreateChildren = useCanCreateChildren(item); + const fileDragToastId = useRef(null); const fileUploadsToastId = useRef(null); const [uploadingState, setUploadingState] = useState({ @@ -199,7 +215,7 @@ export const useUploadZone = ({ item }: { item: Item }) => { const { filesToUpload, handleHierarchy } = useUpload({ item: item! }); const validateDrop = () => { - const canUpload = item?.abilities?.children_create ?? false; + const canUpload = canCreateChildren; if (!canUpload) { return { code: "no-upload-rights", @@ -229,7 +245,7 @@ export const useUploadZone = ({ item }: { item: Item }) => { return; } - const canUpload = item?.abilities?.children_create ?? false; + const canUpload = canCreateChildren; fileDragToastId.current = addToast( { dismissDragToast(); }, onDrop: async (acceptedFiles) => { - if (!(item?.abilities?.children_create ?? false)) { + if (!canCreateChildren) { dismissDragToast(); return; } @@ -357,7 +373,7 @@ export const useUploadZone = ({ item }: { item: Item }) => { { filename: file.name, file, - parentId: file.parentId!, + parentId: file.parentId, progressHandler: (progress) => { setUploadingState((prev) => { const newState = { @@ -419,7 +435,11 @@ export const useUploadZone = ({ item }: { item: Item }) => { useEffect(() => { const unloadCallback = (event: BeforeUnloadEvent) => { - if ([UploadingStep.CREATE_FOLDERS, UploadingStep.UPLOAD_FILES].includes(uploadingState.step)) { + if ( + [UploadingStep.CREATE_FOLDERS, UploadingStep.UPLOAD_FILES].includes( + uploadingState.step + ) + ) { event.preventDefault(); } return "";