Skip to content

Commit

Permalink
Merge pull request #735 from alexstotsky/improve-sync-end-checking
Browse files Browse the repository at this point in the history
(improvements) Sync state checking flow
  • Loading branch information
ezewer authored Nov 28, 2023
2 parents e2c25af + afa9457 commit 362f9b8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/ErrorDialog/ErrorDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ErrorDialog = ({

useEffect(() => {
if (shouldStartSync) startSync()
}, [shouldStartSync])
}, [])

const handleClose = () => {
toggleDialog(false)
Expand Down
1 change: 1 addition & 0 deletions src/state/sync/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
15 changes: 5 additions & 10 deletions src/state/sync/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down

0 comments on commit 362f9b8

Please sign in to comment.