mirror of
https://github.com/zadam/trilium.git
synced 2025-11-30 12:34:24 +01:00
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import type { LatLng, LeafletMouseEvent } from "leaflet";
|
|
import { LOCATION_ATTRIBUTE } from ".";
|
|
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";
|
|
|
|
const CHILD_NOTE_ICON = "bx bx-pin";
|
|
|
|
export async function moveMarker(noteId: string, latLng: LatLng | null) {
|
|
const value = latLng ? [latLng.lat, latLng.lng].join(",") : "";
|
|
await attributes.setLabel(noteId, LOCATION_ATTRIBUTE, value);
|
|
}
|
|
|
|
export async function createNewNote(noteId: string, 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`, {
|
|
title,
|
|
content: "",
|
|
type: "text"
|
|
});
|
|
attributes.setLabel(note.noteId, "iconClass", CHILD_NOTE_ICON);
|
|
moveMarker(note.noteId, e.latlng);
|
|
}
|
|
}
|