From 78253f512c99d4def10ceeb05c2ffdef32d8af1c Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Wed, 4 Mar 2026 15:35:23 -0300 Subject: [PATCH] chore: fix Super read only state --- .../Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx | 10 +++--- .../Components/SuperEditor/SuperEditor.tsx | 33 ++++++++++++++++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx index b99660f2504..dd036b3cf41 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx @@ -3,26 +3,26 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext import { SNNote, ContentType } from '@standardnotes/snjs' import { useState, useEffect } from 'react' -const ReadonlyPlugin = ({ note }: { note: SNNote }) => { +const ReadonlyPlugin = ({ note, forceReadonly = false }: { note: SNNote; forceReadonly?: boolean }) => { const application = useApplication() const [editor] = useLexicalComposerContext() - const [readOnly, setReadOnly] = useState(note.locked) + const [noteLocked, setNoteLocked] = useState(note.locked) useEffect(() => { return application.items.streamItems(ContentType.TYPES.Note, ({ changed }) => { const changedNoteItem = changed.find((changedItem) => changedItem.uuid === note.uuid) if (changedNoteItem) { - setReadOnly(changedNoteItem.locked) + setNoteLocked(changedNoteItem.locked) } }) }, [application, note.uuid]) useEffect(() => { editor.update(() => { - editor.setEditable(!readOnly) + editor.setEditable(!(noteLocked || forceReadonly)) }) - }, [editor, readOnly]) + }, [editor, noteLocked, forceReadonly]) return null } diff --git a/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx b/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx index ac02992ce0c..a06181b3c5b 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/SuperEditor.tsx @@ -1,5 +1,6 @@ import { WebApplication } from '@/Application/WebApplication' import { + ApplicationEvent, isPayloadSourceRetrieved, NativeFeatureIdentifier, FeatureStatus, @@ -71,7 +72,7 @@ export const SuperEditor: FunctionComponent = ({ const getMarkdownPlugin = useRef(null) const [featureStatus, setFeatureStatus] = useState(FeatureStatus.Entitled) - useEffect(() => { + const reloadFeatureStatus = useCallback(() => { setFeatureStatus( application.features.getFeatureStatus( NativeFeatureIdentifier.create(NativeFeatureIdentifier.TYPES.SuperEditor).getValue(), @@ -82,7 +83,24 @@ export const SuperEditor: FunctionComponent = ({ ) }, [application.features]) + useEffect(() => { + reloadFeatureStatus() + }, [reloadFeatureStatus]) + + useEffect(() => { + return application.addEventObserver(async (event) => { + switch (event) { + case ApplicationEvent.FeaturesAvailabilityChanged: + case ApplicationEvent.UserRolesChanged: + case ApplicationEvent.LocalDataLoaded: + reloadFeatureStatus() + break + } + }) + }, [application, reloadFeatureStatus]) + const keyboardService = application.keyboardService + const isEditorReadonly = note.current.locked || Boolean(readonly) || featureStatus !== FeatureStatus.Entitled useEffect(() => { return application.commands.addWithShortcut( @@ -155,6 +173,9 @@ export const SuperEditor: FunctionComponent = ({ ignoreNextChange.current = false return } + if (isEditorReadonly) { + return + } void controller.saveAndAwaitLocalPropagation({ text: value, @@ -165,7 +186,7 @@ export const SuperEditor: FunctionComponent = ({ }, }) }, - [controller], + [controller, isEditorReadonly], ) const handleBubbleRemove = useCallback( @@ -252,13 +273,13 @@ export const SuperEditor: FunctionComponent = ({ - + @@ -271,7 +292,9 @@ export const SuperEditor: FunctionComponent = ({ /> - {readonly === undefined && } + {readonly === undefined && ( + + )}