Skip to content

Improved drag and drop#1799

Open
Dima-1 wants to merge 14 commits into
mainfrom
ui-drag-and-drop
Open

Improved drag and drop#1799
Dima-1 wants to merge 14 commits into
mainfrom
ui-drag-and-drop

Conversation

@Dima-1

@Dima-1 Dima-1 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements an improved drag-and-drop flow for importing track files into OsmAnd Cloud, including visual drop overlays and folder-targeted dropping from the Tracks UI.

Changes:

  • Added a global GPX drag controller + geometry helpers to resolve drop targets (map vs tracks menu folders) and show contextual overlays.
  • Refactored Cloud GPX/KMZ/KML import into a shared useCloudGpxImport hook and reused it from both drag-and-drop and the existing uploader.
  • Enhanced UX by styling drop targets in the Tracks menu and enabling “zoom to track” after successful upload/open.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
map/src/util/hooks/useCloudGpxImport.js New shared hook for importing GPX/KMZ/KML into OsmAnd Cloud.
map/src/menu/tracks/TracksMenu.jsx Marks the tracks list container as a drop target (data attribute + styling hook).
map/src/menu/tracks/TrackGroupFolder.jsx Marks opened folders as drop targets for folder-specific imports.
map/src/menu/tracks/CloudTrackGroup.jsx Adds drop-hover styling and folder targeting metadata for groups.
map/src/menu/trackfavmenu.module.css Adds drop-target styles for folders/groups.
map/src/map/layers/LocalClientTrackLayer.js Removes the old map-only drag/drop handling in favor of the global controller.
map/src/map/components/GpxMenuDropOverlay.jsx New overlay for menu-drop guidance (positioned to menu region).
map/src/map/components/gpxMapDropOverlay.module.css Updates overlay styling and renames .overlay.dropOverlay.
map/src/map/components/GpxMapDropOverlay.jsx Converts overlay to use AppContext drag state + computed insets.
map/src/map/components/GpxMapDropGeometry.js New helper module for computing visible map/menu drop geometry + target resolution.
map/src/map/components/GpxFileDragController.jsx New global window-level drag/drop controller, triggers cloud import into resolved folder.
map/src/manager/track/TracksManager.js Adds IMPORT_FOLDER_NAME constant used for map-drop default folder.
map/src/manager/track/SaveTrackManager.js Sets zoomToTrack when opening a just-uploaded track.
map/src/frame/util/CloudGpxUploader.jsx Refactors uploader to use the shared cloud import hook.
map/src/frame/GlobalFrame.js Mounts the global drag controller and moves main menu open-state to AppContext.
map/src/context/AppContext.js Adds openMainMenu and gpxFileDrag to shared app context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread map/src/util/hooks/useCloudGpxImport.js Outdated

@alisa911 alisa911 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename all the new files away from the gpx prefix, the feature handles not only GPX (also KMZ/KML), but only tracks (not favorites). Also move these files out of map/ into frame/, since they're not map-specific.

Comment thread map/src/frame/TracksFileDragController.jsx Outdated
Comment thread map/src/frame/TracksFileDragController.jsx
Comment thread map/src/util/hooks/useCloudGpxImport.js Outdated
Comment thread map/src/util/hooks/useCloudGpxImport.js
Comment thread map/src/manager/track/TracksManager.js
Comment thread map/src/map/components/GpxMenuDropOverlay.jsx Outdated
Comment thread map/src/map/components/GpxMenuDropOverlay.jsx Outdated
Comment thread map/src/map/components/GpxMenuDropOverlay.jsx Outdated
Comment thread map/src/map/components/GpxMenuDropOverlay.jsx Outdated
Comment thread map/src/menu/tracks/TrackGroupFolder.jsx Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.

Comment on lines +1 to +21
import { useContext, useEffect } from 'react';
import { createPortal } from 'react-dom';
import AppContext from '../context/AppContext';
import LoginContext from '../context/LoginContext';
import { IMPORT_FOLDER_NAME } from '../manager/track/TracksManager';
import useCloudGpxImport from '../util/hooks/useCloudGpxImport';
import TracksDropOverlay from './TracksDropOverlay';

export const GPX_FILE_DRAG_IDLE = { active: false, hoverFolder: null, overMap: false };

export function hasFiles(e) {
return e.dataTransfer?.types?.includes('Files');
}

export default function TracksFileDragController() {
const ctx = useContext(AppContext);
const ltx = useContext(LoginContext);
const { importGpxFiles } = useCloudGpxImport();
const isProAccount = ltx.isProAccount();

useEffect(() => {
Comment on lines +64 to +66
const files = Array.from(e.dataTransfer?.files || []);
const { hoverFolder, overMap } = ctx.gpxFileDrag ?? GPX_FILE_DRAG_IDLE;
if (hoverFolder !== null) {
container.removeEventListener('drop', onDrop);
window.removeEventListener('dragend', onDragEnd);
};
}, [ctx.gpxFileDrag, ctx.setGpxFileDrag, importGpxFiles, isProAccount]);
Comment on lines +31 to +52
const loadingName = removeFileExtension(file.name) + GPX_FILE_EXT;
const reader = new FileReader();
reader.addEventListener('load', (e) => {
const data = e.target.result;
if (data) {
resolve({
file,
selected,
data: data,
name: file.name,
originalName: file.name,
folder,
});
} else {
ctx.setTrackErrorMsg({
title: 'Import error',
msg: `Unable to import ${file.name}`,
});
ctx.setTrackLoading((prev) => prev.filter((n) => n !== loadingName));
resolve(null);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants