fix: show file icon when drag files

This commit is contained in:
Xu Quan 2025-03-04 15:53:31 +08:00
parent b0d3327293
commit 3f54fdfa69

View file

@ -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 (
<div
style={{
@ -24,7 +36,7 @@ const CustomDragLayer = () => {
zIndex: 100,
}}
>
{item instanceof TFile ? "📄" : "📁"}
{renderDraggingIcon()}
</div>
);
};