2016-10-19 08:06:28 +11:00
|
|
|
import Status from './status';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
import { ScrollContainer } from 'react-router-scroll';
|
2016-10-25 02:11:02 +11:00
|
|
|
import StatusContainer from '../containers/status_container';
|
2016-08-25 01:56:44 +10:00
|
|
|
|
|
|
|
const StatusList = React.createClass({
|
2016-09-01 00:15:12 +10:00
|
|
|
|
2016-08-25 01:56:44 +10:00
|
|
|
propTypes: {
|
2016-10-25 02:11:02 +11:00
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
2016-09-30 08:00:45 +10:00
|
|
|
onScrollToBottom: React.PropTypes.func,
|
2016-10-25 02:11:02 +11:00
|
|
|
trackScroll: React.PropTypes.bool
|
2016-08-25 01:56:44 +10:00
|
|
|
},
|
|
|
|
|
2016-10-19 08:06:28 +11:00
|
|
|
getDefaultProps () {
|
|
|
|
return {
|
|
|
|
trackScroll: true
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-09-01 00:15:12 +10:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2016-09-22 09:08:35 +10:00
|
|
|
handleScroll (e) {
|
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
|
|
|
|
2016-11-07 12:02:55 +11:00
|
|
|
this._oldScrollPosition = scrollHeight - scrollTop;
|
|
|
|
|
2016-09-22 09:08:35 +10:00
|
|
|
if (scrollTop === scrollHeight - clientHeight) {
|
|
|
|
this.props.onScrollToBottom();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-07 12:02:55 +11:00
|
|
|
componentDidUpdate (prevProps) {
|
2016-11-07 12:11:38 +11:00
|
|
|
if (prevProps.statusIds.size < this.props.statusIds.size && prevProps.statusIds.first() !== this.props.statusIds.first() && this._oldScrollPosition) {
|
2016-11-07 12:02:55 +11:00
|
|
|
const node = ReactDOM.findDOMNode(this);
|
|
|
|
|
|
|
|
if (node.scrollTop > 0) {
|
|
|
|
node.scrollTop = node.scrollHeight - this._oldScrollPosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-01 00:15:12 +10:00
|
|
|
render () {
|
2016-10-25 02:11:02 +11:00
|
|
|
const { statusIds, onScrollToBottom, trackScroll } = this.props;
|
2016-09-30 08:00:45 +10:00
|
|
|
|
2016-10-19 08:06:28 +11:00
|
|
|
const scrollableArea = (
|
2016-11-04 23:32:14 +11:00
|
|
|
<div className='scrollable' onScroll={this.handleScroll}>
|
2016-08-25 01:56:44 +10:00
|
|
|
<div>
|
2016-10-25 02:11:02 +11:00
|
|
|
{statusIds.map((statusId) => {
|
2016-11-18 02:34:36 +11:00
|
|
|
return <StatusContainer key={statusId} id={statusId} />;
|
2016-08-25 01:56:44 +10:00
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2016-10-19 08:06:28 +11:00
|
|
|
|
|
|
|
if (trackScroll) {
|
|
|
|
return (
|
|
|
|
<ScrollContainer scrollKey='status-list'>
|
|
|
|
{scrollableArea}
|
|
|
|
</ScrollContainer>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return scrollableArea;
|
|
|
|
}
|
2016-08-25 01:56:44 +10:00
|
|
|
}
|
2016-09-01 00:15:12 +10:00
|
|
|
|
2016-08-25 01:56:44 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
export default StatusList;
|