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()); - } }