fix(quick_edit): note context not injected on first render

This commit is contained in:
Elian Doran
2025-11-22 19:25:27 +02:00
parent 5531c15126
commit bb9cb2fb75
3 changed files with 18 additions and 19 deletions

View File

@@ -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 (
<Modal
title={<TitleRow />}
className="popup-editor-dialog"
size="lg"
show={shown}
onHidden={() => setShown(false)}
>
<NoteDetail />
</Modal>
<NoteContextContext.Provider value={noteContext}>
<Modal
title={<TitleRow />}
className="popup-editor-dialog"
size="lg"
show={shown}
onHidden={() => setShown(false)}
>
<NoteDetail />
</Modal>
</NoteContextContext.Provider>
)
}