|
1 | | -import React, {PropTypes} from 'react' |
| 1 | +import React, {Component, PropTypes} from 'react' |
2 | 2 | import Panel from '../Panel/Panel' |
3 | 3 | import './MessageList.scss' |
4 | 4 | import cn from 'classnames' |
@@ -49,18 +49,40 @@ const MessageRow = ({title, messages, isActive, unreadCount, onClick}) => { |
49 | 49 | } |
50 | 50 |
|
51 | 51 |
|
52 | | -const MessageList = ({threads, onSelect, onAdd, showAddButton, showEmptyState}) => ( |
53 | | - <Panel className="message-list"> |
54 | | - <Panel.Title> |
55 | | - Discussions |
56 | | - { showAddButton && <Panel.AddBtn onClick={onAdd} /> } |
57 | | - </Panel.Title> |
58 | | - <div className="panel-messages"> |
59 | | - { showEmptyState && <MessageRow title="First discussion post" isActive messages={[{ content: ''}]} /> } |
60 | | - {threads.map((item) => <MessageRow key={item.id} onClick={(e) => onSelect(item, e) } {...item} />)} |
61 | | - </div> |
62 | | - </Panel> |
63 | | -) |
| 52 | +class MessageList extends Component { |
| 53 | + constructor(props) { |
| 54 | + super(props) |
| 55 | + } |
| 56 | + |
| 57 | + componentDidMount() { |
| 58 | + const { scrollPosition } = this.props |
| 59 | + if (scrollPosition) { |
| 60 | + const panelMessages = this.refs.panelMessages |
| 61 | + // We use requestAnimationFrame because this function may be executed before |
| 62 | + // the DOM elements are actually drawn. |
| 63 | + // Source: http://stackoverflow.com/a/28748160 |
| 64 | + requestAnimationFrame(() => { |
| 65 | + panelMessages.scrollTop += scrollPosition |
| 66 | + }) |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + render() { |
| 71 | + const {threads, onSelect, onAdd, showAddButton, showEmptyState } = this.props |
| 72 | + return ( |
| 73 | + <Panel className="message-list"> |
| 74 | + <Panel.Title> |
| 75 | + Discussions |
| 76 | + { showAddButton && <Panel.AddBtn onClick={onAdd} /> } |
| 77 | + </Panel.Title> |
| 78 | + <div className="panel-messages" ref="panelMessages"> |
| 79 | + { showEmptyState && <MessageRow title="First discussion post" isActive messages={[{ content: ''}]} /> } |
| 80 | + {threads.map((item) => <MessageRow key={item.id} onClick={(e) => onSelect(item, e) } {...item} />)} |
| 81 | + </div> |
| 82 | + </Panel> |
| 83 | + ) |
| 84 | + } |
| 85 | +} |
64 | 86 |
|
65 | 87 | MessageList.propTypes = { |
66 | 88 | /** |
|
0 commit comments