Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(quick_edit): note context not injected on first render
Elian Doranbb9cb2fb75e3
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsxindex d28e7d6d80..b19851bb9b 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 (- <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>)}diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex 856896f2cb..63fa4fff1f 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<NoteContext>();+ const noteContextContext = useContext(NoteContextContext);+ const [ noteContext, setNoteContext ] = useState<NoteContext | null>(noteContextContext);const [ notePath, setNotePath ] = useState<string | null | undefined>();const [ note, setNote ] = useState<FNote | null | undefined>();const [ , setViewScope ] = useState<ViewScope>();diff --git a/apps/client/src/widgets/react/react_utils.tsx b/apps/client/src/widgets/react/react_utils.tsxindex d752662f55..468a0e73ef 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<Component | null>(null);+export const NoteContextContext = createContext<NoteContext | null>(null);+/*** Takes in a React ref and returns a corresponding JQuery selector.*