Mailspring/internal_packages/thread-list/lib/thread-list.cjsx

301 lines
9.2 KiB
Plaintext
Raw Normal View History

_ = require 'underscore'
React = require 'react'
classNames = require 'classnames'
{ListTabular,
MultiselectList,
RetinaImg,
MailLabel,
InjectedComponentSet} = require 'nylas-component-kit'
{timestamp, subject} = require './formatting-utils'
{Actions,
Utils,
Thread,
CanvasUtils,
TaskFactory,
WorkspaceStore,
AccountStore,
CategoryStore,
FocusedContentStore,
FocusedMailViewStore} = require 'nylas-exports'
ThreadListParticipants = require './thread-list-participants'
ThreadListQuickActions = require './thread-list-quick-actions'
feat(thread-list): Multiple selection, bulk actions, refactoring Summary: This diff provides multi-selection in the thread list powered by a new ModelList component that implements selection on top of ListTabular (or soon another List component). It includes business logic for single selection, shift selection, command-click selection, etc. This diff also improves the performance of DatabaseView by assessing whether updates are required based on specific database changes and skipping queries in many scenarios. WIP WIP Move selection into modelView instead of store WIP Preparing to convert to ModelList mixin Make ThreadStore => ThreadListStore Break the DraftStore in two (new DraftListStore) to avoid keeping all drafts in all windows Get rid of unread instance variable in favor of getter that falls through to isUnread() Much smarter logic in DatabaseView to prevent needless queries (especially counts and full invalidation of retained range) Squashed commit of the following: commit 486516b540e659735675765ca8b20d8a107ee2a9 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:23 2015 -0700 Invalidate the retained range debounced commit 7ac80403f52d108696c555f79c4c687d969f0228 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:16 2015 -0700 Wait until after the view updates to move focus commit 88d66eb19a9710847ff98bea22045bb686f30cc6 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:28:01 2015 -0700 Bail out early when loading data if a reload has been requested commit a49bedc44687040f7c675ff298376917a0b5fdcb Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:58 2015 -0700 Log query data when in a query is being logged commit c64a9e02f9072fd30edb98c45be581d6ac00c48a Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:45 2015 -0700 Mark thread and messages as read in parallel instead of in sequence commit 4b227100a795e20257cda0d60b00cc75b0000b0f Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:32 2015 -0700 Don't load tags with hardcoded IDs from the database, and load them in parallel instead of in sequence commit aeb7f1d646786cfa1c247fe78ce5467da07c4446 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:37:54 2015 -0700 Pass objects instead of ids to thread methods—since we always have the most current thread anyway, this makes things a bit faster commit e70889d1d05ece81a081b8b3f27b62491429b6f9 Author: Ben Gotow <bengotow@gmail.com> Date: Mon Apr 6 16:41:49 2015 -0700 [icon] Paper airplanes Restyle account sidebar, optimize tag count queries a bit more Fix initialization issue with webkit image mask Can't compare dates with is/isnt Assets for check boxes Bug fixes Wrap ModelList instead of providing props Verbose mode for database view Fix existing specs Six new specs covering invalidateIfItemsInconsistent Test Plan: Run 40+ new tests Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1410
2015-04-09 10:25:00 +08:00
ThreadListStore = require './thread-list-store'
ThreadListIcon = require './thread-list-icon'
EmptyState = require './empty-state'
{MailImportantIcon} = require 'nylas-component-kit'
class ThreadListScrollTooltip extends React.Component
@displayName: 'ThreadListScrollTooltip'
@propTypes:
viewportCenter: React.PropTypes.number.isRequired
totalHeight: React.PropTypes.number.isRequired
componentWillMount: =>
@setupForProps(@props)
componentWillReceiveProps: (newProps) =>
@setupForProps(newProps)
shouldComponentUpdate: (newProps, newState) =>
@state?.idx isnt newState.idx
setupForProps: (props) ->
idx = Math.floor(ThreadListStore.view().count() / @props.totalHeight * @props.viewportCenter)
@setState
idx: idx
item: ThreadListStore.view().get(idx)
render: ->
perf(thread-list): Tailored SQLite indexes, ListTabular / ScrollRegion optimizations galore Summary: Allow Database models to create indexes, but don't autocreate bad ones fix minor bug in error-reporter Fix index on message list to make thread list lookups use proper index Developer bar ignores state changes unless it's open DatabaseView now asks for metadata for a set of items rather than calling a function for every item. Promise.props was cute but we really needed to make a single database query for all message metadata. New "in" matcher so you can say `thread_id IN (1,2,3)` Add .scroll-region-content-inner which is larger than the viewport by 1 page size, and uses transform(0,0,0) trick ScrollRegion exposes `onScrollEnd` so listTabular, et al don't need to re-implement it with more timers. Also removing requestAnimationFrame which was causing us to request scrollTop when it was not ready, and caching the values of... ...clientHeight/scrollHeight while scrolling is in-flight Updating rendered content 10 rows at a time (RangeChunkSize) was a bad idea. Instead, add every row in a render: pass as it comes in (less work all the time vs more work intermittently). Also remove bad requestAnimationFrame, and prevent calls to... ...updateRangeState from triggering additional calls to updateRangeState by removing `componentDidUpdate => updateRangeState ` Turning off hover (pointer-events:none) is now standard in ScrollRegion Loading text in the scroll tooltip, instead of random date shown Handle query parse errors by catching error and throwing a better more explanatory error Replace "quick action" retina images with background images to make React render easier Replace hasTagId with a faster implementation which doesn't call functions and doesn't build a temporary array Print query durations when printing to console instead of only in metadata Remove headers from support from ListTabular, we'll never use it Making columns part of state was a good idea but changing the array causes the entire ListTabular to re-render. To avoid this, be smarter about updating columns. This logic could potentially go in `componentDidReceiveProps` too. Fix specs and add 6 more for new database store functionality Test Plan: Run 6 new specs. More in the works? Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1651
2015-06-18 11:12:48 +08:00
if @state.item
content = timestamp(@state.item.lastMessageReceivedTimestamp)
perf(thread-list): Tailored SQLite indexes, ListTabular / ScrollRegion optimizations galore Summary: Allow Database models to create indexes, but don't autocreate bad ones fix minor bug in error-reporter Fix index on message list to make thread list lookups use proper index Developer bar ignores state changes unless it's open DatabaseView now asks for metadata for a set of items rather than calling a function for every item. Promise.props was cute but we really needed to make a single database query for all message metadata. New "in" matcher so you can say `thread_id IN (1,2,3)` Add .scroll-region-content-inner which is larger than the viewport by 1 page size, and uses transform(0,0,0) trick ScrollRegion exposes `onScrollEnd` so listTabular, et al don't need to re-implement it with more timers. Also removing requestAnimationFrame which was causing us to request scrollTop when it was not ready, and caching the values of... ...clientHeight/scrollHeight while scrolling is in-flight Updating rendered content 10 rows at a time (RangeChunkSize) was a bad idea. Instead, add every row in a render: pass as it comes in (less work all the time vs more work intermittently). Also remove bad requestAnimationFrame, and prevent calls to... ...updateRangeState from triggering additional calls to updateRangeState by removing `componentDidUpdate => updateRangeState ` Turning off hover (pointer-events:none) is now standard in ScrollRegion Loading text in the scroll tooltip, instead of random date shown Handle query parse errors by catching error and throwing a better more explanatory error Replace "quick action" retina images with background images to make React render easier Replace hasTagId with a faster implementation which doesn't call functions and doesn't build a temporary array Print query durations when printing to console instead of only in metadata Remove headers from support from ListTabular, we'll never use it Making columns part of state was a good idea but changing the array causes the entire ListTabular to re-render. To avoid this, be smarter about updating columns. This logic could potentially go in `componentDidReceiveProps` too. Fix specs and add 6 more for new database store functionality Test Plan: Run 6 new specs. More in the works? Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1651
2015-06-18 11:12:48 +08:00
else
content = "Loading..."
<div className="scroll-tooltip">
perf(thread-list): Tailored SQLite indexes, ListTabular / ScrollRegion optimizations galore Summary: Allow Database models to create indexes, but don't autocreate bad ones fix minor bug in error-reporter Fix index on message list to make thread list lookups use proper index Developer bar ignores state changes unless it's open DatabaseView now asks for metadata for a set of items rather than calling a function for every item. Promise.props was cute but we really needed to make a single database query for all message metadata. New "in" matcher so you can say `thread_id IN (1,2,3)` Add .scroll-region-content-inner which is larger than the viewport by 1 page size, and uses transform(0,0,0) trick ScrollRegion exposes `onScrollEnd` so listTabular, et al don't need to re-implement it with more timers. Also removing requestAnimationFrame which was causing us to request scrollTop when it was not ready, and caching the values of... ...clientHeight/scrollHeight while scrolling is in-flight Updating rendered content 10 rows at a time (RangeChunkSize) was a bad idea. Instead, add every row in a render: pass as it comes in (less work all the time vs more work intermittently). Also remove bad requestAnimationFrame, and prevent calls to... ...updateRangeState from triggering additional calls to updateRangeState by removing `componentDidUpdate => updateRangeState ` Turning off hover (pointer-events:none) is now standard in ScrollRegion Loading text in the scroll tooltip, instead of random date shown Handle query parse errors by catching error and throwing a better more explanatory error Replace "quick action" retina images with background images to make React render easier Replace hasTagId with a faster implementation which doesn't call functions and doesn't build a temporary array Print query durations when printing to console instead of only in metadata Remove headers from support from ListTabular, we'll never use it Making columns part of state was a good idea but changing the array causes the entire ListTabular to re-render. To avoid this, be smarter about updating columns. This logic could potentially go in `componentDidReceiveProps` too. Fix specs and add 6 more for new database store functionality Test Plan: Run 6 new specs. More in the works? Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1651
2015-06-18 11:12:48 +08:00
{content}
</div>
class ThreadList extends React.Component
@displayName: 'ThreadList'
feat(unsafe-components): Wrap injected components, catch exceptions, clean up ComponentRegistry Summary: This diff gives the ComponentRegistry a cleaner, smaller API. Instead of querying by name, location or role, it's now just location and role, and you can register components for one or more location and one or more roles without assigning the entries in the registry separate names. When you register with the ComponentRegistry, the syntax is also cleaner and uses the component's displayName instead of requiring you to provide a name. You also provide the actual component when unregistering, ensuring that you can't unregister someone else's component. InjectedComponent and InjectedComponentSet now wrap their children in UnsafeComponent, which prevents render/component lifecycle problems from propogating. Existing components have been updated: 1. maxWidth / minWidth are now containerStyles.maxWidth/minWidth 2. displayName is now required to use the CR. 3. containerRequired = false can be provided to exempt a component from being wrapped in an UnsafeComponent. This is useful because it's slightly faster and keeps DOM flat. This diff also makes the "Show Component Regions" more awesome. It displays column regions, since they now use the InjectedComponentSet, and also shows for InjectedComponent as well as InjectedComponentSet. Change ComponentRegistry syntax, lots more work on safely wrapping items. See description. Fix for inline flexbox scenarios (message actions) Allow ~/.inbox/packages to be symlinked to a github repo Test Plan: Run tests! Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1457
2015-05-01 07:10:15 +08:00
@containerRequired: false
@containerStyles:
minWidth: 300
maxWidth: 3000
constructor: (@props) ->
@state =
style: 'unknown'
componentWillMount: =>
c1 = new ListTabular.Column
name: "★"
resolver: (thread) =>
[
<ThreadListIcon thread={thread} />
<MailImportantIcon thread={thread} />
<InjectedComponentSet
inline={true}
containersRequired={false}
matching={role: "ThreadListIcon"}
className="thread-injected-icons"
exposedProps={thread: thread}/>
]
c2 = new ListTabular.Column
name: "Participants"
width: 200
resolver: (thread) =>
feat(*): draft icon, misc fixes, and WorkspaceStore / custom toolbar in secondary windows Summary: Features: - ThreadListParticipants ignores drafts when computing participants, renders "Draft" label, pending design - Put the WorkspaceStore in every window—means they all get toolbars and custom gumdrop icons on Mac OS X Bug Fixes: - Never display notifications for email the user just sent - Fix obscure issue with DatabaseView trying to update metadata on items it froze. This resolves issue with names remaining bold after marking as read, drafts not appearing in message list immediately. - When you pop out a draft, save it first and *wait* for the commit() promise to succeed. - If you scroll very fast, you node.contentWindow can be null in eventedIframe Other: Make it OK to re-register the same component Make it possible to unregister a hot window Break the Sheet Toolbar out into it's own file to make things manageable Replace `package.windowPropsReceived` with a store-style model where anyone can listen for changes to `windowProps` When I put the WorkspaceStore in every window, I ran into a problem because the package was no longer rendering an instance of the Composer, it was declaring a root sheet with a composer in it. This meant that it was actually a React component that needed to listen to window props, not the package itself. `atom` is already an event emitter, so I added a `onWindowPropsReceived` hook so that components can listen to window props as if they were listening to a store. I think this might be more flexible than only broadcasting the props change event to packages. Test Plan: Run tests Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1592
2015-06-04 07:02:19 +08:00
hasDraft = _.find (thread.metadata ? []), (m) -> m.draft
if hasDraft
<div style={display: 'flex'}>
<ThreadListParticipants thread={thread} />
<RetinaImg name="icon-draft-pencil.png"
className="draft-icon"
mode={RetinaImg.Mode.ContentPreserve} />
feat(*): draft icon, misc fixes, and WorkspaceStore / custom toolbar in secondary windows Summary: Features: - ThreadListParticipants ignores drafts when computing participants, renders "Draft" label, pending design - Put the WorkspaceStore in every window—means they all get toolbars and custom gumdrop icons on Mac OS X Bug Fixes: - Never display notifications for email the user just sent - Fix obscure issue with DatabaseView trying to update metadata on items it froze. This resolves issue with names remaining bold after marking as read, drafts not appearing in message list immediately. - When you pop out a draft, save it first and *wait* for the commit() promise to succeed. - If you scroll very fast, you node.contentWindow can be null in eventedIframe Other: Make it OK to re-register the same component Make it possible to unregister a hot window Break the Sheet Toolbar out into it's own file to make things manageable Replace `package.windowPropsReceived` with a store-style model where anyone can listen for changes to `windowProps` When I put the WorkspaceStore in every window, I ran into a problem because the package was no longer rendering an instance of the Composer, it was declaring a root sheet with a composer in it. This meant that it was actually a React component that needed to listen to window props, not the package itself. `atom` is already an event emitter, so I added a `onWindowPropsReceived` hook so that components can listen to window props as if they were listening to a store. I think this might be more flexible than only broadcasting the props change event to packages. Test Plan: Run tests Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1592
2015-06-04 07:02:19 +08:00
</div>
else
<ThreadListParticipants thread={thread} />
c3LabelComponentCache = {}
c3 = new ListTabular.Column
name: "Message"
flex: 4
resolver: (thread) =>
attachment = []
labels = []
if thread.hasAttachments
attachment = <div className="thread-icon thread-icon-attachment"></div>
currentCategoryId = FocusedMailViewStore.mailView()?.categoryId()
allCategoryId = CategoryStore.getStandardCategory('all')?.id
ignoredIds = [currentCategoryId]
ignoredIds.push(cat.id) for cat in CategoryStore.getHiddenCategories()
for label in (thread.sortedLabels())
continue if label.id in ignoredIds
c3LabelComponentCache[label.id] ?= <MailLabel label={label} key={label.id} />
labels.push c3LabelComponentCache[label.id]
<span className="details">
{labels}
<span className="subject">{subject(thread.subject)}</span>
<span className="snippet">{thread.snippet}</span>
{attachment}
</span>
c4 = new ListTabular.Column
name: "Date"
resolver: (thread) =>
<span className="timestamp">{timestamp(thread.lastMessageReceivedTimestamp)}</span>
c5 = new ListTabular.Column
name: "HoverActions"
resolver: (thread) =>
<ThreadListQuickActions thread={thread} />
@wideColumns = [c1, c2, c3, c4, c5]
cNarrow = new ListTabular.Column
name: "Item"
flex: 1
resolver: (thread) =>
pencil = []
attachment = []
hasDraft = _.find (thread.metadata ? []), (m) -> m.draft
if thread.hasAttachments
attachment = <div className="thread-icon thread-icon-attachment"></div>
if hasDraft
pencil = <RetinaImg name="icon-draft-pencil.png" className="draft-icon" mode={RetinaImg.Mode.ContentPreserve} />
<div>
<div style={display: 'flex'}>
<ThreadListIcon thread={thread} />
<ThreadListParticipants thread={thread} />
{pencil}
<span style={flex:1}></span>
{attachment}
<span className="timestamp">{timestamp(thread.lastMessageReceivedTimestamp)}</span>
</div>
<MailImportantIcon thread={thread} />
<div className="subject">{subject(thread.subject)}</div>
<div className="snippet">{thread.snippet}</div>
</div>
@narrowColumns = [cNarrow]
_shift = ({offset, afterRunning}) =>
view = ThreadListStore.view()
focusedId = FocusedContentStore.focusedId('thread')
focusedIdx = Math.min(view.count() - 1, Math.max(0, view.indexOfId(focusedId) + offset))
item = view.get(focusedIdx)
afterRunning()
Actions.setFocus(collection: 'thread', item: item)
feat(thread-list): Multiple selection, bulk actions, refactoring Summary: This diff provides multi-selection in the thread list powered by a new ModelList component that implements selection on top of ListTabular (or soon another List component). It includes business logic for single selection, shift selection, command-click selection, etc. This diff also improves the performance of DatabaseView by assessing whether updates are required based on specific database changes and skipping queries in many scenarios. WIP WIP Move selection into modelView instead of store WIP Preparing to convert to ModelList mixin Make ThreadStore => ThreadListStore Break the DraftStore in two (new DraftListStore) to avoid keeping all drafts in all windows Get rid of unread instance variable in favor of getter that falls through to isUnread() Much smarter logic in DatabaseView to prevent needless queries (especially counts and full invalidation of retained range) Squashed commit of the following: commit 486516b540e659735675765ca8b20d8a107ee2a9 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:23 2015 -0700 Invalidate the retained range debounced commit 7ac80403f52d108696c555f79c4c687d969f0228 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:16 2015 -0700 Wait until after the view updates to move focus commit 88d66eb19a9710847ff98bea22045bb686f30cc6 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:28:01 2015 -0700 Bail out early when loading data if a reload has been requested commit a49bedc44687040f7c675ff298376917a0b5fdcb Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:58 2015 -0700 Log query data when in a query is being logged commit c64a9e02f9072fd30edb98c45be581d6ac00c48a Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:45 2015 -0700 Mark thread and messages as read in parallel instead of in sequence commit 4b227100a795e20257cda0d60b00cc75b0000b0f Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:32 2015 -0700 Don't load tags with hardcoded IDs from the database, and load them in parallel instead of in sequence commit aeb7f1d646786cfa1c247fe78ce5467da07c4446 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:37:54 2015 -0700 Pass objects instead of ids to thread methods—since we always have the most current thread anyway, this makes things a bit faster commit e70889d1d05ece81a081b8b3f27b62491429b6f9 Author: Ben Gotow <bengotow@gmail.com> Date: Mon Apr 6 16:41:49 2015 -0700 [icon] Paper airplanes Restyle account sidebar, optimize tag count queries a bit more Fix initialization issue with webkit image mask Can't compare dates with is/isnt Assets for check boxes Bug fixes Wrap ModelList instead of providing props Verbose mode for database view Fix existing specs Six new specs covering invalidateIfItemsInconsistent Test Plan: Run 40+ new tests Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1410
2015-04-09 10:25:00 +08:00
@commands =
'core:remove-item': @_onBackspace
'core:star-item': @_onStarItem
'core:remove-and-previous': =>
_shift(offset: 1, afterRunning: @_onBackspace)
'core:remove-and-next': =>
_shift(offset: -1, afterRunning: @_onBackspace)
@itemPropsProvider = (item) ->
className: classNames
'unread': item.unread
'data-thread-id': item.id
feat(thread-list): Multiple selection, bulk actions, refactoring Summary: This diff provides multi-selection in the thread list powered by a new ModelList component that implements selection on top of ListTabular (or soon another List component). It includes business logic for single selection, shift selection, command-click selection, etc. This diff also improves the performance of DatabaseView by assessing whether updates are required based on specific database changes and skipping queries in many scenarios. WIP WIP Move selection into modelView instead of store WIP Preparing to convert to ModelList mixin Make ThreadStore => ThreadListStore Break the DraftStore in two (new DraftListStore) to avoid keeping all drafts in all windows Get rid of unread instance variable in favor of getter that falls through to isUnread() Much smarter logic in DatabaseView to prevent needless queries (especially counts and full invalidation of retained range) Squashed commit of the following: commit 486516b540e659735675765ca8b20d8a107ee2a9 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:23 2015 -0700 Invalidate the retained range debounced commit 7ac80403f52d108696c555f79c4c687d969f0228 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:16 2015 -0700 Wait until after the view updates to move focus commit 88d66eb19a9710847ff98bea22045bb686f30cc6 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:28:01 2015 -0700 Bail out early when loading data if a reload has been requested commit a49bedc44687040f7c675ff298376917a0b5fdcb Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:58 2015 -0700 Log query data when in a query is being logged commit c64a9e02f9072fd30edb98c45be581d6ac00c48a Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:45 2015 -0700 Mark thread and messages as read in parallel instead of in sequence commit 4b227100a795e20257cda0d60b00cc75b0000b0f Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:32 2015 -0700 Don't load tags with hardcoded IDs from the database, and load them in parallel instead of in sequence commit aeb7f1d646786cfa1c247fe78ce5467da07c4446 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:37:54 2015 -0700 Pass objects instead of ids to thread methods—since we always have the most current thread anyway, this makes things a bit faster commit e70889d1d05ece81a081b8b3f27b62491429b6f9 Author: Ben Gotow <bengotow@gmail.com> Date: Mon Apr 6 16:41:49 2015 -0700 [icon] Paper airplanes Restyle account sidebar, optimize tag count queries a bit more Fix initialization issue with webkit image mask Can't compare dates with is/isnt Assets for check boxes Bug fixes Wrap ModelList instead of providing props Verbose mode for database view Fix existing specs Six new specs covering invalidateIfItemsInconsistent Test Plan: Run 40+ new tests Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1410
2015-04-09 10:25:00 +08:00
componentDidMount: =>
window.addEventListener('resize', @_onResize, true)
@_onResize()
componentWillUnmount: =>
window.removeEventListener('resize', @_onResize, true)
render: =>
if @state.style is 'wide'
2015-08-04 10:09:08 +08:00
<MultiselectList
dataStore={ThreadListStore}
columns={@wideColumns}
commands={@commands}
itemPropsProvider={@itemPropsProvider}
itemHeight={39}
className="thread-list"
scrollTooltipComponent={ThreadListScrollTooltip}
emptyComponent={EmptyState}
onDragStart={@_onDragStart}
onDragEnd={@_onDragEnd}
draggable="true"
collection="thread" />
else if @state.style is 'narrow'
2015-08-04 10:09:08 +08:00
<MultiselectList
dataStore={ThreadListStore}
columns={@narrowColumns}
commands={@commands}
itemPropsProvider={@itemPropsProvider}
itemHeight={90}
className="thread-list thread-list-narrow"
scrollTooltipComponent={ThreadListScrollTooltip}
emptyComponent={EmptyState}
onDragStart={@_onDragStart}
onDragEnd={@_onDragEnd}
draggable="true"
2015-08-04 10:09:08 +08:00
collection="thread" />
else
<div></div>
_threadIdAtPoint: (x, y) ->
item = document.elementFromPoint(event.clientX, event.clientY).closest('.list-item')
return null unless item
return item.dataset.threadId
_onDragStart: (event) =>
itemThreadId = @_threadIdAtPoint(event.clientX, event.clientY)
unless itemThreadId
event.preventDefault()
return
if itemThreadId in ThreadListStore.view().selection.ids()
dragThreadIds = ThreadListStore.view().selection.ids()
else
dragThreadIds = [itemThreadId]
event.dataTransfer.effectAllowed = "move"
event.dataTransfer.dragEffect = "move"
canvas = CanvasUtils.canvasWithThreadDragImage(dragThreadIds.length)
event.dataTransfer.setDragImage(canvas, 10, 10)
event.dataTransfer.setData('nylas-thread-ids', JSON.stringify(dragThreadIds))
return
_onDragEnd: (event) =>
_onResize: (event) =>
current = @state.style
desired = if React.findDOMNode(@).offsetWidth < 540 then 'narrow' else 'wide'
if current isnt desired
@setState(style: desired)
feat(thread-list): Multiple selection, bulk actions, refactoring Summary: This diff provides multi-selection in the thread list powered by a new ModelList component that implements selection on top of ListTabular (or soon another List component). It includes business logic for single selection, shift selection, command-click selection, etc. This diff also improves the performance of DatabaseView by assessing whether updates are required based on specific database changes and skipping queries in many scenarios. WIP WIP Move selection into modelView instead of store WIP Preparing to convert to ModelList mixin Make ThreadStore => ThreadListStore Break the DraftStore in two (new DraftListStore) to avoid keeping all drafts in all windows Get rid of unread instance variable in favor of getter that falls through to isUnread() Much smarter logic in DatabaseView to prevent needless queries (especially counts and full invalidation of retained range) Squashed commit of the following: commit 486516b540e659735675765ca8b20d8a107ee2a9 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:23 2015 -0700 Invalidate the retained range debounced commit 7ac80403f52d108696c555f79c4c687d969f0228 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:30:16 2015 -0700 Wait until after the view updates to move focus commit 88d66eb19a9710847ff98bea22045bb686f30cc6 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 17:28:01 2015 -0700 Bail out early when loading data if a reload has been requested commit a49bedc44687040f7c675ff298376917a0b5fdcb Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:58 2015 -0700 Log query data when in a query is being logged commit c64a9e02f9072fd30edb98c45be581d6ac00c48a Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:45 2015 -0700 Mark thread and messages as read in parallel instead of in sequence commit 4b227100a795e20257cda0d60b00cc75b0000b0f Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:38:32 2015 -0700 Don't load tags with hardcoded IDs from the database, and load them in parallel instead of in sequence commit aeb7f1d646786cfa1c247fe78ce5467da07c4446 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Apr 7 16:37:54 2015 -0700 Pass objects instead of ids to thread methods—since we always have the most current thread anyway, this makes things a bit faster commit e70889d1d05ece81a081b8b3f27b62491429b6f9 Author: Ben Gotow <bengotow@gmail.com> Date: Mon Apr 6 16:41:49 2015 -0700 [icon] Paper airplanes Restyle account sidebar, optimize tag count queries a bit more Fix initialization issue with webkit image mask Can't compare dates with is/isnt Assets for check boxes Bug fixes Wrap ModelList instead of providing props Verbose mode for database view Fix existing specs Six new specs covering invalidateIfItemsInconsistent Test Plan: Run 40+ new tests Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1410
2015-04-09 10:25:00 +08:00
# Additional Commands
_onStarItem: =>
return unless ThreadListStore.view()
focused = FocusedContentStore.focused('thread')
if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
threads = [focused]
else if ThreadListStore.view().selection.count() > 0
threads = ThreadListStore.view().selection.items()
else
threads = [focused]
task = TaskFactory.taskForInvertingStarred({threads})
Actions.queueTask(task)
_onBackspace: =>
return unless ThreadListStore.view()
focused = FocusedContentStore.focused('thread')
if WorkspaceStore.layoutMode() is "split" and focused
task = TaskFactory.taskForMovingToTrash
threads: [focused]
fromView: FocusedMailViewStore.mailView()
Actions.queueTask(task)
else if ThreadListStore.view().selection.count() > 0
task = TaskFactory.taskForMovingToTrash
threads: ThreadListStore.view().selection.items()
fromView: FocusedMailViewStore.mailView()
Actions.queueTask(task)
else if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
Actions.popSheet()
module.exports = ThreadList