diff --git a/internal_packages/notifications/lib/sidebar/initial-sync-activity.jsx b/internal_packages/notifications/lib/sidebar/initial-sync-activity.jsx index dfe560ebc..6144a1b53 100644 --- a/internal_packages/notifications/lib/sidebar/initial-sync-activity.jsx +++ b/internal_packages/notifications/lib/sidebar/initial-sync-activity.jsx @@ -12,7 +12,6 @@ export default class InitialSyncActivity extends React.Component { super(props); this.state = { syncState: NylasSyncStatusStore.getSyncState(), - syncProgress: NylasSyncStatusStore.getSyncProgress(), } this.mounted = false; } @@ -33,9 +32,8 @@ export default class InitialSyncActivity extends React.Component { } onDataChanged = () => { - const syncState = NylasSyncStatusStore.getSyncState() - const syncProgress = NylasSyncStatusStore.getSyncProgress() - this.setState({syncState, syncProgress}); + const syncState = Utils.deepClone(NylasSyncStatusStore.getSyncState()) + this.setState({syncState}); } renderFolderProgress(name, progress, oldestProcessedDate) { @@ -70,7 +68,7 @@ export default class InitialSyncActivity extends React.Component { } render() { - if (!AccountStore.accountsAreSyncing() || this.state.syncProgress.progress === 1) { + if (!AccountStore.accountsAreSyncing() || NylasSyncStatusStore.isSyncComplete()) { return false; } diff --git a/src/flux/stores/nylas-sync-status-store.es6 b/src/flux/stores/nylas-sync-status-store.es6 index 09dde67d4..84f8f5e78 100644 --- a/src/flux/stores/nylas-sync-status-store.es6 +++ b/src/flux/stores/nylas-sync-status-store.es6 @@ -99,7 +99,7 @@ class NylasSyncStatusStore extends NylasStore { if (uidnext) { // TODO: when we unify the databases, we shouldn't need code to // calculate this in two different places anymore - const progress = (+minUID + (+fetchedmax - +fetchedmin) + 1) / uidnext + const progress = (+fetchedmax - +fetchedmin + 1) / (uidnext - minUID + 1) updates[name] = { progress, total: uidnext, @@ -130,52 +130,6 @@ class NylasSyncStatusStore extends NylasStore { return this._statesByAccount } - /** - * Returns the weighted sync progress as a percentage, and - * the total number of messages to sync for a given account - */ - getSyncProgressForAccount(accountId) { - const state = this._statesByAccount[accountId] - if (!state) { return null } - const {folderSyncProgress} = this._statesByAccount[accountId] - if (!folderSyncProgress) { return null } - const folderNames = Object.keys(folderSyncProgress) - const progressPerFolder = folderNames.map(fname => folderSyncProgress[fname]) - const weightedProgress = progressPerFolder.reduce( - (accum, {progress, total}) => accum + progress * total, 0 - ) - const totalMessageCount = progressPerFolder.reduce( - (accum, {total}) => accum + total, 0 - ) - return { - progress: weightedProgress / totalMessageCount, - total: totalMessageCount, - } - } - - /** - * Returns the weighted sync progress for all accounts as a percentage, and - * the total number of messages to sync - */ - getSyncProgress() { - const accountIds = AccountStore.accountIds() - const progressPerAccount = ( - accountIds - .map(accId => this.getSyncProgressForAccount(accId)) - .filter(p => p != null) - ) - const weightedProgress = progressPerAccount.reduce( - (accum, {progress, total}) => accum + progress * total, 0 - ) - const totalMessageCount = progressPerAccount.reduce( - (accum, {total}) => accum + total, 0 - ) - return { - progress: totalMessageCount ? weightedProgress / totalMessageCount : 0, - total: totalMessageCount, - } - } - /** * Returns true if N1's local cache contains the entire list of available * folders and labels.