From 63c408c45b6d348498532b944a3c7df6ecf6b07c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 7 Jul 2025 18:02:32 +0300 Subject: [PATCH] feat(views/geomap): dragging notes that are not children --- .../widgets/view_widgets/geo_view/dragging.ts | 16 +++++++++++++--- .../src/widgets/view_widgets/geo_view/index.ts | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/client/src/widgets/view_widgets/geo_view/dragging.ts b/apps/client/src/widgets/view_widgets/geo_view/dragging.ts index df056aad5..bc1b0aa97 100644 --- a/apps/client/src/widgets/view_widgets/geo_view/dragging.ts +++ b/apps/client/src/widgets/view_widgets/geo_view/dragging.ts @@ -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, map: Map) { +export default function setupDragging($container: JQuery, 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, 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); } diff --git a/apps/client/src/widgets/view_widgets/geo_view/index.ts b/apps/client/src/widgets/view_widgets/geo_view/index.ts index ebb060693..3181773d8 100644 --- a/apps/client/src/widgets/view_widgets/geo_view/index.ts +++ b/apps/client/src/widgets/view_widgets/geo_view/index.ts @@ -159,7 +159,7 @@ export default class GeoView extends ViewMode { 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();