2016-03-10 03:33:31 +08:00
|
|
|
import React from 'react'
|
2016-03-10 05:17:20 +08:00
|
|
|
import {Utils, Actions} from 'nylas-exports'
|
2016-03-10 03:33:31 +08:00
|
|
|
|
|
|
|
export default class RelatedThreads extends React.Component {
|
|
|
|
static displayName = "RelatedThreads";
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
contact: React.PropTypes.object,
|
|
|
|
contactThreads: React.PropTypes.array,
|
|
|
|
}
|
|
|
|
|
2016-05-07 07:06:16 +08:00
|
|
|
static containerStyles = {
|
|
|
|
order: 99,
|
|
|
|
}
|
|
|
|
|
2016-03-10 03:33:31 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {expanded: false}
|
|
|
|
this.DEFAULT_NUM = 3
|
|
|
|
}
|
|
|
|
|
|
|
|
_onClick(thread) {
|
|
|
|
Actions.setFocus({collection: 'thread', item: thread})
|
|
|
|
}
|
|
|
|
|
|
|
|
_toggle = () => {
|
|
|
|
this.setState({expanded: !this.state.expanded})
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderToggle() {
|
|
|
|
if (!this._hasToggle()) { return false; }
|
|
|
|
const msg = this.state.expanded ? "Collapse" : "Show more"
|
|
|
|
return (
|
|
|
|
<div className="toggle" onClick={this._toggle}>{msg}</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
_hasToggle() {
|
|
|
|
return (this.props.contactThreads.length > this.DEFAULT_NUM)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let limit;
|
|
|
|
if (this.state.expanded) {
|
|
|
|
limit = this.props.contactThreads.length;
|
|
|
|
} else {
|
|
|
|
limit = Math.min(this.props.contactThreads.length, this.DEFAULT_NUM)
|
|
|
|
}
|
|
|
|
|
2016-03-11 04:06:44 +08:00
|
|
|
const height = ((limit + (this._hasToggle() ? 1 : 0)) * 31);
|
2016-03-10 03:33:31 +08:00
|
|
|
const shownThreads = this.props.contactThreads.slice(0, limit)
|
|
|
|
const threads = shownThreads.map((thread) => {
|
2016-04-15 05:33:43 +08:00
|
|
|
const {snippet, subject, lastMessageReceivedTimestamp} = thread;
|
|
|
|
const snippetStyles = (subject && subject.length) ? {marginLeft: '1em'} : {};
|
2016-03-10 03:33:31 +08:00
|
|
|
const onClick = () => { this._onClick(thread) }
|
2016-04-15 05:33:43 +08:00
|
|
|
|
2016-03-10 03:33:31 +08:00
|
|
|
return (
|
|
|
|
<div key={thread.id} className="related-thread" onClick={onClick} >
|
2016-04-15 05:33:43 +08:00
|
|
|
<span className="content" title={subject}>
|
|
|
|
{subject}
|
|
|
|
<span className="snippet" style={snippetStyles}>{snippet}</span>
|
|
|
|
</span>
|
|
|
|
<span className="timestamp" title={Utils.fullTimeString(lastMessageReceivedTimestamp)}>{Utils.shortTimeString(lastMessageReceivedTimestamp)}</span>
|
2016-03-10 03:33:31 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="related-threads" style={{height}}>
|
|
|
|
{threads}
|
|
|
|
{this._renderToggle()}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|