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
No known key found for this signature in database
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 NoteTitleWidget from "../note_title";
import NoteIcon from "../note_icon"; import NoteIcon from "../note_icon";
import NoteContext from "../../components/note_context"; import NoteContext from "../../components/note_context";
import { ParentComponent } from "../react/react_utils"; import { NoteContextContext, ParentComponent } from "../react/react_utils";
import NoteDetail from "../NoteDetail"; import NoteDetail from "../NoteDetail";
const noteContext = new NoteContext("_popup-editor"); const noteContext = new NoteContext("_popup-editor");
export default function PopupEditor() { export default function PopupEditor() {
const [ shown, setShown ] = useState(false); const [ shown, setShown ] = useState(false);
const parentComponent = useContext(ParentComponent);
useTriliumEvent("openInPopup", async ({ noteIdOrPath }) => { useTriliumEvent("openInPopup", async ({ noteIdOrPath }) => {
await noteContext.setNote(noteIdOrPath, { await noteContext.setNote(noteIdOrPath, {
@ -24,22 +23,18 @@ export default function PopupEditor() {
setShown(true); setShown(true);
}); });
// Inject the note context
useEffect(() => {
if (!shown || !parentComponent) return;
parentComponent.handleEventInChildren("activeContextChanged", { noteContext });
}, [ shown ]);
return ( return (
<Modal <NoteContextContext.Provider value={noteContext}>
title={<TitleRow />} <Modal
className="popup-editor-dialog" title={<TitleRow />}
size="lg" className="popup-editor-dialog"
show={shown} size="lg"
onHidden={() => setShown(false)} show={shown}
> onHidden={() => setShown(false)}
<NoteDetail /> >
</Modal> <NoteDetail />
</Modal>
</NoteContextContext.Provider>
) )
} }

View File

@ -2,7 +2,7 @@ import { CSSProperties } from "preact/compat";
import { DragData } from "../note_tree"; import { DragData } from "../note_tree";
import { FilterLabelsByType, KeyboardActionNames, OptionNames, RelationNames } from "@triliumnext/commons"; import { FilterLabelsByType, KeyboardActionNames, OptionNames, RelationNames } from "@triliumnext/commons";
import { MutableRef, useCallback, useContext, useDebugValue, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks"; 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 { RefObject, VNode } from "preact";
import { Tooltip } from "bootstrap"; import { Tooltip } from "bootstrap";
import { ViewMode, ViewScope } from "../../services/link"; import { ViewMode, ViewScope } from "../../services/link";
@ -257,7 +257,8 @@ export function useUniqueName(prefix?: string) {
} }
export function useNoteContext() { export function useNoteContext() {
const [ noteContext, setNoteContext ] = useState<NoteContext>(); const noteContextContext = useContext(NoteContextContext);
const [ noteContext, setNoteContext ] = useState<NoteContext | null>(noteContextContext);
const [ notePath, setNotePath ] = useState<string | null | undefined>(); const [ notePath, setNotePath ] = useState<string | null | undefined>();
const [ note, setNote ] = useState<FNote | null | undefined>(); const [ note, setNote ] = useState<FNote | null | undefined>();
const [ , setViewScope ] = useState<ViewScope>(); const [ , setViewScope ] = useState<ViewScope>();

View File

@ -1,8 +1,11 @@
import { ComponentChild, createContext, render, type JSX, type RefObject } from "preact"; import { ComponentChild, createContext, render, type JSX, type RefObject } from "preact";
import Component from "../../components/component"; import Component from "../../components/component";
import NoteContext from "../../components/note_context";
export const ParentComponent = createContext<Component | null>(null); export const ParentComponent = createContext<Component | null>(null);
export const NoteContextContext = createContext<NoteContext | null>(null);
/** /**
* Takes in a React ref and returns a corresponding JQuery selector. * Takes in a React ref and returns a corresponding JQuery selector.
* *