_ = require 'underscore' _str = require 'underscore.string' classNames = require 'classnames' React = require 'react' {Actions, AccountStore, NylasSyncStatusStore} = require 'nylas-exports' class InitialSyncActivity extends React.Component @displayName: 'InitialSyncActivity' constructor: (@props) -> @state = @_getStateFromStores() componentDidMount: => @_usub = NylasSyncStatusStore.listen @_onDataChanged componentWillUnmount: => @_usub?() _onDataChanged: => @setState(@_getStateFromStores()) _getStateFromStores: => sync: NylasSyncStatusStore.state() render: => count = 0 fetched = 0 totalProgress = 0 incomplete = 0 for acctId, state of @state.sync for modelName in NylasSyncStatusStore.ModelsForSync modelState = state[modelName] continue unless modelState if not modelState.complete incomplete += 1 if modelState.count count += modelState.count / 1 fetched += modelState.fetched / 1 totalProgress = (fetched / count) * 100 if count > 0 classSet = classNames 'item': true 'expanded-sync': @state.expandedSync if incomplete is 0 return false else
@setState expandedSync: !@state.expandedSync}> {@_renderProgressBar(totalProgress)}
Syncing your mailbox…
{@_expandedSyncState()}
_expandedSyncState: -> accounts = [] for acctId, state of @state.sync account = _.findWhere(AccountStore.accounts(), id: acctId) continue unless account modelStates = _.map state, (modelState, model) => @_renderModelProgress(model, modelState, 100) accounts.push(

{account.emailAddress}

{modelStates}
)
{accounts} Hide
_hideExpandedState: (event) => event.stopPropagation() # So it doesn't reach the parent's onClick event.preventDefault() @setState expandedSync: false return _renderModelProgress: (model, modelState) -> if modelState.error status = "error" else if modelState.complete status = "complete" else status = "busy" percent = (+modelState.fetched / +modelState.count) * 100

{_str.titleize(model)}:

{@_renderProgressBar(percent)}
{_str.numberFormat(modelState.fetched)} / {_str.numberFormat(modelState.count)}
{modelState.error}
_renderProgressBar: (percent) ->
_onTryAgain: => Actions.retrySync() module.exports = InitialSyncActivity