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

37 lines
987 B
Text
Raw Normal View History

2016-01-15 06:04:51 +08:00
React = require 'react'
ThreadListStore = require './thread-list-store'
{timestamp} = require './formatting-utils'
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: ->
if @state.item
content = timestamp(@state.item.lastMessageReceivedTimestamp)
else
content = "Loading..."
<div className="scroll-tooltip">
{content}
</div>
module.exports = ThreadListScrollTooltip