mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-25 09:46:07 +08:00
eb6001480c
Summary: Lots of components were rendering when they didn't have to on the very frequent account sidebar updates Test Plan: manual Reviewers: mark, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D3691
49 lines
1.3 KiB
CoffeeScript
49 lines
1.3 KiB
CoffeeScript
{Utils, Actions, React} = require 'nylas-exports'
|
|
{RetinaImg} = require 'nylas-component-kit'
|
|
|
|
class StreamingSyncActivity extends React.Component
|
|
|
|
constructor: (@props) ->
|
|
@_timeoutId = null
|
|
@state =
|
|
receivingDelta: false
|
|
|
|
shouldComponentUpdate: (nextProps, nextState) =>
|
|
not Utils.isEqualReact(nextProps, @props) or
|
|
not Utils.isEqualReact(nextState, @state)
|
|
|
|
componentDidMount: =>
|
|
@_unlistener = Actions.longPollReceivedRawDeltasPing.listen(@_onDeltaReceived)
|
|
|
|
componentWillUnmount: =>
|
|
@_unlistener() if @_unlistener
|
|
clearTimeout(@_timeoutId) if @_timeoutId
|
|
|
|
render: =>
|
|
return false unless @state.receivingDelta
|
|
<div className="item" key="delta-sync-item">
|
|
<div style={padding: "9px 9px 0 12px", float: "left"}>
|
|
<RetinaImg name="sending-spinner.gif" width={18} mode={RetinaImg.Mode.ContentPreserve} />
|
|
</div>
|
|
<div className="inner">
|
|
Syncing your mailbox…
|
|
</div>
|
|
</div>
|
|
|
|
_onDeltaReceived: (countDeltas) =>
|
|
tooSmallForNotification = countDeltas <= 10
|
|
return if tooSmallForNotification
|
|
|
|
if @_timeoutId
|
|
clearTimeout(@_timeoutId)
|
|
|
|
@_timeoutId = setTimeout(( =>
|
|
delete(@_timeoutId)
|
|
@setState(receivingDelta: false)
|
|
), 20000)
|
|
|
|
@setState(receivingDelta: true)
|
|
|
|
|
|
module.exports = StreamingSyncActivity
|