Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(map): does not respect protected note of parent
Elian Doran4ab3b0dd2bc3
diff --git a/apps/client/src/widgets/collections/geomap/api.ts b/apps/client/src/widgets/collections/geomap/api.tsindex 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<CreateChildrenResponse>(`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.tsindex 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<keyof CommandMappings>[] = [@@ -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<keyof CommandMappings>[] = [...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.tsxindex 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 }: ViewMconst 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 ]);// Draggingconst containerRef = useRef<HTMLDivElement>(null);