Mailspring/internal_packages/account-sidebar/lib/account-sidebar-mail-view-item.cjsx
Ben Gotow a83201ef7e feat(sidebar): Hierarchical folders/labels in the sidebar, rendering perf
Summary:
Fix label sorting... apparently we just synced them in creation date order

Allow labels / folders to be nested using separators `.`, `/`, and `\`

Allow collapsing of nested labels in sidebar

Add overflow hidden to some core flexboxes, which dramatically reduces repaints because it knows columns will not overflow into other columns

Prevent scroll region contents from re-rendering all the time, not sure why this works

Add test for account sidebar store

Test Plan: Run new test of AccountSidebarStore

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2181
2015-10-22 10:53:57 -07:00

83 lines
2.4 KiB
CoffeeScript

React = require 'react'
classNames = require 'classnames'
{Actions,
Utils,
UnreadCountStore,
WorkspaceStore,
AccountStore,
FocusedMailViewStore,
ChangeLabelsTask,
ChangeFolderTask,
CategoryStore} = require 'nylas-exports'
{RetinaImg, DropZone} = require 'nylas-component-kit'
class AccountSidebarMailViewItem extends React.Component
@displayName: 'AccountSidebarMailViewItem'
@propTypes:
select: React.PropTypes.bool
item: React.PropTypes.object.isRequired
mailView: React.PropTypes.object.isRequired
constructor: (@props) ->
@state =
unreadCount: UnreadCountStore.count() ? 0
componentWillMount: =>
@_usub = UnreadCountStore.listen @_onUnreadCountChange
componentWillUnmount: =>
@_usub()
_onUnreadCountChange: =>
@setState unreadCount: UnreadCountStore.count()
shouldComponentUpdate: (nextProps, nextState) =>
!Utils.isEqualReact(@props, nextProps) or !Utils.isEqualReact(@state, nextState)
render: =>
unread = []
if @props.mailView.category?.name is "inbox" and @state.unreadCount > 0
unread = <div className="unread item-count-box">{@state.unreadCount}</div>
containerClass = classNames
'item': true
'selected': @props.select
'dropping': @state.isDropping
<DropZone className={containerClass}
onClick={@_onClick}
id={@props.mailView.id}
shouldAcceptDrop={@_shouldAcceptDrop}
onDragStateChange={ ({isDropping}) => @setState({isDropping}) }
onDrop={@_onDrop}>
{unread}
<div className="icon">{@_renderIcon()}</div>
<div className="name">{@props.item.name}</div>
</DropZone>
_renderIcon: ->
<RetinaImg name={@props.mailView.iconName} fallback={'folder.png'} mode={RetinaImg.Mode.ContentIsMask} />
_shouldAcceptDrop: (e) =>
return false if @props.mailView.isEqual(FocusedMailViewStore.mailView())
return false unless @props.mailView.canApplyToThreads()
'nylas-thread-ids' in e.dataTransfer.types
_onDrop: (e) =>
jsonString = e.dataTransfer.getData('nylas-thread-ids')
try
ids = JSON.parse(jsonString)
catch err
console.error("AccountSidebarMailViewItem onDrop: JSON parse #{err}")
return unless ids
@props.mailView.applyToThreads(ids)
_onClick: (event) =>
event.preventDefault()
Actions.selectRootSheet(WorkspaceStore.Sheet.Threads)
Actions.focusMailView(@props.mailView)
module.exports = AccountSidebarMailViewItem