diff --git a/src/component/Uploader/Uploader.tsx b/src/component/Uploader/Uploader.tsx index 4472815..18ea540 100644 --- a/src/component/Uploader/Uploader.tsx +++ b/src/component/Uploader/Uploader.tsx @@ -1,6 +1,6 @@ import dayjs from "dayjs"; import { useSnackbar } from "notistack"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { closeUploadTaskList, openUploadTaskList, setUploadProgress } from "../../redux/globalStateSlice.ts"; import { useAppDispatch, useAppSelector } from "../../redux/hooks.ts"; @@ -12,6 +12,9 @@ import Base, { Status } from "./core/uploader/base.ts"; import { DropFileBackground } from "./DropFile.tsx"; import PasteUploadDialog from "./PasteUploadDialog.tsx"; import TaskList from "./Popup/TaskList.tsx"; +import useActionDisplayOpt from "../FileManager/ContextMenu/useActionDisplayOpt.ts"; +import { ContextMenuTypes } from "../../redux/fileManagerSlice.ts"; +import { FileManagerIndex } from "../FileManager/FileManager.tsx"; let totalProgressCollector: NodeJS.Timeout | null = null; let lastProgressStart = -1; @@ -25,15 +28,32 @@ const Uploader = () => { const { enqueueSnackbar } = useSnackbar(); const [uploaders, setUploaders] = useState([]); const [dropBgOpen, setDropBgOpen] = useState(false); + + const uploadEnabled = useRef(false); const totalProgress = useAppSelector((state) => state.globalState.uploadProgress); const taskListOpen = useAppSelector((state) => state.globalState.uploadTaskListOpen); - const parent = useAppSelector((state) => state.fileManager[0].list?.parent); - const path = useAppSelector((state) => state.fileManager[0].pure_path); - const policy = useAppSelector((state) => state.fileManager[0].list?.storage_policy); + const parent = useAppSelector((state) => state.fileManager[FileManagerIndex.main].list?.parent); + const path = useAppSelector((state) => state.fileManager[FileManagerIndex.main].pure_path); + const policy = useAppSelector((state) => state.fileManager[FileManagerIndex.main].list?.storage_policy); const selectFileSignal = useAppSelector((state) => state.globalState.uploadFileSignal); const selectFolderSignal = useAppSelector((state) => state.globalState.uploadFolderSignal); + const displayOpt = useActionDisplayOpt( + [], + ContextMenuTypes.empty, + parent, + FileManagerIndex.main, + ); + + useEffect(() => { + if (!parent) { + uploadEnabled.current = false; + return; + } + uploadEnabled.current = displayOpt.showUpload ?? false; + }, [parent, displayOpt.showUpload]); + const taskAdded = useCallback( (original?: Base) => (tasks: Base[]) => { if (original !== undefined) { @@ -69,10 +89,16 @@ const Uploader = () => { enqueueSnackbar(msg, { variant: type }); }, onDropOver: (_e) => { + if (!uploadEnabled.current) { + return; + } dragCounter++; setDropBgOpen((value) => !value); }, onDropLeave: (_e) => { + if (!uploadEnabled.current) { + return; + } dragCounter--; setDropBgOpen((value) => !value); }, @@ -84,11 +110,11 @@ const Uploader = () => { }, 1000); }, }); - }, []); + }, [enqueueSnackbar, taskAdded, dispatch]); useEffect(() => { uploadManager.setPolicy(policy, path); - }, [policy]); + }, [policy, path]); const handleUploaderError = useCallback( (e: any) => {