From 033e90f8b7185e8a712087dd371c57c676983564 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 21 Aug 2025 12:13:30 +0300 Subject: [PATCH] fix(react/note_title): not refreshing on protected session --- apps/client/src/widgets/note_title.tsx | 6 +++--- apps/client/src/widgets/react/hooks.tsx | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/client/src/widgets/note_title.tsx b/apps/client/src/widgets/note_title.tsx index 267d8ff27..8c0cfae7d 100644 --- a/apps/client/src/widgets/note_title.tsx +++ b/apps/client/src/widgets/note_title.tsx @@ -12,10 +12,10 @@ export default function NoteTitleWidget() { const title = useNoteProperty(note, "title", componentId); const isProtected = useNoteProperty(note, "isProtected"); const newTitle = useRef(""); - + const [ isReadOnly, setReadOnly ] = useState(false); const [ navigationTitle, setNavigationTitle ] = useState(null); - + useEffect(() => { const isReadOnly = note === null || note === undefined @@ -23,7 +23,7 @@ export default function NoteTitleWidget() { || isLaunchBarConfig(note.noteId) || viewScope?.viewMode !== "default"; setReadOnly(isReadOnly); - }, [ note?.noteId, note?.isProtected, viewScope?.viewMode ]); + }, [ note, note?.noteId, note?.isProtected, viewScope?.viewMode ]); useEffect(() => { if (isReadOnly) { diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 7526bbd61..05821754b 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -9,6 +9,7 @@ import Component from "../../components/component"; import NoteContext from "../../components/note_context"; import { ReactWrappedWidget } from "../basic_widget"; import FNote from "../../entities/fnote"; +import froca from "../../services/froca"; type TriliumEventHandler = (data: EventData) => void; const registeredHandlers: Map[]>> = new Map(); @@ -233,10 +234,15 @@ export function useNoteContext() { const [ noteContext, setNoteContext ] = useState(); const [ notePath, setNotePath ] = useState(); + const [ note, setNote ] = useState(); + + useEffect(() => { + setNote(noteContext?.note); + }, [ notePath ]); useTriliumEventBeta("activeContextChanged", ({ noteContext }) => { setNoteContext(noteContext); - setNotePath(noteContext.notePath); + setNotePath(noteContext.notePath); }); useTriliumEventBeta("setNoteContext", ({ noteContext }) => { console.log("Set note context", noteContext, noteContext.noteId); @@ -250,11 +256,14 @@ export function useNoteContext() { console.warn("Note switched", notePath); setNotePath(notePath); }); + useTriliumEventBeta("frocaReloaded", () => { + setNote(noteContext?.note); + }); const parentComponent = useContext(ParentComponent) as ReactWrappedWidget; return { - note: noteContext?.note, + note: note, noteId: noteContext?.note?.noteId, notePath: noteContext?.notePath, hoistedNoteId: noteContext?.hoistedNoteId, @@ -280,16 +289,17 @@ export function useNoteProperty(note: FNote | null | unde } const [ value, setValue ] = useState(note[property]); + const refreshValue = () => setValue(note[property]); // Watch for note changes. - useEffect(() => setValue(note[property]), [ note[property] ]); + useEffect(() => refreshValue(), [ note, note[property] ]); // Watch for external changes. useTriliumEventBeta("entitiesReloaded", ({ loadResults }) => { if (loadResults.isNoteReloaded(note.noteId, componentId)) { - setValue(note[property]); + refreshValue(); } }); - return value; + return note[property]; } \ No newline at end of file