mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
351a602b86
- Creates OutlineView generic component and uses that instead of custom code - Refactors AccountSidebarStore: - Split the generation of the state tree into smaller functions - Adds different types of account sidebar items and sections, which contain logic and props necessary to be rendered as OutlineViewItems, and removes that logic from the store - Removes WorkspaceStore.SidebarItem and removes the ability to register new sidebar items. If people want to add something to the sidebar they can just register a Component via the component registry and use the OutlineView component - Removes the DraftListSidebarItem, which was basically duplicated code for an item but with a different data source. This is now handled generically by the account sidebar by rendering OutlineViewItems with different props and handlers - Clean ups here and there: - TODO - Add AccountSwitcher - Revisit calculation and generation of the state tree. Should the parent store contain and update the entire state all the time. Should separate items inside the tree have their own data sources? - This would avoid having the AccountSidebarStore listen to a bunch of different other stores, and the specific logic wold be contained inside each item type.
47 lines
1.1 KiB
CoffeeScript
47 lines
1.1 KiB
CoffeeScript
React = require 'react'
|
|
_ = require 'underscore'
|
|
{OutlineView, ScrollRegion} = require 'nylas-component-kit'
|
|
AccountSidebarStore = require '../account-sidebar-store'
|
|
SidebarSection = require './sidebar-section'
|
|
|
|
|
|
class AccountSidebar extends React.Component
|
|
@displayName: 'AccountSidebar'
|
|
|
|
@containerRequired: false
|
|
@containerStyles:
|
|
minWidth: 165
|
|
maxWidth: 210
|
|
|
|
constructor: (@props) ->
|
|
@state = @_getStateFromStores()
|
|
|
|
componentDidMount: =>
|
|
@unsubscribers = []
|
|
@unsubscribers.push AccountSidebarStore.listen @_onStoreChange
|
|
|
|
componentWillUnmount: =>
|
|
unsubscribe() for unsubscribe in @unsubscribers
|
|
|
|
_onStoreChange: =>
|
|
@setState @_getStateFromStores()
|
|
|
|
_getStateFromStores: =>
|
|
sections: [
|
|
AccountSidebarStore.mailboxesSection()
|
|
AccountSidebarStore.categoriesSection()
|
|
]
|
|
|
|
_renderSections: =>
|
|
@state.sections.map (section) =>
|
|
<OutlineView key={section.label} {...section} />
|
|
|
|
render: =>
|
|
<ScrollRegion style={flex:1} id="account-sidebar">
|
|
<div className="account-sidebar-sections">
|
|
{@_renderSections()}
|
|
</div>
|
|
</ScrollRegion>
|
|
|
|
|
|
module.exports = AccountSidebar
|