disable drag upload hint based on permission (#264)

* fix(uploader): prevent drag upload hint from showing in trash directory (cloudreve/cloudreve#2229)

* refactor(uploader): disable drag upload hint based on permission
This commit is contained in:
WittF 2025-06-20 21:03:17 +08:00 committed by GitHub
parent 0720c1a800
commit 93d616e742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<Base[]>([]);
const [dropBgOpen, setDropBgOpen] = useState(false);
const uploadEnabled = useRef<boolean>(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) => {