From 3f54fdfa690e2c18d266cb9ed26cb43383e9561e Mon Sep 17 00:00:00 2001 From: Xu Quan Date: Tue, 4 Mar 2025 15:53:31 +0800 Subject: [PATCH] fix: show file icon when drag files --- src/components/CustomDragLayer.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/CustomDragLayer.tsx b/src/components/CustomDragLayer.tsx index cd59376..b53bce5 100644 --- a/src/components/CustomDragLayer.tsx +++ b/src/components/CustomDragLayer.tsx @@ -1,10 +1,14 @@ -import { TFile } from "obsidian"; import { useDragLayer } from "react-dnd"; +import { + FFS_DRAG_FILES_TYPE, + FFS_DRAG_FOLDER_TYPE, +} from "src/assets/constants"; const CustomDragLayer = () => { - const { isDragging, item, currentOffset } = useDragLayer((monitor) => ({ + const { isDragging, currentOffset, itemType } = useDragLayer((monitor) => ({ isDragging: monitor.isDragging(), item: monitor.getItem(), + itemType: monitor.getItemType(), currentOffset: monitor.getClientOffset(), })); @@ -12,6 +16,14 @@ const CustomDragLayer = () => { return null; } + const renderDraggingIcon = () => { + if (itemType === FFS_DRAG_FOLDER_TYPE) { + return "📁"; + } else if (itemType === FFS_DRAG_FILES_TYPE) { + return "📄"; + } + }; + return (
{ zIndex: 100, }} > - {item instanceof TFile ? "📄" : "📁"} + {renderDraggingIcon()}
); };