mirror of
https://github.com/zadam/trilium.git
synced 2026-03-14 16:10:23 +01:00
fix(map): does not respect protected note of parent
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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<HTMLDivElement>(null);
|
||||
|
||||
Reference in New Issue
Block a user