diff --git a/components/editor.tsx b/components/editor.tsx
index a683e75..2724b1d 100644
--- a/components/editor.tsx
+++ b/components/editor.tsx
@@ -24,13 +24,13 @@ interface EditorProps {
type FormData = z.infer
export function Editor({ post }: EditorProps) {
- const { register, handleSubmit } = useForm({
+ const { register, handleSubmit, formState: {errors, isSubmitting, isDirty} } = useForm({
resolver: zodResolver(postPatchSchema),
})
const ref = React.useRef()
const router = useRouter()
- const [isSaving, setIsSaving] = React.useState(false)
const [isMounted, setIsMounted] = React.useState(false)
+ const [editorContentChanged, setEditorContentChanged] = React.useState(false);
const initializeEditor = React.useCallback(async () => {
const EditorJS = (await import("@editorjs/editorjs")).default
@@ -50,6 +50,9 @@ export function Editor({ post }: EditorProps) {
onReady() {
ref.current = editor
},
+ onChange: () => {
+ setEditorContentChanged(true);
+ },
placeholder: "Type here to write your post...",
inlineToolbar: true,
data: body.content,
@@ -84,7 +87,6 @@ export function Editor({ post }: EditorProps) {
}, [isMounted, initializeEditor])
async function onSubmit(data: FormData) {
- setIsSaving(true)
const blocks = await ref.current?.save()
@@ -99,8 +101,6 @@ export function Editor({ post }: EditorProps) {
}),
})
- setIsSaving(false)
-
if (!response?.ok) {
return toast({
title: "Something went wrong.",
@@ -138,8 +138,8 @@ export function Editor({ post }: EditorProps) {
{post.published ? "Published" : "Draft"}
-