From 73213d2a17feb83eeaac5b9813f239edfa5427b7 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 5 Oct 2025 16:59:46 +0300 Subject: [PATCH] refactor(react/type_widgets): bring back execute with type widget --- apps/client/src/widgets/NoteDetail.tsx | 17 ++++- apps/client/src/widgets/note_detail.ts.bak | 77 ---------------------- 2 files changed, 16 insertions(+), 78 deletions(-) diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsx index 617380c76..b3acd80d3 100644 --- a/apps/client/src/widgets/NoteDetail.tsx +++ b/apps/client/src/widgets/NoteDetail.tsx @@ -19,6 +19,7 @@ import { isMobile } from "../services/utils"; * - Caches the note type elements based on what the user has accessed, in order to quickly load it again. */ export default function NoteDetail() { + const containerRef = useRef(null); const { note, type, mime, noteContext, parentComponent } = useNoteInfo(); const { ntxId, viewScope } = noteContext ?? {}; const isFullHeight = checkFullHeight(noteContext, type); @@ -103,8 +104,22 @@ export default function NoteDetail() { document.body.classList.toggle("force-fixed-tree", hasFixedTree); }, [ note ]); + useTriliumEvent("executeWithTypeWidget", ({ resolve, ntxId: eventNtxId }) => { + if (eventNtxId !== ntxId || !activeNoteType || !containerRef.current) return; + + const classNameToSearch = TYPE_MAPPINGS[activeNoteType].className; + const componentEl = containerRef.current.querySelector(`.${classNameToSearch}`); + if (!componentEl) return; + + const component = glob.getComponentByEl(componentEl); + resolve(component); + }); + return ( -
+
{Object.entries(noteTypesToRender.current).map(([ type, Element ]) => { return ; @@ -118,8 +54,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { this.child(typeWidget); } - - this.checkFullHeight(); } /** @@ -231,15 +165,4 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { } } - async executeWithTypeWidgetEvent({ resolve, ntxId }: EventData<"executeWithTypeWidget">) { - if (!this.isNoteContext(ntxId)) { - return; - } - - await this.initialized; - - await this.getWidgetType(); - - resolve(this.getTypeWidget()); - } }