draft-save-debug
This commit is contained in:
parent
7dc2efca66
commit
439be16fa1
|
@ -71,9 +71,10 @@ export const EditView = (props: Props) => {
|
||||||
// TODO: проверить сохранение черновика в local storage (не работает)
|
// TODO: проверить сохранение черновика в local storage (не работает)
|
||||||
const draft = props.shout || getDraftFromLocalStorage(props.shout.id)
|
const draft = props.shout || getDraftFromLocalStorage(props.shout.id)
|
||||||
if (draft) {
|
if (draft) {
|
||||||
// console.debug('draft: ', draft)
|
console.debug('draft from localstorage: ', draft)
|
||||||
setForm(Object.keys(draft).length !== 0 ? draft : { shoutId: props.shout.id })
|
setForm(Object.keys(draft).length !== 0 ? draft : { shoutId: props.shout.id })
|
||||||
} else {
|
} else {
|
||||||
|
console.debug('draft from props data: ', props.shout)
|
||||||
setForm({
|
setForm({
|
||||||
slug: props.shout.slug,
|
slug: props.shout.slug,
|
||||||
shoutId: props.shout.id,
|
shoutId: props.shout.id,
|
||||||
|
@ -110,9 +111,6 @@ export const EditView = (props: Props) => {
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
window.removeEventListener('scroll', handleScroll)
|
window.removeEventListener('scroll', handleScroll)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
// eslint-disable-next-line unicorn/consistent-function-scoping
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
||||||
const handleBeforeUnload = (event) => {
|
const handleBeforeUnload = (event) => {
|
||||||
if (!deepEqual(prevForm, form)) {
|
if (!deepEqual(prevForm, form)) {
|
||||||
|
@ -188,17 +186,12 @@ export const EditView = (props: Props) => {
|
||||||
const hasChanges = !deepEqual(form, prevForm)
|
const hasChanges = !deepEqual(form, prevForm)
|
||||||
const hasTopic = Boolean(form.mainTopic)
|
const hasTopic = Boolean(form.mainTopic)
|
||||||
if (hasChanges || hasTopic) {
|
if (hasChanges || hasTopic) {
|
||||||
console.debug('saving draft')
|
console.debug('saving draft', form)
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
if (props.shout?.published_at) {
|
|
||||||
saveDraftToLocalStorage(form)
|
saveDraftToLocalStorage(form)
|
||||||
} else {
|
|
||||||
await saveDraft(form)
|
await saveDraft(form)
|
||||||
}
|
|
||||||
setPrevForm(clone(form))
|
setPrevForm(clone(form))
|
||||||
setTimeout(() => {
|
setTimeout(() => setSaving(false), AUTO_SAVE_DELAY)
|
||||||
setSaving(false)
|
|
||||||
}, AUTO_SAVE_DELAY)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user