fix: improve local backup detection
This commit is contained in:
parent
4a73ea65fd
commit
d4f56da6e7
@ -4,6 +4,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|||||||
import { translate } from 'react-polyglot';
|
import { translate } from 'react-polyglot';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import isEqual from 'lodash/isEqual';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createDraftDuplicateFromEntry,
|
createDraftDuplicateFromEntry,
|
||||||
@ -165,7 +166,12 @@ const Editor: FC<TranslatedProps<EditorProps>> = ({
|
|||||||
>();
|
>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!prevLocalBackup && localBackup) {
|
if (
|
||||||
|
!prevLocalBackup &&
|
||||||
|
localBackup &&
|
||||||
|
(!isEqual(localBackup.entry.data, entryDraft.entry?.data) ||
|
||||||
|
!isEqual(localBackup.entry.meta, entryDraft.entry?.meta))
|
||||||
|
) {
|
||||||
const updateLocalBackup = async () => {
|
const updateLocalBackup = async () => {
|
||||||
const confirmLoadBackupBody = await confirm({
|
const confirmLoadBackupBody = await confirm({
|
||||||
title: 'editor.editor.confirmLoadBackupTitle',
|
title: 'editor.editor.confirmLoadBackupTitle',
|
||||||
@ -184,7 +190,15 @@ const Editor: FC<TranslatedProps<EditorProps>> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPrevLocalBackup(localBackup);
|
setPrevLocalBackup(localBackup);
|
||||||
}, [deleteBackup, dispatch, localBackup, prevLocalBackup, version]);
|
}, [
|
||||||
|
deleteBackup,
|
||||||
|
dispatch,
|
||||||
|
entryDraft.entry?.data,
|
||||||
|
entryDraft.entry?.meta,
|
||||||
|
localBackup,
|
||||||
|
prevLocalBackup,
|
||||||
|
version,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasChanged && entryDraft.entry) {
|
if (hasChanged && entryDraft.entry) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user