mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	chore(react): use different injection mechanism
This commit is contained in:
		| @@ -417,17 +417,27 @@ export function useNoteBlob(note: FNote | null | undefined): [ FBlob | null | un | |||||||
| export function useLegacyWidget(widgetFactory: () => BasicWidget, { noteContext }: { | export function useLegacyWidget(widgetFactory: () => BasicWidget, { noteContext }: { | ||||||
|     noteContext?: NoteContext; |     noteContext?: NoteContext; | ||||||
| } = {}) { | } = {}) { | ||||||
|  |     const ref = useRef<HTMLDivElement>(null); | ||||||
|     const widget = useMemo(widgetFactory, []); |     const widget = useMemo(widgetFactory, []); | ||||||
|     const parentComponent = useContext(ParentComponent); |     const parentComponent = useContext(ParentComponent); | ||||||
|  |  | ||||||
|  |     useEffect(() => { | ||||||
|  |         if (!ref.current) return; | ||||||
|  |  | ||||||
|  |         const $container = $(ref.current); | ||||||
|  |         $container.empty(); | ||||||
|  |         widget.render().appendTo($container); | ||||||
|  |  | ||||||
|  |         if (noteContext && widget instanceof NoteContextAwareWidget) { | ||||||
|  |             console.log("Injecting note context", noteContext); | ||||||
|  |             widget.setNoteContextEvent({ noteContext }); | ||||||
|  |             widget.activeContextChangedEvent({ noteContext }); | ||||||
|  |         } | ||||||
|  |     }, [ widget ]); | ||||||
|  |  | ||||||
|     if (parentComponent) { |     if (parentComponent) { | ||||||
|         parentComponent.child(widget); |         parentComponent.child(widget); | ||||||
|     } |     }     | ||||||
|  |  | ||||||
|     if (noteContext && widget instanceof NoteContextAwareWidget) { |     return <div ref={ref} /> | ||||||
|         console.log("Inject!"); |  | ||||||
|         widget.setNoteContextEvent({ noteContext }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return <RawHtml html={widget.render()} /> |  | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user