diff --git a/src/components/ErrorDialog/ErrorDialog.js b/src/components/ErrorDialog/ErrorDialog.js index 00289aaeb..af1ca2c57 100644 --- a/src/components/ErrorDialog/ErrorDialog.js +++ b/src/components/ErrorDialog/ErrorDialog.js @@ -29,7 +29,7 @@ const ErrorDialog = ({ useEffect(() => { if (shouldStartSync) startSync() - }, [shouldStartSync]) + }, []) const handleClose = () => { toggleDialog(false) diff --git a/src/state/sync/constants.js b/src/state/sync/constants.js index b9d8e607d..33515574a 100644 --- a/src/state/sync/constants.js +++ b/src/state/sync/constants.js @@ -27,4 +27,5 @@ export default { WS_REQUESTS_REDIRECT: 'ws_emitRedirectingRequestsStatusToApi', SYNC_INTERRUPTED: 'SYNCHRONIZATION_HAS_BEEN_INTERRUPTED', SYNC_NOT_STARTED: 'SYNCHRONIZATION_HAS_NOT_STARTED_YET', + SYNC_FINISHED: 'SYNCHRONIZATION_IS_FINISHED', } diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index b5de8406d..0b2e9a6ab 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -76,9 +76,10 @@ function* startSyncNow() { function* stopSyncNow() { const { result, error } = yield call(syncNowStop) if (result) { + const { result: haveSyncedAtLeastOnce } = yield call(haveCollsBeenSyncedAtLeastOnce) + yield put(actions.setIsSyncRequired(!haveSyncedAtLeastOnce)) yield put(actions.setIsSyncing(false)) yield put(actions.setEstimatedTime({})) - yield put(actions.setIsSyncRequired(true)) yield put(updateStatus({ id: 'sync.logout' })) } if (error) { @@ -201,6 +202,8 @@ function* progressUpdate({ payload }) { if (!isSyncInProgress || state === types.SYNC_INTERRUPTED) { yield put(actions.setIsSyncing(false)) if (error) yield put(updateSyncErrorStatus(error)) + } else if (state === types.SYNC_FINISHED) { + yield put(actions.setIsSyncing(false)) } else { const syncProgress = Number.isInteger(progress) ? progress @@ -215,15 +218,7 @@ function* requestsRedirectUpdate({ payload }) { if (result) { yield put(actions.setSyncMode(types.MODE_ONLINE)) - const syncProgress = yield select(getSyncProgress) - const isSyncing = Number.isInteger(syncProgress) && syncProgress !== 100 - if (isSyncing) { - yield put(actions.setIsSyncing(true)) - } else { - yield put(actions.setIsSyncing(false)) - yield put(actions.setIsSyncRequired(false)) - yield put(updateStatus({ id: 'sync.sync-done' })) - } + yield put(actions.setIsSyncing(false)) } else { yield put(actions.setSyncMode(types.MODE_OFFLINE)) yield put(actions.forceQueryFromDb())