Files
spacedrive/interface/app/$libraryId/debug/dnd.tsx
Utku 7e5f7c0539 Make eslint happy (#2198)
* eslint maxing

* @sd/ui too
2024-03-12 20:41:41 +00:00

35 lines
951 B
TypeScript

import { useEffect, useRef } from 'react';
import { usePlatform } from '~/util/Platform';
export function DragAndDropDebug() {
const ref = useRef<HTMLDivElement>(null);
const platform = usePlatform();
useEffect(() => {
if (!platform.subscribeToDragAndDropEvents) return;
let finished = false;
const unsub = platform.subscribeToDragAndDropEvents((event) => {
if (finished) return;
console.log(JSON.stringify(event));
if (!ref.current) return;
if (event.type === 'Hovered') {
ref.current.classList.remove('hidden');
ref.current.style.left = `${event.x}px`;
ref.current.style.top = `${event.y}px`;
} else if (event.type === 'Dropped' || event.type === 'Cancelled') {
ref.current.classList.add('hidden');
}
});
return () => {
finished = true;
void unsub.then((unsub) => unsub());
};
}, [platform, ref]);
return <div ref={ref} className="absolute z-[500] hidden size-10 bg-red-500"></div>;
}