Skip to content

Build your personal knowledge base with Trilium Notes

fix(collections): make embedded collection command buttons work

Elian Dorand28fa3a5e9a6
diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.ts
index 2b625b67be..b84eb4478a 100644
--- a/apps/client/src/services/content_renderer.ts
+++ b/apps/client/src/services/content_renderer.ts
@@ -376,6 +376,18 @@ async function mountInteractiveWidget(vnode: JSX.Element, container: HTMLElement
import("../components/app_context")
]);
renderReactWidgetAtElement(appContext, vnode, container);
+
+ // The global [data-trigger-command] click delegate resolves its handler via
+ // closest(".component").prop("component"). A standalone mount has no legacy widget setting that
+ // prop (ReactWrappedWidget does it in the note detail), so point the rendered ".component"
+ // element(s) at appContext — an unhandled command there is converted into an event, reaching the
+ // widget's own useTriliumEvent subscription. Without it an embedded command button (e.g. the geo
+ // map "Add marker") throws "component is undefined".
+ for (const el of container.querySelectorAll<HTMLElement>(".component")) {
+ if (!$(el).prop("component")) {
+ $(el).prop("component", appContext);
+ }
+ }
}
/**
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index 4d0f86b8c0..396759df5e 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -64,8 +64,11 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
setZoom(viewConfig?.view?.zoom ?? DEFAULT_ZOOM);
}, [ note, viewConfig ]);
- // Note creation.
- useTriliumEvent("geoMapCreateChildNote", () => {
+ // Note creation. Scoped to this map instance via a local callback rather than the global
+ // geoMapCreateChildNote command: embedded maps share no note context (no distinct ntxId), so a
+ // broadcast command would arm placement mode on every map at once. The button is this command's
+ // only trigger, so a direct handler keeps it isolated to the clicked map.
+ const startNotePlacement = useCallback(() => {
toast.showPersistent({
icon: "plus",
id: "geo-new-note",
@@ -75,7 +78,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
setState(State.NewNote);
- const globalKeyListener: (this: Window, ev: KeyboardEvent) => any = (e) => {
+ const globalKeyListener: (this: Window, ev: KeyboardEvent) => void = (e) => {
if (e.key === "Escape") {
setState(State.Normal);
@@ -84,7 +87,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
}
};
window.addEventListener("keydown", globalKeyListener);
- });
+ }, []);
useTriliumEvent("deleteFromMap", ({ noteId }) => {
moveMarker(noteId, null);
@@ -142,7 +145,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
icon="bx bx-plus"
text={t("geo-map.create-child-note-text")}
title={t("geo-map.create-child-note-title")}
- triggerCommand="geoMapCreateChildNote"
+ onClick={startNotePlacement}
disabled={isReadOnly}
/>
</>}