feat(views/geomap): dragging notes that are not children

This commit is contained in:
Elian Doran 2025-07-07 18:02:32 +03:00
parent 2a665dffbc
commit 63c408c45b
No known key found for this signature in database
2 changed files with 14 additions and 4 deletions

View file

@ -1,13 +1,15 @@
import type { Map } from "leaflet";
import type { DragData } from "../../note_tree.js";
import { moveMarker } from "./editing";
import froca from "../../../services/froca.js";
import branches from "../../../services/branches.js";
export default function setupDragging($container: JQuery<HTMLElement>, map: Map) {
export default function setupDragging($container: JQuery<HTMLElement>, map: Map, mapNoteId: string) {
$container.on("dragover", (e) => {
// Allow drag.
e.preventDefault();
});
$container.on("drop", (e) => {
$container.on("drop", async (e) => {
if (!e.originalEvent) {
return;
}
@ -30,7 +32,15 @@ export default function setupDragging($container: JQuery<HTMLElement>, map: Map)
var y = e.originalEvent.clientY - (offset?.top ?? 0);
const latlng = map.containerPointToLatLng([ x, y ]);
moveMarker(noteId, latlng);
const note = await froca.getNote(noteId, true);
const parents = note?.getParentNoteIds();
if (parents?.includes(mapNoteId)) {
await moveMarker(noteId, latlng);
} else {
await branches.cloneNoteToParentNote(noteId, mapNoteId);
await moveMarker(noteId, latlng);
}
} catch (e) {
console.warn(e);
}

View file

@ -159,7 +159,7 @@ export default class GeoView extends ViewMode<MapData> {
map.on("zoomend", updateFn);
map.on("click", (e) => this.#onMapClicked(e))
map.on("contextmenu", (e) => openMapContextMenu(this.parentNote.noteId, e));
setupDragging(this.$container, map);
setupDragging(this.$container, map, this.parentNote.noteId);
this.#reloadMarkers();