refactor(react/type_widgets): bring back execute with type widget

This commit is contained in:
Elian Doran
2025-10-05 16:59:46 +03:00
parent 763bcbd394
commit 73213d2a17
2 changed files with 16 additions and 78 deletions

View File

@@ -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<HTMLDivElement>(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<HTMLElement>(`.${classNameToSearch}`);
if (!componentEl) return;
const component = glob.getComponentByEl(componentEl);
resolve(component);
});
return (
<div class={`note-detail ${isFullHeight ? "full-height" : ""}`}>
<div
ref={containerRef}
class={`note-detail ${isFullHeight ? "full-height" : ""}`}
>
{Object.entries(noteTypesToRender.current).map(([ type, Element ]) => {
return <NoteDetailWrapper
Element={Element}