import { AccountStore, FolderSyncProgressStore, React } from 'mailspring-exports'; import utf7 from 'utf7'; 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, busy }) { let status = 'complete'; let progressLabel = ''; if (busy) { status = 'busy'; if (progress < 1) { progressLabel = `Scanning (${Math.round(progress * 100)}%)`; } else { progressLabel = `Building index…`; } } const folderDisplayPath = utf7.imap.decode(folderPath); return (
{folderDisplayPath} {progressLabel}
); } render() { if (FolderSyncProgressStore.isSyncComplete()) { return false; } let maxHeight = 0; let accounts = Object.entries(this.state.syncState).map(([accountId, accountSyncState]) => { const account = AccountStore.accountForId(accountId); if (!account) { return false; } let folderStates = Object.entries(accountSyncState).map(([folderPath, folderState]) => { return this.renderFolderProgress(folderPath, folderState); }); 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}
); } }