diff --git a/src/components/Views/EditView/EditView.tsx b/src/components/Views/EditView/EditView.tsx index 64c5f244..200a57f2 100644 --- a/src/components/Views/EditView/EditView.tsx +++ b/src/components/Views/EditView/EditView.tsx @@ -71,9 +71,10 @@ export const EditView = (props: Props) => { // TODO: проверить сохранение черновика в local storage (не работает) const draft = props.shout || getDraftFromLocalStorage(props.shout.id) if (draft) { - // console.debug('draft: ', draft) + console.debug('draft from localstorage: ', draft) setForm(Object.keys(draft).length !== 0 ? draft : { shoutId: props.shout.id }) } else { + console.debug('draft from props data: ', props.shout) setForm({ slug: props.shout.slug, shoutId: props.shout.id, @@ -110,9 +111,6 @@ export const EditView = (props: Props) => { onCleanup(() => { window.removeEventListener('scroll', handleScroll) }) - }) - - onMount(() => { // eslint-disable-next-line unicorn/consistent-function-scoping const handleBeforeUnload = (event) => { if (!deepEqual(prevForm, form)) { @@ -188,17 +186,12 @@ export const EditView = (props: Props) => { const hasChanges = !deepEqual(form, prevForm) const hasTopic = Boolean(form.mainTopic) if (hasChanges || hasTopic) { - console.debug('saving draft') + console.debug('saving draft', form) setSaving(true) - if (props.shout?.published_at) { - saveDraftToLocalStorage(form) - } else { - await saveDraft(form) - } + saveDraftToLocalStorage(form) + await saveDraft(form) setPrevForm(clone(form)) - setTimeout(() => { - setSaving(false) - }, AUTO_SAVE_DELAY) + setTimeout(() => setSaving(false), AUTO_SAVE_DELAY) } }