fix: issue where converting empty plain note to super would result in error
This commit is contained in:
@@ -5,7 +5,7 @@ import {BlockEditorNodes} from '../Lexical/Nodes/AllNodes';
|
|||||||
import {Klass, LexicalNode} from 'lexical';
|
import {Klass, LexicalNode} from 'lexical';
|
||||||
|
|
||||||
type BlocksEditorComposerProps = {
|
type BlocksEditorComposerProps = {
|
||||||
initialValue: string;
|
initialValue: string | undefined;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
nodes?: Array<Klass<LexicalNode>>;
|
nodes?: Array<Klass<LexicalNode>>;
|
||||||
readonly?: boolean;
|
readonly?: boolean;
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ export default function ImportPlugin({ text, format }: { text: string; format: '
|
|||||||
const [editor] = useLexicalComposerContext()
|
const [editor] = useLexicalComposerContext()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const dontAllowConversionOfEmptyStringWhichWouldResultInError = text.length === 0
|
||||||
|
if (dontAllowConversionOfEmptyStringWhichWouldResultInError) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
if (format === 'md') {
|
if (format === 'md') {
|
||||||
$convertFromMarkdownString(text, [...TRANSFORMERS])
|
$convertFromMarkdownString(text, [...TRANSFORMERS])
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application, closeDialog, onConvertComplete }) => {
|
export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application, closeDialog, onConvertComplete }) => {
|
||||||
|
const isSeamlessConvert = note.text.length === 0
|
||||||
const [lastValue, setLastValue] = useState({ text: '', previewPlain: '' })
|
const [lastValue, setLastValue] = useState({ text: '', previewPlain: '' })
|
||||||
|
|
||||||
const format =
|
const format =
|
||||||
@@ -51,16 +52,18 @@ export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application,
|
|||||||
)
|
)
|
||||||
|
|
||||||
const confirmConvert = useCallback(async () => {
|
const confirmConvert = useCallback(async () => {
|
||||||
await performConvert(lastValue.text, lastValue.previewPlain)
|
|
||||||
closeDialog()
|
closeDialog()
|
||||||
|
|
||||||
|
await performConvert(lastValue.text, lastValue.previewPlain)
|
||||||
|
|
||||||
onConvertComplete()
|
onConvertComplete()
|
||||||
}, [closeDialog, performConvert, onConvertComplete, lastValue])
|
}, [closeDialog, performConvert, onConvertComplete, lastValue])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (note.text.length === 0) {
|
if (isSeamlessConvert) {
|
||||||
void confirmConvert()
|
void confirmConvert()
|
||||||
}
|
}
|
||||||
}, [note, confirmConvert])
|
}, [isSeamlessConvert, confirmConvert])
|
||||||
|
|
||||||
const convertAsIs = useCallback(async () => {
|
const convertAsIs = useCallback(async () => {
|
||||||
const confirmed = await application.alertService.confirm(
|
const confirmed = await application.alertService.confirm(
|
||||||
@@ -75,12 +78,17 @@ export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeDialog()
|
||||||
|
|
||||||
await performConvert(note.text, note.preview_plain)
|
await performConvert(note.text, note.preview_plain)
|
||||||
|
|
||||||
closeDialog()
|
|
||||||
onConvertComplete()
|
onConvertComplete()
|
||||||
}, [closeDialog, application, note, onConvertComplete, performConvert])
|
}, [closeDialog, application, note, onConvertComplete, performConvert])
|
||||||
|
|
||||||
|
if (isSeamlessConvert) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalDialog>
|
<ModalDialog>
|
||||||
<ModalDialogLabel closeDialog={closeDialog}>
|
<ModalDialogLabel closeDialog={closeDialog}>
|
||||||
@@ -93,7 +101,7 @@ export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application,
|
|||||||
<ModalDialogDescription>
|
<ModalDialogDescription>
|
||||||
<div className="relative w-full">
|
<div className="relative w-full">
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<BlocksEditorComposer readonly initialValue={''}>
|
<BlocksEditorComposer readonly initialValue={undefined}>
|
||||||
<BlocksEditor
|
<BlocksEditor
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
ignoreFirstChange={false}
|
ignoreFirstChange={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user