mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-23 08:46:07 +08:00
81d2edcaf9
Summary: This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`. This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work. When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account. Search bar doesn't need to do full refresh on clear if it never committed Allow drafts to be switched to a different account when not in reply to an existing thread Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal Show many dots for many accounts in long polling status bar add/remove accounts from prefs Spec fixes! Test Plan: Run tests, none broken! Reviewers: evan, dillon Reviewed By: evan, dillon Differential Revision: https://phab.nylas.com/D1928
126 lines
3.4 KiB
CoffeeScript
126 lines
3.4 KiB
CoffeeScript
React = require 'react'
|
|
_ = require 'underscore'
|
|
classNames = require 'classnames'
|
|
NotificationStore = require './notifications-store'
|
|
{Actions,
|
|
TaskQueue,
|
|
AccountStore,
|
|
NylasAPI} = require 'nylas-exports'
|
|
{TimeoutTransitionGroup} = require 'nylas-component-kit'
|
|
|
|
class ActivitySidebar extends React.Component
|
|
@displayName: 'ActivitySidebar'
|
|
|
|
@containerRequired: false
|
|
@containerStyles:
|
|
minWidth: 165
|
|
maxWidth: 400
|
|
|
|
constructor: (@props) ->
|
|
@state = @_getStateFromStores()
|
|
|
|
componentDidMount: =>
|
|
@_unlisteners = []
|
|
@_unlisteners.push AccountStore.listen @_onAccountsChanged
|
|
@_unlisteners.push TaskQueue.listen @_onDataChanged
|
|
@_unlisteners.push NotificationStore.listen @_onDataChanged
|
|
@_onAccountsChanged()
|
|
|
|
componentWillUnmount: =>
|
|
unlisten() for unlisten in @_unlisteners
|
|
@_workerUnlisten() if @_workerUnlisten
|
|
|
|
render: =>
|
|
items = [].concat(@_renderSyncActivityItem(), @_renderNotificationActivityItems(), @_renderTaskActivityItems())
|
|
|
|
names = classNames
|
|
"sidebar-activity": true
|
|
"sidebar-activity-empty": items.length is 0
|
|
"sidebar-activity-error": error?
|
|
|
|
<TimeoutTransitionGroup
|
|
className={names}
|
|
leaveTimeout={625}
|
|
enterTimeout={125}
|
|
transitionName="activity-item">
|
|
{items}
|
|
</TimeoutTransitionGroup>
|
|
|
|
_renderSyncActivityItem: =>
|
|
count = 0
|
|
fetched = 0
|
|
progress = 0
|
|
incomplete = 0
|
|
error = null
|
|
|
|
for model, modelState of @state.sync
|
|
incomplete += 1 unless modelState.complete
|
|
error ?= modelState.error
|
|
if modelState.count
|
|
count += modelState.count / 1
|
|
fetched += modelState.fetched / 1
|
|
|
|
progress = (fetched / count) * 100 if count > 0
|
|
|
|
if incomplete is 0
|
|
return []
|
|
else if error
|
|
<div className="item" key="initial-sync">
|
|
<div className="inner">Initial sync encountered an error. Waiting to retry...
|
|
<div className="btn btn-emphasis" onClick={@_onTryAgain}>Try Again</div>
|
|
</div>
|
|
</div>
|
|
else
|
|
<div className="item" key="initial-sync">
|
|
<div className="progress-track">
|
|
<div className="progress" style={width: "#{progress}%"}></div>
|
|
</div>
|
|
<div className="inner">Syncing mail data...</div>
|
|
</div>
|
|
|
|
_renderTaskActivityItems: =>
|
|
summary = {}
|
|
|
|
@state.tasks.map (task) ->
|
|
label = task.label?()
|
|
return unless label
|
|
summary[label] ?= 0
|
|
summary[label] += 1
|
|
|
|
_.pairs(summary).map ([label, count]) ->
|
|
<div className="item" key={label}>
|
|
<div className="inner">
|
|
{label} <span className="count">({count})</span>
|
|
</div>
|
|
</div>
|
|
|
|
_renderNotificationActivityItems: =>
|
|
@state.notifications.map (notification) ->
|
|
<div className="item" key={notification.id}>
|
|
<div className="inner">
|
|
{notification.message}
|
|
</div>
|
|
</div>
|
|
|
|
_onAccountsChanged: =>
|
|
account = AccountStore.current()
|
|
return unless account
|
|
@_worker = NylasAPI.workerForAccount(account)
|
|
@_workerUnlisten() if @_workerUnlisten
|
|
@_workerUnlisten = @_worker.listen(@_onDataChanged, @)
|
|
@_onDataChanged()
|
|
|
|
_onTryAgain: =>
|
|
@_worker.resumeFetches()
|
|
|
|
_onDataChanged: =>
|
|
@setState(@_getStateFromStores())
|
|
|
|
_getStateFromStores: =>
|
|
tasks: TaskQueue.queue()
|
|
notifications: NotificationStore.notifications()
|
|
sync: @_worker?.state()
|
|
|
|
|
|
module.exports = ActivitySidebar
|