mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
d3f62d4bb0
commit 7a67c1fd349c575a91b162024cc03050e86574c9 Author: Ben Gotow <bengotow@gmail.com> Date: Fri Jan 8 11:14:07 2016 -0800 WIP commit 891f23487827a447ec95406ef26f1473a0c07de6 Author: Ben Gotow <bengotow@gmail.com> Date: Wed Jan 6 15:25:09 2016 -0800 WIP commit 3c323cd4beb2df2fae2439a556d3129404d942cc Author: Ben Gotow <bengotow@gmail.com> Date: Mon Jan 4 17:46:11 2016 -0800 WIP commit ec7090ea9e1969fea2ea583f80a9a2ac41e6c8b0 Author: Ben Gotow <bengotow@gmail.com> Date: Mon Jan 4 17:22:07 2016 -0800 Remove unused LRUCache commit e10c3919559d3c364cb7bb94d19094a2444c10f3 Author: Ben Gotow <bengotow@gmail.com> Date: Mon Jan 4 16:21:37 2016 -0800 rm(database-view): Performance refactor of thread-list Summary: This diff removes the old DatabaseView class, which included lots of gross optimizations that have since been duplicated in QuerySubscription and makes the thread list use the QuerySubscription class. This diff also substantially replaces the QuerySubscription class. The new implementation actually makes more queries but is less gross and more straightforward. It leverages a couple findings from database profiling: - Because of the sqlite page cache, asking for ids you've previously asked for is very fast. + Don't bother sorting in memory to avoid a query, just ask for ids again and fill in any missing objects. - Loading and inflating models is 4x+ slower than just grabbing ids I've also added more convenience classes around database queries: - QueryRange: Represents {offset, limit}, and can do boolean intersections - QueryResultSet: Better than passing an array of 50 items when you really mean items 150-200. Also tries hard to be immutable. This diff doesn't fully remove the concept of a "ModelView" because it's used /everywhere/ in the multiselect list source. There's a small shim that we can remove when we refactor that code. Ideally, I think we should rename ModelView to "MultiselectListDataSource" to follow iOS conventions (eg UITableViewDataSource). RIP 80char lines? Test Plan: They've gone to hell. WIP. Reviewers: evan, juan Differential Revision: https://phab.nylas.com/D2408 commit 32607eee8aafb7fa98b866347bdd2c0b963a602c Author: Ben Gotow <bengotow@gmail.com> Date: Mon Jan 4 09:56:34 2016 -0800 WIP commit 5ab5fe74e94db6904bd77d224720ad9fc69fe6a7 Author: Ben Gotow <bengotow@gmail.com> Date: Wed Dec 30 22:56:46 2015 -0800 redo scrollbars to not require counts commit 361bb192d072dc8a69fd3ef143cad7bed214ebdc Author: Ben Gotow <bengotow@gmail.com> Date: Wed Dec 30 17:50:57 2015 -0800 wip commit 079394de1cc3344fb6568efe00a52d7fc97fbd27 Author: Ben Gotow <bengotow@gmail.com> Date: Wed Dec 30 13:49:11 2015 -0800 wip commit 65142be03c27c653fe1147fdde6c2f9b046ade22 Author: Ben Gotow <bengotow@gmail.com> Date: Wed Dec 30 01:23:20 2015 -0800 wip commit 5d412ec276be1104175ad0f43c9d54e1cea857bf Author: Ben Gotow <bengotow@gmail.com> Date: Tue Dec 29 22:49:58 2015 -0800 Refactor start commit d2b6eea884fcd2bd81ebe3985f2b2636a510c493 Author: Ben Gotow <bengotow@gmail.com> Date: Tue Dec 29 18:51:53 2015 -0800 RIP DatabaseView
127 lines
4 KiB
CoffeeScript
127 lines
4 KiB
CoffeeScript
_ = require 'underscore'
|
|
React = require 'react'
|
|
classNames = require 'classnames'
|
|
{RetinaImg} = require 'nylas-component-kit'
|
|
{DatabaseView,
|
|
NylasAPI,
|
|
NylasSyncStatusStore,
|
|
Message,
|
|
WorkspaceStore} = require 'nylas-exports'
|
|
|
|
EmptyMessages = [{
|
|
"body":"The pessimist complains about the wind.\nThe optimist expects it to change.\nThe realist adjusts the sails."
|
|
"byline": "- William Arthur Ward"
|
|
},{
|
|
"body":"The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart."
|
|
"byline": "- Helen Keller"
|
|
},{
|
|
"body":"Believe you can and you're halfway there."
|
|
"byline": "- Theodore Roosevelt"
|
|
},{
|
|
"body":"Don't judge each day by the harvest you reap but by the seeds that you plant."
|
|
"byline": "- Robert Louis Stevenson"
|
|
}]
|
|
|
|
class ContentGeneric extends React.Component
|
|
render: ->
|
|
<div className="generic">
|
|
<div className="message">
|
|
{@props.messageOverride ? "No threads to display."}
|
|
</div>
|
|
</div>
|
|
|
|
class ContentQuotes extends React.Component
|
|
@displayName = 'Quotes'
|
|
|
|
constructor: (@props) ->
|
|
@state = {}
|
|
|
|
componentDidMount: ->
|
|
# Pick a random quote using the day as a seed. I know not all months have
|
|
# 31 days - this is good enough to generate one quote a day at random!
|
|
d = new Date()
|
|
r = d.getDate() + d.getMonth() * 31
|
|
message = EmptyMessages[r % EmptyMessages.length]
|
|
@setState(message: message)
|
|
|
|
render: ->
|
|
<div className="quotes">
|
|
{@_renderMessage()}
|
|
<RetinaImg mode={RetinaImg.Mode.ContentLight} url="nylas://thread-list/assets/blank-bottom-left@2x.png" className="bottom-left"/>
|
|
<RetinaImg mode={RetinaImg.Mode.ContentLight} url="nylas://thread-list/assets/blank-top-left@2x.png" className="top-left"/>
|
|
<RetinaImg mode={RetinaImg.Mode.ContentLight} url="nylas://thread-list/assets/blank-bottom-right@2x.png" className="bottom-right"/>
|
|
<RetinaImg mode={RetinaImg.Mode.ContentLight} url="nylas://thread-list/assets/blank-top-right@2x.png" className="top-right"/>
|
|
</div>
|
|
|
|
_renderMessage: ->
|
|
if @props.messageOverride
|
|
<div className="message">{@props.messageOverride}</div>
|
|
else
|
|
<div className="message">
|
|
{@state.message?.body}
|
|
<div className="byline">
|
|
{@state.message?.byline}
|
|
</div>
|
|
</div>
|
|
|
|
|
|
class EmptyState extends React.Component
|
|
@displayName = 'EmptyState'
|
|
@propTypes =
|
|
visible: React.PropTypes.bool.isRequired
|
|
dataView: React.PropTypes.object
|
|
|
|
constructor: (@props) ->
|
|
@state =
|
|
layoutMode: WorkspaceStore.layoutMode()
|
|
syncing: NylasSyncStatusStore.busy()
|
|
active: false
|
|
|
|
componentDidMount: ->
|
|
@_unlisteners = []
|
|
@_unlisteners.push WorkspaceStore.listen(@_onChange, @)
|
|
@_unlisteners.push NylasSyncStatusStore.listen(@_onChange, @)
|
|
if @props.visible and not @state.active
|
|
@setState(active:true)
|
|
|
|
shouldComponentUpdate: (nextProps, nextState) ->
|
|
# Avoid deep comparison of dataView, which is a very complex object
|
|
return true if nextProps.visible isnt @props.visible
|
|
return true if nextProps.dataView isnt @props.dataView
|
|
return not _.isEqual(nextState, @state)
|
|
|
|
componentWillUnmount: ->
|
|
unlisten() for unlisten in @_unlisteners
|
|
|
|
componentDidUpdate: ->
|
|
if @props.visible and not @state.active
|
|
@setState(active:true)
|
|
|
|
componentWillReceiveProps: (newProps) ->
|
|
if newProps.visible is false
|
|
@setState(active:false)
|
|
|
|
render: ->
|
|
ContentComponent = ContentGeneric
|
|
|
|
messageOverride = "Nothing to display."
|
|
if @state.layoutMode is 'list'
|
|
ContentComponent = ContentQuotes
|
|
if @state.syncing
|
|
messageOverride = "Please wait while we prepare your mailbox."
|
|
|
|
classes = classNames
|
|
'empty-state': true
|
|
'visible': @props.visible
|
|
'active': @state.active
|
|
|
|
<div className={classes}>
|
|
<ContentComponent messageOverride={messageOverride}/>
|
|
</div>
|
|
|
|
_onChange: ->
|
|
@setState
|
|
layoutMode: WorkspaceStore.layoutMode()
|
|
syncing: NylasSyncStatusStore.busy()
|
|
|
|
module.exports = EmptyState
|