diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsx index 7969e3ac0..6b305fbb2 100644 --- a/apps/client/src/widgets/dialogs/PopupEditor.tsx +++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx @@ -1,17 +1,34 @@ -import { useState } from "preact/hooks"; +import { useContext, useEffect, useState } from "preact/hooks"; import Modal from "../react/Modal"; import "./PopupEditor.css"; import { useTriliumEvent } from "../react/hooks"; import NoteTitleWidget from "../note_title"; import NoteIcon from "../note_icon"; +import NoteContext from "../../components/note_context"; +import { ParentComponent } from "../react/react_utils"; + +const noteContext = new NoteContext("_popup-editor"); export default function PopupEditor() { const [ shown, setShown ] = useState(false); + const parentComponent = useContext(ParentComponent); + + useTriliumEvent("openInPopup", async ({ noteIdOrPath }) => { + await noteContext.setNote(noteIdOrPath, { + viewScope: { + readOnlyTemporarilyDisabled: true + } + }); - useTriliumEvent("openInPopup", () => { setShown(true); }); + // Inject the note context + useEffect(() => { + if (!shown || !parentComponent) return; + parentComponent.handleEventInChildren("activeContextChanged", { noteContext }); + }, [ shown ]); + return ( { constructor() { super(); - this.noteContext = new NoteContext("_popup-editor"); + this.noteContext = } doRender() { @@ -34,11 +34,7 @@ export default class PopupEditorDialog extends Container { } async openInPopupEvent({ noteIdOrPath }: EventData<"openInPopup">) { - await this.noteContext.setNote(noteIdOrPath, { - viewScope: { - readOnlyTemporarilyDisabled: true - } - }); + const colorClass = this.noteContext.note?.getColorClass(); const wrapperElement = this.$wrapper.get(0)!; @@ -61,7 +57,6 @@ export default class PopupEditorDialog extends Container { } $dialog.on("shown.bs.modal", async () => { - await this.handleEventInChildren("activeContextChanged", { noteContext: this.noteContext }); this.setVisibility(true); await this.handleEventInChildren("focusOnDetail", { ntxId: this.noteContext.ntxId }); });