Skip to content

Build your personal knowledge base with Trilium Notes

chore(quick_edit): inject note context

Elian Doran29f049c4118d
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsx
index 7969e3ac02..6b305fbb21 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 (
<Modal
title={(
diff --git a/apps/client/src/widgets/dialogs/popup_editor.ts b/apps/client/src/widgets/dialogs/popup_editor.ts
index bc862822e3..9899ad163a 100644
--- a/apps/client/src/widgets/dialogs/popup_editor.ts
+++ b/apps/client/src/widgets/dialogs/popup_editor.ts
@@ -13,7 +13,7 @@ export default class PopupEditorDialog extends Container<BasicWidget> {
constructor() {
super();
- this.noteContext = new NoteContext("_popup-editor");
+ this.noteContext =
}
doRender() {
@@ -34,11 +34,7 @@ export default class PopupEditorDialog extends Container<BasicWidget> {
}
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<BasicWidget> {
}
$dialog.on("shown.bs.modal", async () => {
- await this.handleEventInChildren("activeContextChanged", { noteContext: this.noteContext });
this.setVisibility(true);
await this.handleEventInChildren("focusOnDetail", { ntxId: this.noteContext.ntxId });
});