diff --git a/internal_packages/account-sidebar/lib/account-commands.coffee b/internal_packages/account-sidebar/lib/account-commands.coffee index d153ff573..9005a6ded 100644 --- a/internal_packages/account-sidebar/lib/account-commands.coffee +++ b/internal_packages/account-sidebar/lib/account-commands.coffee @@ -12,8 +12,10 @@ class AccountCommands @_isSelected: (account, focusedAccounts) => if focusedAccounts.length > 1 return account instanceof Array - else + else if focusedAccounts.length is 1 return account?.id is focusedAccounts[0].id + else + return false @registerCommands: (accounts) -> @_commandsDisposable?.dispose() diff --git a/internal_packages/account-sidebar/lib/sidebar-actions.coffee b/internal_packages/account-sidebar/lib/sidebar-actions.coffee index 80b7774fd..8aaa18047 100644 --- a/internal_packages/account-sidebar/lib/sidebar-actions.coffee +++ b/internal_packages/account-sidebar/lib/sidebar-actions.coffee @@ -1,7 +1,8 @@ Reflux = require 'reflux' Actions = [ - 'focusAccounts' + 'focusAccounts', + 'setKeyCollapsed', ] for idx in Actions diff --git a/internal_packages/account-sidebar/lib/sidebar-item.coffee b/internal_packages/account-sidebar/lib/sidebar-item.coffee index 5793f8a75..391891dbc 100644 --- a/internal_packages/account-sidebar/lib/sidebar-item.coffee +++ b/internal_packages/account-sidebar/lib/sidebar-item.coffee @@ -9,6 +9,7 @@ _str = require 'underscore.string' Utils} = require 'nylas-exports' {OutlineViewItem} = require 'nylas-component-kit' +SidebarActions = require './sidebar-actions' idForCategories = (categories) -> _.pluck(categories, 'id').join('-') @@ -27,13 +28,14 @@ isItemDeleted = (perspective) -> _.any perspective.categories(), (c) -> c.isDeleted isItemCollapsed = (id) -> - key = "core.accountSidebarCollapsed.#{id}" - NylasEnv.config.get(key) + if NylasEnv.savedState.sidebarKeysCollapsed[id] isnt undefined + NylasEnv.savedState.sidebarKeysCollapsed[id] + else + true toggleItemCollapsed = (item) -> return unless item.children.length > 0 - key = "core.accountSidebarCollapsed.#{item.id}" - NylasEnv.config.set(key, not item.collapsed) + SidebarActions.setKeyCollapsed(item.id, not isItemCollapsed(item.id)) onDeleteItem = (item) -> # TODO Delete multiple categories at once diff --git a/internal_packages/account-sidebar/lib/sidebar-section.coffee b/internal_packages/account-sidebar/lib/sidebar-section.coffee index 2205b7da2..8f87d2724 100644 --- a/internal_packages/account-sidebar/lib/sidebar-section.coffee +++ b/internal_packages/account-sidebar/lib/sidebar-section.coffee @@ -6,17 +6,17 @@ _ = require 'underscore' CategoryStore, Category} = require 'nylas-exports' SidebarItem = require './sidebar-item' +SidebarActions = require './sidebar-actions' +isSectionCollapsed = (title) -> + if NylasEnv.savedState.sidebarKeysCollapsed[title] isnt undefined + NylasEnv.savedState.sidebarKeysCollapsed[title] + else + false -isSectionCollapsed = (id) -> - key = "core.accountSidebarCollapsed.#{id}Section" - collapsed = NylasEnv.config.get(key) - -toggleSectionCollapse = (section) -> - key = "core.accountSidebarCollapsed.#{section.title}Section" +toggleSectionCollapsed = (section) -> return unless section - NylasEnv.config.set(key, not section.collapsed) - + SidebarActions.setKeyCollapsed(section.title, not isSectionCollapsed(section.title)) class SidebarSection @@ -130,7 +130,7 @@ class SidebarSection title ?= account.categoryLabel() collapsed = isSectionCollapsed(title) if collapsible - onCollapseToggled = toggleSectionCollapse + onCollapseToggled = toggleSectionCollapsed return { title: title diff --git a/internal_packages/account-sidebar/lib/sidebar-store.coffee b/internal_packages/account-sidebar/lib/sidebar-store.coffee index d70a49767..eac634aa9 100644 --- a/internal_packages/account-sidebar/lib/sidebar-store.coffee +++ b/internal_packages/account-sidebar/lib/sidebar-store.coffee @@ -20,10 +20,13 @@ Sections = { class SidebarStore extends NylasStore constructor: -> + NylasEnv.savedState.sidebarKeysCollapsed ?= {} + @_sections = {} @_sections[Sections.Standard] = {} @_sections[Sections.User] = [] - @_focusedAccounts = @accounts() + @_focusedAccounts = FocusedPerspectiveStore.current().accountIds.map (id) -> + AccountStore.accountForId(id) @_registerCommands() @_registerMenuItems() @_registerListeners() @@ -43,6 +46,7 @@ class SidebarStore extends NylasStore _registerListeners: -> @listenTo SidebarActions.focusAccounts, @_onAccountsFocused + @listenTo SidebarActions.setKeyCollapsed, @_onSetCollapsed @listenTo AccountStore, @_onAccountsChanged @listenTo FocusedPerspectiveStore, @_onFocusedPerspectiveChanged @listenTo WorkspaceStore, @_updateSections @@ -54,12 +58,13 @@ class SidebarStore extends NylasStore 'core.workspace.showUnreadForAllCategories', @_updateSections ) - @configSubscription = NylasEnv.config.onDidChange( - 'core.accountSidebarCollapsed', - @_updateSections - ) + return + _onSetCollapsed: (key, collapsed) => + NylasEnv.savedState.sidebarKeysCollapsed[key] = collapsed + @_updateSections() + _registerCommands: (accounts = AccountStore.accounts()) => AccountCommands.registerCommands(accounts) diff --git a/internal_packages/search-bar/lib/search-bar.cjsx b/internal_packages/search-bar/lib/search-bar.cjsx index 4ae638f7e..f2f8302eb 100644 --- a/internal_packages/search-bar/lib/search-bar.cjsx +++ b/internal_packages/search-bar/lib/search-bar.cjsx @@ -14,10 +14,9 @@ class SearchBar extends React.Component @displayName = 'SearchBar' constructor: (@props) -> - @state = - query: "" + @state = _.extend({}, @_getStateFromStores(), { focused: false - suggestions: [] + },) componentDidMount: => @usub = [] diff --git a/internal_packages/search-bar/lib/search-suggestion-store.coffee b/internal_packages/search-bar/lib/search-suggestion-store.coffee index 3a782f4ad..5d85b3137 100644 --- a/internal_packages/search-bar/lib/search-suggestion-store.coffee +++ b/internal_packages/search-bar/lib/search-suggestion-store.coffee @@ -19,7 +19,7 @@ SearchActions = require './search-actions' class SearchSuggestionStore extends NylasStore constructor: -> - @_searchQuery = "" + @_searchQuery = FocusedPerspectiveStore.current().searchQuery ? "" @_searchSuggestionsVersion = 1 @_clearResults() @@ -47,8 +47,11 @@ class SearchSuggestionStore extends NylasStore Actions.focusMailboxPerspective(next) else if FocusedPerspectiveStore.current().searchQuery - Actions.focusMailboxPerspective(@_perspectiveBeforeSearch) - @_perspectiveBeforeSearch = null + if @_perspectiveBeforeSearch + Actions.focusMailboxPerspective(@_perspectiveBeforeSearch) + @_perspectiveBeforeSearch = null + else + Actions.focusDefaultMailboxPerspectiveForAccounts(AccountStore.accounts()) @_clearResults() diff --git a/src/flux/action-bridge.coffee b/src/flux/action-bridge.coffee index 217ca36fc..893bead26 100644 --- a/src/flux/action-bridge.coffee +++ b/src/flux/action-bridge.coffee @@ -3,8 +3,6 @@ Model = require './models/model' DatabaseStore = require './stores/database-store' Utils = require './models/utils' -TaskRegistry = require '../task-registry' -DatabaseObjectRegistry = require '../database-object-registry' Role = WORK: 'work', diff --git a/src/flux/stores/focused-perspective-store.coffee b/src/flux/stores/focused-perspective-store.coffee index 21c008631..3a8c0221e 100644 --- a/src/flux/stores/focused-perspective-store.coffee +++ b/src/flux/stores/focused-perspective-store.coffee @@ -8,15 +8,14 @@ Actions = require '../actions' class FocusedPerspectiveStore extends NylasStore constructor: -> - @_current = @_defaultPerspective() + if NylasEnv.savedState.perspective + @_current = MailboxPerspective.fromJSON(NylasEnv.savedState.perspective) + @_current ?= @_defaultPerspective() @listenTo CategoryStore, @_onCategoryStoreChanged - @listenTo Actions.focusMailboxPerspective, @_onFocusPerspective @listenTo Actions.focusDefaultMailboxPerspectiveForAccounts, @_onFocusAccounts - @_onCategoryStoreChanged() - # Inbound Events _onCategoryStoreChanged: -> @@ -45,6 +44,7 @@ class FocusedPerspectiveStore extends NylasStore _setPerspective: (perspective) -> return if perspective?.isEqual(@_current) + NylasEnv.savedState.perspective = perspective.toJSON() @_current = perspective @trigger() diff --git a/src/mailbox-perspective.coffee b/src/mailbox-perspective.coffee index 530ef5ab7..ae63b8bd5 100644 --- a/src/mailbox-perspective.coffee +++ b/src/mailbox-perspective.coffee @@ -1,5 +1,6 @@ _ = require 'underscore' +Utils = require './flux/models/utils' TaskFactory = require './flux/tasks/task-factory' AccountStore = require './flux/stores/account-store' CategoryStore = require './flux/stores/category-store' @@ -44,6 +45,22 @@ class MailboxPerspective @forInbox: (accountsOrIds) => @forStandardCategories(accountsOrIds, 'inbox') + @fromJSON: (json) => + try + if json.type is CategoryMailboxPerspective.name + categories = JSON.parse(json.serializedCategories, Utils.registeredObjectReviver) + return @forCategories(categories) + else if json.type is SearchMailboxPerspective.name + return @forSearch(json.accountIds, json.searchQuery) + else if json.type is StarredMailboxPerspective.name + return @forStarred(json.accountIds) + else if json.type is DraftsMailboxPerspective.name + return @forDrafts(json.accountIds) + else + return null + catch error + NylasEnv.reportError(new Error("Could not restore mailbox perspective: #{error}")) + return null # Instance Methods @@ -52,6 +69,9 @@ class MailboxPerspective throw new Error("#{@constructor.name}: You must provide an array of string `accountIds`") @ + toJSON: => + return {accountIds: @accountIds, type: @constructor.name} + isEqual: (other) => return false unless other and @constructor is other.constructor return false unless other.name is @name @@ -123,6 +143,11 @@ class SearchMailboxPerspective extends MailboxPerspective @ + toJSON: => + json = super + json.searchQuery = @searchQuery + json + isEqual: (other) => super(other) and other.searchQuery is @searchQuery @@ -147,6 +172,9 @@ class DraftsMailboxPerspective extends MailboxPerspective @drafts = true # The DraftListStore looks for this @ + fromJSON: => + {type: @constructor.name, accountIds: @accountIds} + threads: => null @@ -220,8 +248,13 @@ class CategoryMailboxPerspective extends MailboxPerspective @ + toJSON: => + json = super + json.serializedCategories = JSON.stringify(@_categories, Utils.registeredObjectReplacer) + json + isEqual: (other) => - super(other) and _.isEqual(@categories(), other.categories()) + super(other) and _.isEqual(_.pluck(@categories(), 'id'), _.pluck(other.categories(), 'id')) threads: => query = DatabaseStore.findAll(Thread) diff --git a/static/components/outline-view.less b/static/components/outline-view.less index 830f3311c..9a19fc826 100644 --- a/static/components/outline-view.less +++ b/static/components/outline-view.less @@ -45,6 +45,7 @@ display: none; min-width: 30px; margin-left: auto; + margin-right: 8px; } &:hover {