mirror of
https://github.com/zadam/trilium.git
synced 2025-12-21 07:39:55 +01:00
fix(quick_edit): note context not injected on first render
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user