Improve draft saving process in EditView
This commit is contained in:
parent
bf9f0d9c7b
commit
2280a776b3
|
@ -64,10 +64,11 @@ export const EditView = (props: Props) => {
|
||||||
getDraftFromLocalStorage,
|
getDraftFromLocalStorage,
|
||||||
} = useEditorContext()
|
} = useEditorContext()
|
||||||
const shoutTopics = props.shout.topics || []
|
const shoutTopics = props.shout.topics || []
|
||||||
const draft = getDraftFromLocalStorage(props.shout.id)
|
|
||||||
|
|
||||||
|
// TODO: проверить сохранение черновика в local storage (не работает)
|
||||||
|
const draft = getDraftFromLocalStorage(props.shout.id)
|
||||||
if (draft) {
|
if (draft) {
|
||||||
setForm(draft)
|
setForm(Object.keys(draft).length !== 0 ? draft : { shoutId: props.shout.id });
|
||||||
} else {
|
} else {
|
||||||
setForm({
|
setForm({
|
||||||
slug: props.shout.slug,
|
slug: props.shout.slug,
|
||||||
|
@ -179,6 +180,7 @@ export const EditView = (props: Props) => {
|
||||||
|
|
||||||
let autoSaveTimeOutId: number | string | NodeJS.Timeout
|
let autoSaveTimeOutId: number | string | NodeJS.Timeout
|
||||||
|
|
||||||
|
//TODO: add throttle
|
||||||
const autoSaveRecursive = () => {
|
const autoSaveRecursive = () => {
|
||||||
autoSaveTimeOutId = setTimeout(async () => {
|
autoSaveTimeOutId = setTimeout(async () => {
|
||||||
const hasChanges = !deepEqual(form, prevForm)
|
const hasChanges = !deepEqual(form, prevForm)
|
||||||
|
|
|
@ -184,8 +184,10 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveDraft = async (draftForm: ShoutForm) => {
|
const saveDraft = async (draftForm: ShoutForm) => {
|
||||||
|
console.log("!!! draftForm:", draftForm);
|
||||||
const { error } = await updateShout(draftForm, { publish: false })
|
const { error } = await updateShout(draftForm, { publish: false })
|
||||||
if (error) {
|
if (error) {
|
||||||
|
console.log("!!! error:", error);
|
||||||
snackbar?.showSnackbar({ type: 'error', body: localize?.t(error) || '' })
|
snackbar?.showSnackbar({ type: 'error', body: localize?.t(error) || '' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user