lexical: fix modal close confirmation

environments/review-lexical-ujdd17/deployments/4019
Alex Gleason 2023-09-23 15:33:43 -05:00
rodzic 4f65c96da4
commit 46b63571e7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -1,5 +1,5 @@
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { KEY_ENTER_COMMAND } from 'lexical';
import { $getRoot, KEY_ENTER_COMMAND } from 'lexical';
import { useEffect } from 'react';
import { setEditorState } from 'soapbox/actions/compose';
@ -23,7 +23,9 @@ const StatePlugin = ({ composeId, handleSubmit }: IStatePlugin) => {
return false;
}, 1);
editor.registerUpdateListener(({ editorState }) => {
dispatch(setEditorState(composeId, editorState.isEmpty() ? null : JSON.stringify(editorState.toJSON())));
const isEmpty = editorState.read(() => $getRoot().getTextContent()) === '';
const data = isEmpty ? null : JSON.stringify(editorState.toJSON());
dispatch(setEditorState(composeId, data));
});
}, [editor]);