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