Warn whenever rich text editor has unsaved changes

This commit is contained in:
Austin Chen 2022-10-05 09:16:05 -04:00
parent 8aaca848b2
commit 419219c703

View File

@ -42,6 +42,7 @@ import ItalicIcon from 'web/lib/icons/italic-icon'
import LinkIcon from 'web/lib/icons/link-icon' import LinkIcon from 'web/lib/icons/link-icon'
import { getUrl } from 'common/util/parse' import { getUrl } from 'common/util/parse'
import { TiptapSpoiler } from 'common/util/tiptap-spoiler' import { TiptapSpoiler } from 'common/util/tiptap-spoiler'
import { useWarnUnsavedChanges } from 'web/hooks/use-warn-unsaved-changes'
const DisplayImage = Image.configure({ const DisplayImage = Image.configure({
HTMLAttributes: { HTMLAttributes: {
@ -150,6 +151,9 @@ export function useTextEditor(props: {
editor?.setEditable(!disabled) editor?.setEditable(!disabled)
}, [editor, disabled]) }, [editor, disabled])
const isEditorFilled = editor != null && !editor.isEmpty
useWarnUnsavedChanges(isEditorFilled)
return { editor, upload } return { editor, upload }
} }