fix: "Prevent editing" option not working correctly for Super notes

This commit is contained in:
Aman Harwara
2022-11-30 18:22:41 +05:30
parent abe2b17cb4
commit f30d0898ec
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { useApplication } from '@/Components/ApplicationView/ApplicationProvider'
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import { SNNote, ContentType } from '@standardnotes/snjs'
import { useState, useEffect } from 'react'
const ReadonlyPlugin = ({ note }: { note: SNNote }) => {
const application = useApplication()
const [editor] = useLexicalComposerContext()
const [readOnly, setReadOnly] = useState(note.locked)
useEffect(() => {
return application.streamItems<SNNote>(ContentType.Note, ({ changed }) => {
const changedNoteItem = changed.find((changedItem) => changedItem.uuid === note.uuid)
if (changedNoteItem) {
setReadOnly(changedNoteItem.locked)
}
})
}, [application, note.uuid])
useEffect(() => {
editor.update(() => {
editor.setEditable(!readOnly)
})
}, [editor, readOnly])
return null
}
export default ReadonlyPlugin

View File

@@ -37,6 +37,7 @@ import { ExportPlugin } from './Plugins/ExportPlugin/ExportPlugin'
import GetMarkdownPlugin, { GetMarkdownPluginInterface } from './Plugins/GetMarkdownPlugin/GetMarkdownPlugin'
import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin'
import { getPlaintextFontSize } from '@/Utils/getPlaintextFontSize'
import ReadonlyPlugin from './Plugins/ReadonlyPlugin/ReadonlyPlugin'
const NotePreviewCharLimit = 160
@@ -190,6 +191,7 @@ export const SuperEditor: FunctionComponent<Props> = ({
<NodeObserverPlugin nodeType={BubbleNode} onRemove={handleBubbleRemove} />
<NodeObserverPlugin nodeType={FileNode} onRemove={handleBubbleRemove} />
<ExportPlugin />
<ReadonlyPlugin note={note.current} />
{controller.isTemplateNote ? <AutoFocusPlugin /> : null}
</BlocksEditor>
</BlocksEditorComposer>