import _ from 'underscore'; import _str from 'underscore.string'; import classNames from 'classnames'; import {AccountStore, NylasSyncStatusStore, React} from 'nylas-exports'; export default class InitialSyncActivity extends React.Component { static displayName = 'InitialSyncActivity'; constructor(props) { super(props); this.state = this.getStateFromStores(); } componentDidMount() { this.unsubscribe = NylasSyncStatusStore.listen(this.onDataChanged); } componentWillUnmount() { if (this.unsubscribe) { this.unsubscribe(); } } onDataChanged = () => { this.setState(this.getStateFromStores()); } getStateFromStores() { return { syncState: NylasSyncStatusStore.state(), }; } /* Iterate through the sync progress of each folder of each account and get a normalized progress value (0: not started, 1: sync complete) for all syncs. */ calculateProgress() { let count = 0; const total = _.values(this.state.syncState).reduce((outerSum, accountSyncState) => { return outerSum + _.values(accountSyncState.folderSyncProgress).reduce((innerSum, progress) => { count++; return innerSum + progress; }, 0) }, 0); return count ? (total / count) : 0; } expandedSyncState() { const accounts = _.map(this.state.syncState, (accountSyncState, accountId) => { const account = _.findWhere(AccountStore.accounts(), {id: accountId}); if (!account) { return false; } const folderStates = _.map(accountSyncState.folderSyncProgress, (progress, name) => { return this.renderFolderProgress(name, progress) }) return (