import { Ban, FileDown, Loader2 } from 'lucide-react'; import { useRef, useState, type DragEvent, type ReactNode } from 'react'; import { useTranslation } from '../../i18n'; import { fs } from '../shared/DialogShell'; import TourGpxPreviewDialog from './TourGpxPreviewDialog'; import type { TourGpxImport } from './useTourGpxImport'; /** Only a drag of files from the desktop; a waypoint or a tour row being dragged is not one. */ const carriesFiles = (event: DragEvent) => Array.from(event.dataTransfer.types).includes('Files'); /** * The tours workspace as a drop target for GPX files: a file dragged over it * dims the workspace and says what will happen, and a drop hands the files to * the same import the button runs. While an import runs, the overlay stays and * says so. A drag of anything else (a waypoint in the list, the map) passes * straight through. */ export default function TourGpxDropZone({ gpxImport, canEdit, className = 'relative', children, }: { gpxImport: TourGpxImport; canEdit: boolean; /** Positions the zone; it must be positioned for the overlay to cover it. */ className?: string; children: ReactNode; }) { const { t } = useTranslation(); const [over, setOver] = useState(false); // dragenter and dragleave fire for every child the pointer crosses, so the // overlay goes only when the count of entered elements is back at zero. const depth = useRef(0); const reset = () => { depth.current = 0; setOver(false); }; return (