diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsx
index d28e7d6d8..b19851bb9 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx
+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx
@@ -5,14 +5,13 @@ 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";
+import { NoteContextContext, ParentComponent } from "../react/react_utils";
import NoteDetail from "../NoteDetail";
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, {
@@ -24,22 +23,18 @@ export default function PopupEditor() {
setShown(true);
});
- // Inject the note context
- useEffect(() => {
- if (!shown || !parentComponent) return;
- parentComponent.handleEventInChildren("activeContextChanged", { noteContext });
- }, [ shown ]);
-
return (
- }
- className="popup-editor-dialog"
- size="lg"
- show={shown}
- onHidden={() => setShown(false)}
- >
-
-
+
+ }
+ className="popup-editor-dialog"
+ size="lg"
+ show={shown}
+ onHidden={() => setShown(false)}
+ >
+
+
+
)
}
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index 856896f2c..63fa4fff1 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -2,7 +2,7 @@ import { CSSProperties } from "preact/compat";
import { DragData } from "../note_tree";
import { FilterLabelsByType, KeyboardActionNames, OptionNames, RelationNames } from "@triliumnext/commons";
import { MutableRef, useCallback, useContext, useDebugValue, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
-import { ParentComponent, refToJQuerySelector } from "./react_utils";
+import { NoteContextContext, ParentComponent, refToJQuerySelector } from "./react_utils";
import { RefObject, VNode } from "preact";
import { Tooltip } from "bootstrap";
import { ViewMode, ViewScope } from "../../services/link";
@@ -257,7 +257,8 @@ export function useUniqueName(prefix?: string) {
}
export function useNoteContext() {
- const [ noteContext, setNoteContext ] = useState();
+ const noteContextContext = useContext(NoteContextContext);
+ const [ noteContext, setNoteContext ] = useState(noteContextContext);
const [ notePath, setNotePath ] = useState();
const [ note, setNote ] = useState();
const [ , setViewScope ] = useState();
diff --git a/apps/client/src/widgets/react/react_utils.tsx b/apps/client/src/widgets/react/react_utils.tsx
index d752662f5..468a0e73e 100644
--- a/apps/client/src/widgets/react/react_utils.tsx
+++ b/apps/client/src/widgets/react/react_utils.tsx
@@ -1,8 +1,11 @@
import { ComponentChild, createContext, render, type JSX, type RefObject } from "preact";
import Component from "../../components/component";
+import NoteContext from "../../components/note_context";
export const ParentComponent = createContext(null);
+export const NoteContextContext = createContext(null);
+
/**
* Takes in a React ref and returns a corresponding JQuery selector.
*