diff --git a/apps/client/src/widgets/collections/geomap/api.ts b/apps/client/src/widgets/collections/geomap/api.ts index 5f73415605..4a839cac5d 100644 --- a/apps/client/src/widgets/collections/geomap/api.ts +++ b/apps/client/src/widgets/collections/geomap/api.ts @@ -1,10 +1,11 @@ import type { LatLng, LeafletMouseEvent } from "leaflet"; -import { LOCATION_ATTRIBUTE } from "."; + +import FNote from "../../../entities/fnote"; import attributes from "../../../services/attributes"; import { prompt } from "../../../services/dialog"; -import server from "../../../services/server"; import { t } from "../../../services/i18n"; -import { CreateChildrenResponse } from "@triliumnext/commons"; +import note_create from "../../../services/note_create"; +import { LOCATION_ATTRIBUTE } from "."; const CHILD_NOTE_ICON = "bx bx-pin"; @@ -13,15 +14,19 @@ export async function moveMarker(noteId: string, latLng: LatLng | null) { await attributes.setLabel(noteId, LOCATION_ATTRIBUTE, value); } -export async function createNewNote(noteId: string, e: LeafletMouseEvent) { +export async function createNewNote(parentNote: FNote, e: LeafletMouseEvent) { const title = await prompt({ message: t("relation_map.enter_title_of_new_note"), defaultValue: t("relation_map.default_new_note_title") }); if (title?.trim()) { - const { note } = await server.post(`notes/${noteId}/children?target=into`, { + const { note } = await note_create.createNote(parentNote.noteId, { title, content: "", - type: "text" + type: "text", + activate: false, + isProtected: parentNote.isProtected }); + if (!note) return; + attributes.setLabel(note.noteId, "iconClass", CHILD_NOTE_ICON); moveMarker(note.noteId, e.latlng); } diff --git a/apps/client/src/widgets/collections/geomap/context_menu.ts b/apps/client/src/widgets/collections/geomap/context_menu.ts index 47026566fc..b4ae723877 100644 --- a/apps/client/src/widgets/collections/geomap/context_menu.ts +++ b/apps/client/src/widgets/collections/geomap/context_menu.ts @@ -1,12 +1,14 @@ import type { LatLng, LeafletMouseEvent } from "leaflet"; + import appContext, { type CommandMappings } from "../../../components/app_context.js"; +import FNote from "../../../entities/fnote.js"; import contextMenu, { type MenuItem } from "../../../menus/context_menu.js"; -import linkContextMenu from "../../../menus/link_context_menu.js"; import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker.jsx"; -import { t } from "../../../services/i18n.js"; -import { createNewNote } from "./api.js"; +import linkContextMenu from "../../../menus/link_context_menu.js"; import { copyTextWithToast } from "../../../services/clipboard_ext.js"; +import { t } from "../../../services/i18n.js"; import link from "../../../services/link.js"; +import { createNewNote } from "./api.js"; export default function openContextMenu(noteId: string, e: LeafletMouseEvent, isEditable: boolean) { let items: MenuItem[] = [ @@ -44,7 +46,7 @@ export default function openContextMenu(noteId: string, e: LeafletMouseEvent, is }); } -export function openMapContextMenu(noteId: string, e: LeafletMouseEvent, isEditable: boolean) { +export function openMapContextMenu(note: FNote, e: LeafletMouseEvent, isEditable: boolean) { let items: MenuItem[] = [ ...buildGeoLocationItem(e) ]; @@ -55,10 +57,10 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent, isEdita { kind: "separator" }, { title: t("geo-map-context.add-note"), - handler: () => createNewNote(noteId, e), + handler: () => createNewNote(note, e), uiIcon: "bx bx-plus" } - ] + ]; } contextMenu.show({ diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx index 8be547fa3a..cb4b33b5af 100644 --- a/apps/client/src/widgets/collections/geomap/index.tsx +++ b/apps/client/src/widgets/collections/geomap/index.tsx @@ -93,14 +93,14 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM const onClick = useCallback(async (e: LeafletMouseEvent) => { if (state === State.NewNote) { toast.closePersistent("geo-new-note"); - await createNewNote(note.noteId, e); + await createNewNote(note, e); setState(State.Normal); } - }, [ state ]); + }, [ note, state ]); const onContextMenu = useCallback((e: LeafletMouseEvent) => { - openMapContextMenu(note.noteId, e, !isReadOnly); - }, [ note.noteId, isReadOnly ]); + openMapContextMenu(note, e, !isReadOnly); + }, [ note, isReadOnly ]); // Dragging const containerRef = useRef(null);