From 737e5b85b442456eeeb2dee346f5f1dc278d944b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 16 Dec 2025 19:40:24 +0200 Subject: [PATCH] fix(badges): "temporarily editable" remaining after changing editability --- apps/client/src/widgets/layout/NoteBadges.tsx | 5 ++--- apps/client/src/widgets/react/hooks.tsx | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/client/src/widgets/layout/NoteBadges.tsx b/apps/client/src/widgets/layout/NoteBadges.tsx index 9cbbf6fcc..245f23199 100644 --- a/apps/client/src/widgets/layout/NoteBadges.tsx +++ b/apps/client/src/widgets/layout/NoteBadges.tsx @@ -22,11 +22,10 @@ export default function NoteBadges() { function ReadOnlyBadge() { const { note, noteContext } = useNoteContext(); - const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext); + const { isReadOnly, enableEditing, temporarilyEditable } = useIsNoteReadOnly(note, noteContext); const isExplicitReadOnly = note?.isLabelTruthy("readOnly"); - const isTemporarilyEditable = noteContext?.ntxId !== "_popup-editor" && noteContext?.viewScope?.readOnlyTemporarilyDisabled; - if (isTemporarilyEditable) { + if (temporarilyEditable) { return (undefined); const [ readOnlyAttr ] = useNoteLabelBoolean(note, "readOnly"); const [ autoReadOnlyDisabledAttr ] = useNoteLabelBoolean(note, "autoReadOnlyDisabled"); + const [ temporarilyEditable, setTemporarilyEditable ] = useState(false); const enableEditing = useCallback((enabled = true) => { if (noteContext?.viewScope) { noteContext.viewScope.readOnlyTemporarilyDisabled = enabled; appContext.triggerEvent("readOnlyTemporarilyDisabled", {noteContext}); + setTemporarilyEditable(enabled); } }, [noteContext]); @@ -945,6 +947,7 @@ export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: N if (note && noteContext) { isNoteReadOnly(note, noteContext).then((readOnly) => { setIsReadOnly(readOnly); + setTemporarilyEditable(false); }); } }, [ note, noteContext, noteContext?.viewScope, readOnlyAttr, autoReadOnlyDisabledAttr ]); @@ -952,10 +955,11 @@ export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: N useTriliumEvent("readOnlyTemporarilyDisabled", ({noteContext: eventNoteContext}) => { if (noteContext?.ntxId === eventNoteContext.ntxId) { setIsReadOnly(!noteContext.viewScope?.readOnlyTemporarilyDisabled); + setTemporarilyEditable(true); } }); - return { isReadOnly, enableEditing }; + return { isReadOnly, enableEditing, temporarilyEditable }; } async function isNoteReadOnly(note: FNote, noteContext: NoteContext) {