import _ from 'underscore'; import {AccountStore, FolderSyncProgressStore, React} from 'nylas-exports'; export default class InitialSyncActivity extends React.Component { static displayName = 'InitialSyncActivity'; constructor(props) { super(props); this.state = { syncState: FolderSyncProgressStore.getSyncState(), } this.mounted = false; } componentDidMount() { this.mounted = true; this.unsub = FolderSyncProgressStore.listen(this.onDataChanged) } componentWillUnmount() { this.unsub(); this.mounted = false; } onDataChanged = () => { this.setState({syncState: FolderSyncProgressStore.getSyncState()}); } renderFolderProgress(folderPath, progress) { let status = 'busy'; let progressLabel = `In Progress (${Math.round(progress * 100)}%)`; if (progress === 1) { status = 'complete'; progressLabel = ''; } return (
{folderPath} {progressLabel}
) } render() { if (FolderSyncProgressStore.isSyncComplete()) { return false; } let maxHeight = 0; let accounts = _.map(this.state.syncState, (accountSyncState, accountId) => { const account = AccountStore.accountForId(accountId); if (!account) { return false; } let folderStates = _.map(accountSyncState, ({progress}, folderPath) => { return this.renderFolderProgress(folderPath, progress) }) if (folderStates.length === 0) { folderStates =

Gathering folders...
} // A row for the account email address plus a row for each folder state, const numRows = 1 + (folderStates.length || 1) maxHeight += 50 * numRows; return (

{account.emailAddress}

{folderStates}
) }); if (accounts.length === 0) { accounts =

Looking for accounts...
} return (
{accounts}
) } }