Fix issues in AccountSidebarStore and MailboxPerpective#isEqual

This commit is contained in:
Juan Tejada 2016-01-11 17:54:40 -08:00
parent b1d1889f28
commit 8db220cbb9
3 changed files with 21 additions and 13 deletions

View file

@ -43,7 +43,7 @@ class AccountSidebarStore extends NylasStore
@listenTo WorkspaceStore, @_updateSections
@listenTo CategoryStore, @_updateSections
@listenTo ThreadCountsStore, @_updateSections
@listenTo FocusedPerspectiveStore, => @_onPerspectiveChanged
@listenTo FocusedPerspectiveStore, @_onPerspectiveChanged
@configSubscription = NylasEnv.config.observe(
'core.workspace.showUnreadForAllCategories',
@_updateSections
@ -52,8 +52,9 @@ class AccountSidebarStore extends NylasStore
_onPerspectiveChanged: =>
account = FocusedPerspectiveStore.current()?.account
if account?.id isnt @_account?.id
@_uptdateSections()
@_trigger()
@_account = account
@_updateSections()
@trigger()
_updateSections: =>
# TODO As it is now, if the current account is null, we will display the

View file

@ -10,6 +10,7 @@ Actions = require '../actions'
class FocusedPerspectiveStore extends NylasStore
constructor: ->
@_current = @_defaultPerspective()
@listenTo CategoryStore, @_onCategoryStoreChanged
@listenTo AccountStore, @_onAccountStoreChanged
@ -32,13 +33,13 @@ class FocusedPerspectiveStore extends NylasStore
account = @_current.account
catId = @_current.categoryId()
if catId and not CategoryStore.byId(account, catId)
@_setPerspective(@_defaultPerspective())
@_setPerspective(@_defaultPerspective(account))
_onFocusPerspective: (filter) =>
return if filter.isEqual(@_current)
_onFocusPerspective: (perspective) =>
return if perspective.isEqual(@_current)
if WorkspaceStore.Sheet.Threads
Actions.selectRootSheet(WorkspaceStore.Sheet.Threads)
@_setPerspective(filter)
@_setPerspective(perspective)
_onFocusAccount: (accountId) =>
account = AccountStore.accountForId(accountId) unless account instanceof Account
@ -54,9 +55,9 @@ class FocusedPerspectiveStore extends NylasStore
return MailboxPerspective.forCategory(account, category)
# MailboxPerspective.unified()
_setPerspective: (filter) ->
return if filter?.isEqual(@_current)
@_current = filter
_setPerspective: (perspective) ->
return if perspective?.isEqual(@_current)
@_current = perspective
@trigger()
_setupFastAccountCommands: ->
@ -87,6 +88,7 @@ class FocusedPerspectiveStore extends NylasStore
# Public Methods
current: -> @_current ? null
current: =>
@_current
module.exports = new FocusedPerspectiveStore()

View file

@ -32,10 +32,14 @@ class MailboxPerspective
constructor: (@account) ->
hasSameAccount: (other) ->
return true if (@account ? null) is (other.account ? null)
return @account?.id is other?.account?.id
isEqual: (other) ->
return false unless other and @constructor.name is other.constructor.name
return false if other.name isnt @name
return false if @account? and @account.accountId isnt other.account?.accountId
return false unless @hasSameAccount(other)
matchers = @matchers() ? []
otherMatchers = other.matchers() ? []
@ -148,8 +152,9 @@ class CategoryMailboxPerspective extends MailboxPerspective
@
matchers: ->
matchers: =>
matchers = []
return matchers unless @account?
if @account.usesLabels()
matchers.push Thread.attributes.labels.contains(@category.id)
else if @account.usesFolders()